国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ShapeFile工具類

2019-11-11 04:58:54
字體:
來源:轉載
供稿:網友

使用GeoTools讀取ShapeFile文件,測試版本為geotools-16.1。 所需jar包有 這里寫圖片描述

package com.test;import java.io.File;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.List;import org.geotools.data.shapefile.ShapefileDataStore;import org.geotools.data.shapefile.ShapefileDataStoreFactory;import org.geotools.data.shapefile.files.ShpFiles;import org.geotools.data.shapefile.shp.ShapefileReader;import org.geotools.data.simple.SimpleFeatureCollection;import org.geotools.data.simple.SimpleFeatureSource;import com.vividsolutions.jts.geom.Geometry;import com.vividsolutions.jts.geom.GeometryFactory;public class ShapeFileUtils { /** * 獲取shape文件feature集合 * @param shapePath shape文件路徑 * @param charSet 讀取shape文件編碼 * @return SimpleFeatureCollection */ public static SimpleFeatureCollection ReadShapeFileFeatures(String shapePath, String charSet){ SimpleFeatureCollection sfc = null; ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); ShapefileDataStore sds = null; try { sds = (ShapefileDataStore)dataStoreFactory.createDataStore(new File(shapePath).toURI().toURL()); sds.setCharset(Charset.forName(charSet)); SimpleFeatureSource featureSource = sds.getFeatureSource(); sfc = featureSource.getFeatures(); } catch (Exception e) { e.PRintStackTrace(); }finally{ sds.dispose(); } return sfc; } /** * 讀取ShapeFile中的空間數據 * @param shapeFilePath * @return List<Geometry> */ public static List<Geometry> getGeometriesFromShapeFile(String shapeFilePath){ List<Geometry> result = new ArrayList<Geometry>(); try { ShpFiles file = new ShpFiles(shapeFilePath); ShapefileReader reader = new ShapefileReader(file, false, false, new GeometryFactory()); while(reader.hasNext()){ result.add((Geometry)reader.nextRecord().shape()); } reader.close(); } catch (Exception e) { e.printStackTrace(); } return result; }}

測試類如下。

package com.test;import org.geotools.data.simple.SimpleFeatureCollection;import org.geotools.data.simple.SimpleFeatureIterator;import org.opengis.feature.simple.SimpleFeature;import com.tongtu.mobile.cuanalysis.utils.ShapeFileUtils;import com.vividsolutions.jts.geom.Geometry;public class ShapeFileTest { public static void main(String[] args) throws Exception{ SimpleFeatureCollection sfc = ShapeFileUtils.ReadShapeFileFeatures("D://z工具類持續完善中…… 參考資料:http://www.cnblogs.com/cugwx/p/3719195.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蓝田县| 汾西县| 渭南市| 乌鲁木齐县| 巴林右旗| 攀枝花市| 中山市| 锦屏县| 龙川县| 张家界市| 聊城市| 奉节县| 苍山县| 涡阳县| 常州市| 合山市| 都安| 天柱县| 泰和县| 循化| 江门市| 连平县| 马关县| 聂拉木县| 淮南市| 秭归县| 泸定县| 白玉县| 化州市| 虞城县| 长海县| 江阴市| 武山县| 阿勒泰市| 都匀市| 峨山| 洛扎县| 津南区| 阳城县| 南靖县| 太仓市|