1

I have implemented GeoTools Query tutorial. Can someone tell me that how could I apply a query in two shape files at a time and save the results in a new shape file or a csv file.

or even can i save the query results of a single shape file as done in the Query Tutorial in a new shape file or csv file?

Just Fun
  • 11
  • 2

1 Answers1

0

You can apply your Query to as many shapefiles as you like just loop through them and keep adding to the feature collection where you are storing the answers.

So in pseudocode:

 collection = new List
 for file in shapefiles:
      collection.add(file.queryResult(query));

 writeShapefile(collection);

You can actually use a normal Java ArrayList (or Set) to store the results in and then use a ListFeatureCollection to write them out.

FeatureCollection features = new ListFeatureCollection(schema, feats);

Caveat: All your shapefiles must have the same contents (or your Query must only extract the common attributes). See my answer to this question for an example of ShapeFile writing.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47