1

我正在使用 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();

有没有另一种方法可以在不做所有这些工作的情况下直接获得所有积分?

4

1 回答 1

1

如果我正确理解了您的问题,您有 a SimpleFeatureCollectionof Points 并且您想将其转换为LineStringwhere 如果差距超过 0.3(度数?)您开始新的一行。

将一组特征转换为一条线没有捷径,因此您需要遍历它们并提取点。我会这样做:

  public List<LineString> toLine(SimpleFeatureCollection features) {
    GeometryFactory factory = new GeometryFactory();
    Point lastPoint = null;
    List<LineString> routes = new ArrayList<>();
    ArrayList<Coordinate> coordList = new ArrayList<>();
    LineString route;
    try (SimpleFeatureIterator iter = features.features()) {
      while (iter.hasNext()) {
        SimpleFeature f = iter.next();
        Point p = (Point) f.getDefaultGeometry();
        double distance;
        if (lastPoint != null) {
          distance = p.distance(lastPoint);
        } else {
          distance = -1;
          lastPoint = p;
        }
        if (distance != -1 && distance < 0.3) {
          if (distance > 0) {
            // skip repeats
            coordList.add(p.getCoordinate());
          }
        } else {
          route = factory.createLineString(coordList.toArray(new Coordinate[] {}));
          routes.add(route);
          System.out.println(route);
          coordList = new ArrayList<>();
        }
      }
    }
    return routes;
  }
于 2018-08-19T12:21:58.700 回答