讀取shp
pom依賴文章來源:http://www.zghlxwxcb.cn/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將幾何要素轉(zhuǎn)換為wkt文章來源地址http://www.zghlxwxcb.cn/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;
}
到了這里,關(guān)于geotools讀取shp數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!