Trying to make a simple class that will read shapefiles and eventually be able to pull out the coordinates/attributes for each feature (working with points here). But can't quite figure out geotools.
File file = new File(filepath);
if(!file.exists() || !filepath.endsWith(".shp")) {
throw new Exception("Invalid shapefile filepath: " + filepath);
}
ShapefileDataStore dataStore = new ShapefileDataStore(file.toURL());
ContentFeatureSource featureSource = dataStore.getFeatureSource();
ContentFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator iterator = featureCollection.features();
while(iterator.hasNext()) {
SimpleFeature feature = iterator.next();
List attributes = feature.getAttributes();
Collection properties = feature.getProperties();
}
Fails at dataStore.getFeatureSource()
with the error: java.lang.NoSuchMethodError: org.geotools.data.shapefile.ShapefileDataStore.getFeatureSource() Lorg/geotools/data/store/ContentFeatureSource;
The imports for every geotools class mentioned above are there. As some of you know, geotools comes with a crapton of jars. As I'm unfamiliar with Maven and this is an existing project that I don't know how to convert over, I'm trying to do the library imports the old fashioned way. Right now my imports are: gt-api-11.1.jar
, gt-data-11.1.jar
, gt-main-11.1.jar
, gt-opengis-11.1.jar
, and gt-shapefile-11.1.jar
. I figure it may be a missing jar that could be the problem but I'm not sure which as every imported class is in one of these jars.