Hi Gaby,

If seems that you could work in this manner...

1. Build a filter for points within the bounds of the polygon shapefile.

// (Something like this may be useful.)
FilterFactory ff = CommonFactoryFinder.getFilterFactory2();
ReferencedEnvelope envelope = polygonShapefile.getBounds();
Filter boundsFilter = ff.createBBoxExpression("geomField", envelope);

2. Iterate through the points, evaluate the boundsFilter. Failing points can go into the collection for the points outside the polygon shapefile.

3. For those accepted, you can evaluate the OR filter you've previously described. Points which satisfy the filter are in, and those which do not are inside in the bounds, but outside the collection of polygons.

As another note, depending on your situation, it may be beneficial to read out the polygons into a GeometryCollection and simplify things with union/buffer(0). This one geometry can be used to create a potentially more simple filter. If the data size grows, you could extend this approach to use R-trees.

Cheers,

Jim

On 05/07/2015 01:24 AM, Gabriella Turek wrote:
I have two shape files, one of polygons and one of points. I want to find out
1) the id’s of all the points that fall into a polygon
2) the id’s of the points that do not fall in any polygon
3) the id’s of any points that lie outside the bonding box of the polygons file

This is how I got started:

public static Map<FeatureId, Integer> computeAssetsExposure(SimpleFeatureCollection assetsfc, SimpleFeatureCollection exposurefc) throws IOException {

Class<?> geomAsset = assetsfc.getSchema().getGeometryDescriptor().getType().getBinding();

Class<?> geomExposure = exposurefc.getSchema().getGeometryDescriptor().getType().getBinding();

String geomExposureAttr = exposurefc.getSchema().getGeometryDescriptor().getLocalName();

if (geomExposure.equals(Polygon.class) || geomExposure.equals(MultiPolygon.class))

{

CommonLogger.getInstance().logInfo(ExposureCalculator.class, "Unsupported configuration");

returnnull;

}

// Points that fall in a polygon

Filter orFilter = null;

try (SimpleFeatureIterator eIt = exposurefc.features()) {

booleanstart= true;

while (eIt.hasNext()) {

SimpleFeature expFeature = eIt.next();

Geometry expGeom = (Geometry) expFeature.getDefaultGeometry();

String expr = "INTERSECTS(" + geomExposureAttr + ", " + expGeom.toText() + ")";

if (start)

{

orFilter = CQL.toFilter(expr);

start = false;

} else {

orFilter = Filters.or(CommonFactoryFinder.getFilterFactory2(), orFilter, CQL.toFilter(expr));

}

}

}


SimpleFeatureCollection exposedAssets = assetsfc.subCollection(orFilter);

              ??????

      }


To get the Ids I think I could use an IdCollectorFilterVisitor.ID_COLLECTOR, but I can’t figure out how to use it.

Once I’ve found out the points that are in a polygon, is there a quick way to find out the id’s of the remaining ones? Or do I have to build Filters.and(…) with the individual filters being DISJOINT filters?

How do I find out if there are any points that lie outside the extent of the polygon shapefile?

Many thanx!

Gaby




------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y


_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to