java读取shp文件中的属性
解决方法:
1.pom.xml
<dependencies>
<!--java导入矢量图shp数据-->
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-mysql</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>2.7.2</version>
</dependency>
<!--java导入矢量图shp数据-->
</dependencies>
<!--java导入矢量图shp数据-->
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
</repositories>
2.java读取shp文件
SimpleFeatureSource featureSource = readSHP("C:\\Users\\Administrator\\Desktop\\jzw84\\jmd84_lbl.shp");
//开始写入数据
try {
SimpleFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator features = featureCollection.features();
while (features.hasNext()) {
SimpleFeature feature = features.next();
Iterator<? extends Property> iterator = feature.getValue().iterator();
while (iterator.hasNext()) {
Property property = iterator.next();
Name name = property.getName();//属性名称
final Object value = property.getValue();//属性值
System.out.println(property);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}