Javaは、形状ファイルを読みます

C#の場合、私が代わりに読んで、JavaベースのGeoToolを使用して、互換性のないバージョンが原因ArcEngine開発を、使用することをお勧め

 

依存以下のポンポン

<プロパティ>
<geotools.version> 19.1 </geotools.version>
</プロパティ>

<リポジトリ>
<リポジトリ>
<ID> OSGEO </ ID>
<名前>オープンソース地理空間財団リポジトリ</名前>
<URL> http://download.osgeo.org/webdav/geotools/ </ URL>
</リポジトリ>
<リポジトリ>
<ID> geosolutions </ ID>
<名前> geosolutionsリポジトリ</名前>
<URL> http://maven.geo-solutions.it/ </ URL>
<スナップショット>
<</有効真>有効>
</スナップショット>
<リリース>
<が有効になって>真</有効>
</リリース>
</リポジトリ>
</リポジトリ>

<依存性>
<依存性>
<のgroupId> org.slf4j </のgroupId>
<たartifactId> JCLオーバーSLF4J </たartifactId>
<バージョン> 1.7.5 </バージョン>
</依存>
<依存性>
<のgroupId> ORG。 SLF4J </のgroupId>
<たartifactId> SLF4J-API </たartifactId>
<バージョン> 1.7.5 </バージョン>
</依存>
<依存性>
<のgroupId> org.slf4j </のgroupId>
<たartifactId> SLF4J-log4j12 </たartifactId>
<バージョン> 1.7.5 </バージョン>
</依存関係>

<依存性>
<のgroupId> nl.pdok </のgroupId>
<たartifactId> geoserverマネージャ</たartifactId>
<バージョン> 1.7.0-pdok2 </バージョン>
</依存>

 

<依存性>
<のgroupId> JUnitの</のgroupId>
<たartifactId> JUnitの</たartifactId>
<バージョン> 4.11 </バージョン>
<スコープ>テスト</スコープ>
</依存>
<依存性>
<のgroupId> org.geotools </ groupId>
<たartifactId> GT-シェープ</たartifactId>
<バージョン> $ {geotools.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.geotools </のgroupId>
<たartifactId> GT-スイング</たartifactId>
<バージョン> $ {geotools.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.geotools </のgroupId>
<たartifactId> GT-JDBC </たartifactId>
<バージョン> $ {geotools.version} </バージョン>
</依存>
<依存性>
<のgroupId> org.geotools.jdbc </のgroupId>
<たartifactId> GT-JDBC-PostGISの</たartifactId>
<バージョン> $ {geotools.version} </バージョン>
</依存>

<依存性>
<のgroupId> org.geotools </のgroupId>
<たartifactId> GT-EPSG-HSQL </たartifactId>
<バージョン> $ {geotools.version} </バージョン>
</依存>
</依存関係>

 

 

 

パッケージreadshape。
輸入org.geotools.data.FileDataStore;
輸入org.geotools.data.FileDataStoreFinder。
輸入org.geotools.data.shapefile.ShapefileDataStore;
輸入org.geotools.data.simple.SimpleFeatureCollection。
輸入org.geotools.data.simple.SimpleFeatureIterator;
輸入org.geotools.data.simple.SimpleFeatureSource。
輸入org.opengis.feature.simple.SimpleFeature。
輸入org.opengis.filter.Filter;

輸入com.vividsolutions.jts.geom.Coordinate;
輸入com.vividsolutions.jts.geom.Geometry;
輸入com.vividsolutions.jts.geom.MultiPolygon;
輸入com.vividsolutions.jts.geom.Polygon;


インポートのjava.io.File;
インポートにjava.io.IOException;
輸入いるjava.nio.charset.Charset;

パブリッククラス読む{

パブリック静的無効メイン(文字列[] args){
文字列パス1 = "E:\\テスト\\ TestOpenLayers \\データ\\ wafangdian_0 \\ wafangdianshi_0.shp"。
//读取SHP
SimpleFeatureCollection colls1 = readShp(パス1)。
//拿到所有特徴
SimpleFeatureIterator iters = colls1.features()を。

//遍历打印
一方(iters.hasNext()){


SimpleFeature SF = iters.next()。
オブジェクトSS = sf.getDefaultGeometry()。
System.out.println(SS)。
System.err.println(sf.getDefaultGeometryProperty()のgetValue()。)。
幾何形状=(ジオメトリ)SS。
System.err.println(shape.toText())。
//印刷内容が同じMULTIPOLYGONある(((107.92820000000006 26.66963000000004、107.92820000000006 26.69963000000007、26.69963000000007 107.95820000000003、107.95820000000003 26.66963000000004、26.66963000000004 107.92820000000006)))
//は、スプライスSQLのPostgreSQLに直接書き込むことができる

/ * INSERT INTOテーブル(GEOM)
VALUES

st_geomfromtext( 'MULTIPOLYGON(((107.92820000000006 26.66963000000004、107.92820000000006 26.69963000000007、26.69963000000007 107.95820000000003、107.95820000000003 26.66963000000004、26.66963000000004 107.92820000000006)))'、4326)


* /

//クラスcom.vividsolutions.jts.geom.MultiPolygon

IF(SS instanceofはポリゴン) {
ポリゴンは、多角形(ポリゴン)SSを=、

座標[] = polygon.getCoordinates座標();
}

そうであれば(MultiPolygonのinstanceofのSS){
MultiPolygonのマルチポリゴン=(MultiPolygonの)SS。
文字列MULT = multiPolygon.toString()。
座標[]座標= multiPolygon.getCoordinates()。
System.err.println(coordinates.length)。

}

System.err.println(ss.getClass()のtoString())。


System.out.println(sf.getID()+ "" + sf.getAttributes());
}
}

パブリック静的SimpleFeatureCollection readShp(文字列のパス){
リターンreadShp(パス、NULL);

}

パブリック静的SimpleFeatureCollection readShp(文字列パスフィルタフィルタ){
SimpleFeatureSource featureSource = readStoreByShp(パス)。
(featureSource == nullの)リターン場合はnull;
{試みる
リターンフィルタを!= nullの?featureSource.getFeatures(フィルタ):featureSource.getFeatures();
}キャッチ(IOExceptionを電子){
e.printStackTrace();
}
はnullを返します。
}

パブリック静的SimpleFeatureSource readStoreByShp(文字列のパス){
ファイルファイル=新しいファイル(パス)。
FileDataStore店。
SimpleFeatureSource featureSource = NULL;
{試みる
店= FileDataStoreFinder.getDataStore(ファイル)。
((ShapefileDataStore)店舗).setCharset(Charset.forName( "UTF-8"));
featureSource = store.getFeatureSource()。
}キャッチ(IOExceptionを電子){
e.printStackTrace();
}
featureSourceを返します。
}

}

おすすめ

転載: www.cnblogs.com/zt2710/p/12112528.html