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

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

ShapeFile工具類

2019-11-11 02:53:11
字體:
來源:轉載
供稿:網友

使用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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 梅州市| 平远县| 桃园县| 济源市| 视频| 红河县| 屏东市| 兴山县| 普兰店市| 磐石市| 德保县| 龙江县| 吉水县| 闽侯县| 光泽县| 云霄县| 定南县| 彰武县| 西宁市| 天水市| 武平县| 中宁县| 应城市| 天水市| 蛟河市| 常熟市| 汕头市| 水富县| 互助| 玛多县| 藁城市| 天镇县| 新民市| 芜湖县| 寿阳县| 上饶县| 五华县| 常德市| 曲靖市| 班戈县| 读书|