geotools读取shapefile文件

原文链接: http://www.cnblogs.com/hanhuibing/articles/5664821.html

依赖

Java代码   收藏代码
  1.   
  2.             org.geotools  
  3.             gt-shapefile  
  4.             ${geotools.version}  
  5.           

 

代码

Java代码   收藏代码
  1. File file = new File("D:\\shapefiles\\states.shp");  
  2.        Map map = new HashMap();  
  3.        map.put("url", file.toURI().toURL());  
  4.   
  5.        DataStore dataStore = DataStoreFinder.getDataStore(map);  
  6.        String typeName = dataStore.getTypeNames()[0];  
  7.   
  8.        FeatureSource source = dataStore  
  9.                .getFeatureSource(typeName);  
  10.   
  11.        FeatureCollection collection = source.getFeatures();  
  12.        FeatureIterator features = collection.features();  
  13.            while (features.hasNext()) {  
  14.                SimpleFeature feature = features.next();  
  15.                System.out.print(feature.getID());  
  16.                System.out.print(": ");  
  17.                System.out.println(feature.getDefaultGeometryProperty().getValue());//此行输出的空间信息的wkt表达形式  
  18.            } 

转载于:https://www.cnblogs.com/hanhuibing/articles/5664821.html

你可能感兴趣的:(geotools读取shapefile文件)