Hi,
I'm new to GIS sw: my only experience is the built of an html interface
for MapServer during the last few weeks. Now I need to move to a GIS
java library to migrate an old web application from a commercial GIS
engine to a full Open Source one. I choose GeoTools for this so in the
last days I'm playing with it.
I started trying simple things and step by step I could work them out.
But now I have a couple of clearly state problems that I'm unable to
solve.
I have two shape file: the first one (lets say towns.shp) describes the
boundaries of the towns in a State, the second one (streets.shp) roads
and streets of that same State. On those shape files I need to make
geo-referenced query:
1) to have all the roads of a specific town
2) to check if a street or road is (wholly or partially) in the
boundaries of a town.
I was unable to solve them neither studing the documentation/tutorial
nor reading the mailing list (I unsuccesfully query it and scanned mail
by mail the last months archive). Can anyone suggest me a solution?
Thanks.
I understand that the solution requires the definition of a Filter
(actually a GeometryFilter) so, modifying snippets and tutorials, In my
attempts I wrote this trying to solve (unsuccesfully) the first one:
<pre>
*****************
String townID = "123456";
String streetsUri = "file/C:/.../streets.shp";
String townsUri = "file/C:/.../towns.shp";
DataStore streetsDataStore = new ShapefileDataStore(new
URL(streetsUri));
FeatureSource features =
streetsDataStore.getFeatureSource(streetsDataStore.getTypeNames()[0]);
FeatureCollection resultCollection = features.getFeatures();
System.out.println("# of available steets: " +
resultCollection.size()); //it returns the number of streets
FilterFactory filterFactory =
FilterFactoryFinder.createFilterFactory();
Envelope envelope = Shapefile.getBounds(townsUri, townID); // is
envolope what I need? I'm not sure: envelope is just a rectangle!
System.out.println("envelope: " + envelope);
Expression townsEnvelopeExpression =
filterFactory.createBBoxExpression(envelope);
Expression streetsExpression =
filterFactory.createAttributeExpression(streetsDataStore.getTypeNames()[
0]); //I'm not really sure about this
GeometryFilter geometryFilter =
filterFactory.createGeometryFilter(GeometryFilter.GEOMETRY_CONTAINS);
geometryFilter.addLeftGeometry(streetsExpression);
geometryFilter.addRightGeometry(townsEnvelopeExpression);
// count filtered features
resultCollection = features.getFeatures(geometryFilter);
System.out.println("# of streets in the defined town: " +
resultCollection.size());
*******************
</pre>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users