读取shp
pom依赖文章来源:https://www.toymoban.com/news/detail-559856.html
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-opengis</artifactId>
<version>${geotools.version}</version>
</dependency>
读取shp将几何要素转换为wkt文章来源地址https://www.toymoban.com/news/detail-559856.html
public List<GeoDataVo> readShpTOWkt(String shpPath) throws IOException {
System.out.println("shp解析"+shpPath);
List<GeoDataVo> list=new ArrayList<>();
File file = new File(shpPath);
if (file == null) {
return null;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
String geoType=store.getSchema().getGeometryDescriptor().getType().getName().getLocalPart();
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureCollection simpleFeatureCollection = featureSource.getFeatures();
SimpleFeatureIterator itertor = simpleFeatureCollection.features();
//遍历featurecollection
while (itertor.hasNext()) {
SimpleFeature feature = itertor.next();
String name= feature.getAttribute("Name").toString();
if(StrUtil.isEmpty(name)){
name=file.getName().substring(0,file.getName().lastIndexOf('.'));
}
String wkt= feature.getDefaultGeometry().toString();
GeoDataVo geoDataVo=new GeoDataVo();
geoDataVo.setType(geoType);
geoDataVo.setWkt(wkt);
geoDataVo.setName(name);
list.add(geoDataVo);
}
return list;
}
到了这里,关于geotools读取shp数据的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!