geotools读取shapefile文件
2015-11-28 22:46
337 查看
依赖
Java代码
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
代码
Java代码
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表达形式
}
Java代码
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency> <groupId>org.geotools</groupId> <artifactId>gt-shapefile</artifactId> <version>${geotools.version}</version> </dependency>
代码
Java代码
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表达形式
}
相关文章推荐
- Spring4 JDBC详解
- 分布式文件系统与HDFS
- bzoj 3535Fair Photography【hash】
- 森林病虫防治系统 (七.1)
- Linux常用服务部署与优化
- 表单开发的一些细节技巧(jsp+js)
- 虚拟机redhat6.5的yum源配置
- srtp项目的看法
- JS贪吃蛇游戏
- setsockopt
- Cocos2dx 3.8 ui资源读取
- 南大软院二十一天成神计划
- Oracle导入导出
- C/C++对一个整数求出每一位的数值
- Effective c++学习笔记四
- poj 2516 Minimum Cost 最小费用流
- bs(二)表单(按钮、input、图片图标)
- struts2 OGNL # % $
- opendalight(Li) northbound APP 开发
- 平均场景法分割前景目标