麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久男人的天堂 | 成人午夜视频网站 | 免费看毛片网站 | 成人福利软件 | 久久久一区二区 | 香蕉国产在线视频 | 精品国产一区二区在线 | 亚洲精品欧美在线 | 成人在线视频网 | 黄色的视频免费观看 | 亚洲电影在线观看高清免费 | 成人性生活视频在线观看 | 久久久久久艹 | 日韩视频一二三 | 一级全毛片 | 国产亚洲精品综合一区91555 | 一级毛片免费高清视频 | 娇喘视频在线观看 | 亚洲午夜国产 | 欧美成人一区二区三区 | 久久久久久久久久久国产精品 | 欧美一级鲁丝片免费看 | 狠狠干伊人网 | 欧美成人精品一级 | 91久久精品一区二区 | 日本欧美一区二区三区视频麻豆 | 一级做a爱视频 | 欧美视频一区二区三区四区 | 精品一区二区三区在线观看视频 | 久久免费视频在线 | 黄色毛片a级 | 久草最新在线 | 今井夏帆av一区二区 | 牛牛碰在线视频 | 国产午夜免费不卡精品理论片 | 99亚洲| 在线观看免费视频麻豆 | 看片一区二区三区 | 欧美性黄| 欧美日韩亚洲视频 | 91麻豆蜜桃一区二区三区 |