I am trying to implement a really basic code to get started with Geotools, but it doesn't work out:
package com.henrytriage.windows;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
File file = new File("filepath");
System.out.println(file.exists() + " " + file.length());
Map<String, Object> map = new HashMap<>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName);
Filter filter = Filter.INCLUDE;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(filter);
try (FeatureIterator<SimpleFeature> features = collection.features()){
while (features.hasNext()) {
SimpleFeature feature = features.next();
System.out.println(feature.getID() + ": \n" + feature.getDefaultGeometryProperty().getValue());
}
}
}
}
After trying lots of different libraries and packages I am still getting the
ClassNotFoundException: javax.measure.spi.SystemOfUnits
I switched from Gradle to a Maven Project. This fixed the issue. There may be a solution for Gradle when handling dependencies, which get imported more than once, in a correct manner, but I didn't figure it out... @ian-turtor thx for your help!