From: Jody G. <jga...@re...> - 2006-05-11 05:49:00
|
Vanmeulebrouk, Bas wrote: > Dear list, > > First of all we would like to thank Jesse and Jody for their answers. We > have been trying to determine the FID so we could use > filterfactory.createFidFactory. See the code below. We have got two > questions. First: How can we obtain a reference to the geometry (in this > case a polygon) of a feature to check if the coordinate falls within > this geometry? One thing to do is look at your FeatureType, go through its list of AttributeTypes and see if any are GeometryAttributeTypes. If you are lazy, or think you only have one geometry per feature, you can cheat and just ask each Feature for its getDefaultGeometry() (but please understand that this is only a shortcut). So if the default geometry is named "the_geom" you can then construct a bbox filter against the attribute "the_geom". So GeometryCondition is BBOX left hand side is attirbute expression "the_geom" right hand side is a literal Envelope > And second: does the getID() function return the FID > which can be used as an argument in createFidFilter? Hopefully someone > can answer our questions. > Yep you got it. Best of Luck, and check out the snipits and tutorials for examples. > private String GetFID(Coordinate aCoordinate, String aLayerName) throws > Exception { > I would make a bounding box out of aCoordinate and then use bbox query - but what you are doing looks like. Just make sure to do it with an Expression instead...that way it can be turned into really fast SQL, or into optimized code for shapefile, or in worst case something like what you have done by hand. > String result = ""; > > MapLayer layer = FindMapLayer(aLayerName); > FeatureSource featuresource = layer.getFeatureSource(); > FeatureCollection featurecollection = featuresource.getFeatures(); > Please replace this line with featuresource.getFeatures( filter ); > Iterator it = null; > try { > for (it = featurecollection .iterator(); it.hasNext();) { > Feature feature = (Feature) it.next(); > if (feature.getBounds().contains(aCoordinate)) { > // ToDo Check if the geometry of the feature > contains aCoordinate. > // How to obtain this geometry? > System.out.println("Bounding box of " + > feature.getID() + " contains the point"); > // Does getID() return the FID which can be > used in a fidFilter? > result = feature.getID(); > break; > } > } > } > finally { > fc.close(it); > } > > return result; > } > |