1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| void selectLines() {
AffineTransform screenToWorld = mapFrame.getMapPane().getScreenToWorldTransform();
Coordinate[] coordinates = new Coordinate[longitude.length];
for(int i=0; i<longitude.length;i++)
{
coordinates[i] = new Coordinate(longitude[i],latitude[i]);
}
Literal literal =
ff.literal( new GeometryFactory().createLineString(coordinates));
Literal literal2 = ff.literal( new GeometryFactory().createMultiPoint(coordinates));
// Literal literal2 = ff.literal( new GeometryFactory().createMultiPoint(coordinates));
// Literal literal2 = ff.literal( new GeometryFactory().createPoint(new Coordinate(longitude[0],latitude[0])));
Filter filter = ff.contains(literal, literal2); //touches(ff.property(geometryAttributeName), literal); //contains(ff.property(geometryAttributeName), literal); //crosses(ff.property(geometryAttributeName), literal);//within(ff.property(geometryAttributeName), literal); //equals(ff.property(geometryAttributeName), literal); //contains(ff.property(geometryAttributeName), literal); //disjoint(ff.property(geometryAttributeName), literal);// crosses(ff.property(geometryAttributeName), literal);// intersects(ff.property(geometryAttributeName), literal);
try {
SimpleFeatureCollection selectedFeatures = featureSource.getFeatures(filter);
//SimpleFeatureCollection selectedFeatures = featureSource.getFeatures();
SimpleFeatureIterator iter = selectedFeatures.features();
Set<FeatureId> IDs = new HashSet<FeatureId>();
try {
while (iter.hasNext()) {
SimpleFeature feature = iter.next();
//System.out.println(feature.getAttribute("the_geom"));
IDs.add(feature.getIdentifier());
System.out.println(" " + feature.getIdentifier());
}
} finally {
iter.close();
}
if (IDs.isEmpty()) {
System.out.println(" no feature selected");
}
displaySelectedFeatures(IDs,2);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
} |
Partager