geotools读取shapefile文件
依赖
- <dependency>
- <groupId>org.geotools</groupId>
- <artifactId>gt-shapefile</artifactId>
- <version>${geotools.version}</version>
- </dependency>
代码
- File file = new File(“D:\\shapefiles\\states.shp”);
- Map<String, Object> map = new HashMap<String, Object>();
- map.put(“url”, file.toURI().toURL());
- DataStore dataStore = DataStoreFinder.getDataStore(map);
- String typeName = dataStore.getTypeNames()[0];
- FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore
- .getFeatureSource(typeName);
- FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures();
- FeatureIterator<SimpleFeature> features = collection.features();
- while (features.hasNext()) {
- SimpleFeature feature = features.next();
- System.out.print(feature.getID());
- System.out.print(“: “);
- System.out.println(feature.getDefaultGeometryProperty().getValue());//此行输出的空间信息的wkt表达形式
- }
转载自:https://blog.csdn.net/xiaohan2826/article/details/53860387