2

I have a LineString featureSource. For one feature from source I want to take intersected lines by startPoint or endPoint from same featureSource.

I tried this for just endPoint:

Filter filter = ff.intersects(ff.literal(featureLastCoordinate), ff.function("endPoint", ff.literal(featureGeom)));
FeatureCollection<SimpleFeatureType, SimpleFeature> intersectedFeatColl = inputSource.getFeatures(filter);

And this:

Filter filter = ff.and(ff.intersects(ff.property(featureGeomPropName), ff.literal(featureLastCoordinate)), ff.function("endPoint", ff.literal(featureGeom)));

I cant find correct expressions for the filter. For example:

exampleImg

I want to get other lines for yellow line.

cgrgcn
  • 361
  • 2
  • 6
  • 24

1 Answers1

0

Depending on how sure you are that the lines touch you can do something like this:

LineString lineString = (LineString) first.getDefaultGeometry();
Point[] points = { lineString.getStartPoint(), lineString.getEndPoint() };
for (Point p : points) {
  Filter f = CQL.toFilter("intersects( " + geom + ", " + p + ")");
  SimpleFeatureCollection res = featureSource.getFeatures(f);
  if (!res.isEmpty()) {
    System.out.println("Point " + p + " touches ");
    try (SimpleFeatureIterator itr = res.features()) {
      while (itr.hasNext()) {
        System.out.println(itr.next());
      }
    }
  }

  Polygon poly = (Polygon) p.buffer(10);
  f = CQL.toFilter("intersects( " + geom + ", " + poly + ")");
  res = featureSource.getFeatures(f);
  if (!res.isEmpty()) {
    System.out.println("Point " + p + " is close to ");
    try (SimpleFeatureIterator itr = res.features()) {
      while (itr.hasNext()) {
        System.out.println(itr.next());
      }
    }
  }
}
Ian Turton
  • 10,018
  • 1
  • 28
  • 47