Jacopo,
The below is a quick example of a getFeatures() operation with a FID
filter
-Jeff
package examples;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.geotools.data.FeatureResults;
import org.geotools.data.FeatureSource;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.filter.FidFilter;
import org.geotools.filter.FilterFactory;
import org.geotools.filter.FilterFactoryFinder;
/**
* @version $Id$
* @author J. F. Hyink
*
*/
public class getFeatureExample {
public static void main(String[] args) {
URL sourceShapeFileURL = null;
ShapefileDataStore store = null;
try {
sourceShapeFileURL = sourceShapeFileURL = (new
File("C:/JavaProjects/Data/Carmel Shapefile/carmel.shp")).toURL();
store = new ShapefileDataStore(sourceShapeFileURL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
//pull the first name off of the typeNames list in the file
String nameOfFeatureType = store.getTypeNames()[0];
FeatureSource source = null;
try {
//get a featureSource for the named feature type
source = store.getFeatureSource(nameOfFeatureType);
} catch (IOException e) {
e.printStackTrace();
}
//now create a FID filter and apply it to get results
FilterFactory filterFactory =
FilterFactoryFinder.createFilterFactory();
FidFilter filter = filterFactory.createFidFilter();
filter.addFid("carmel.22"); //carmel.22 is a valid FID in
this shapefile.
FeatureResults r = null;
int featureCount = 0;
try {
r = source.getFeatures(filter);
//the getCount() method below is deprecated, but works
for a quick example
featureCount = r.getCount();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("caught " + featureCount + " features
with filter");
}
}
-------------------------------------------------------------------------
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