使用Geotools将FeatureCollection转换为LineString

时间:2018-08-18 15:02:19

标签: geotools geomesa

我正在使用Geomesa,我想编写一些与JAVA兼容的东西,在此示例中,我试图获取区域中的一些点并将其转换为一条线以便以后绘制:

Query query=new Query(feature.getTypeName());
        query.setFilter(CQL.toFilter(filtre));
        query.setSortBy(new SortBy[] {CommonFactoryFinder.getFilterFactory2().sort("dtg",SortOrder.ASCENDING) });
        FeatureCollection collection=source.getFeatures(query);
        FeatureIterator iterator=collection.features();

我得到了我需要的所有要点,但问题是我无法直接将其转换为LineString,我所做的是我对所有集合进行了迭代,并在转换后将其收集到ArrayList中每个元素的几何形状将ArrayList放入坐标数组并创建LineString

   Coordinate[] tab;
        cool.add(((com.vividsolutions.jts.geom.Point)save.getDefaultGeometry()).getCoordinate());
        while (iterator.hasNext()) {
            actuel=iterator.next();
            double distance= ( (com.vividsolutions.jts.geom.Point)save.getDefaultGeometry()).distance((com.vividsolutions.jts.geom.Point)actuel.getDefaultGeometry());
                if(distance<0.3 ){
                    if(distance>0) 
                   cool.add(((com.vividsolutions.jts.geom.Point) actuel.getDefaultGeometry()).getCoordinate());

            }
            else{
                tab=new Coordinate[cool.size()];
                tab=cool.toArray(tab);
                route=factory.createLinearRing(tab);
                System.out.println(route);
                cool=new ArrayList<>();
            }
        }
        tab=new Coordinate[cool.size()+1];
        tab=cool.toArray(tab);
        tab[cool.size()]=cool.get(0);
        route=factory.createLinearRing(tab);
        System.out.println(route);
        iterator.close();

是否有另一种方法可以直接获得所有积分而无需完成所有工作?

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,那么您有switch (requestCode) { case GALLERY_PERMISSIONS_REQ_CODE: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { openGallery(); } imgGalleryCV.setClickable(true); break; default: super.onRequestPermissionsResult(requestCode,permissions,grantResults); break; } SimpleFeatureCollection,并且您希望将其转换为Point,如果差距大于0.3(度?),您可以换行。

没有将一组要素转换为线的捷径,因此您需要遍历它们并提取点。这就是我的方法:

LineString