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

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

ShapeFile工具類

2019-11-11 03:22:44
字體:
來源:轉載
供稿:網友

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昌图县| 蒙自县| 沅江市| 逊克县| 满洲里市| 平凉市| 西昌市| 焦作市| 海南省| 正镶白旗| 长沙县| 南江县| 弥勒县| 临邑县| 清流县| 鲁山县| 胶南市| 庆元县| 北安市| 哈尔滨市| 兴安县| 卢湾区| 平顶山市| 毕节市| 新蔡县| 利津县| 西青区| 洛扎县| 临安市| 鹤山市| 志丹县| 当阳市| 青冈县| 枣强县| 左权县| 堆龙德庆县| 民和| 浠水县| 万州区| 冀州市| 萨迦县|