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表达形式
- }
人在山中,才知道,白云也可以抓上一把,苍翠竟有清甜的味道。
人在山中,才知道,高度永远是一个变量,而快乐则是附于中跋涉过程的函数。
人在山中,才知道,庄严是望远时的一种心境,高处才能指点江山。