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

首頁 > 學院 > 開發(fā)設計 > 正文

ShapeFile工具類

2019-11-11 03:22:05
字體:
供稿:網(wǎng)友

使用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中的空間數(shù)據(jù) * @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工具類持續(xù)完善中…… 參考資料:http://www.cnblogs.com/cugwx/p/3719195.html


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 威信县| 仙居县| 大竹县| 青阳县| 洪湖市| 平泉县| 拜城县| 金湖县| 泸州市| 千阳县| 建昌县| 东丽区| 花莲市| 前郭尔| 昌都县| 新晃| 铜山县| 余庆县| 浦北县| 临安市| 宁强县| 新竹市| 洪湖市| 宁远县| 玉山县| 德庆县| 贞丰县| 马山县| 大邑县| 龙口市| 营口市| 怀柔区| 荔波县| 崇阳县| 建湖县| 大新县| 清远市| 东安县| 卢氏县| 鹤峰县| 渝中区|