2017-10-06 2 views
2

これは私が正しい方法でそれをやっていることを望むので、これは私の最初の質問stackoverflowです。GeoToolsを使用してshapeFile .shp内のポリゴンのすべてのポイントを取得するにはどうすればよいですか?

ジオツールを使用してshapeFile(.shp)を読み込んでいて、ポリゴンのすべての点を取得する関数が見つかりません。今では私は、次のコードを持っている:

public class ImportShapeFileService implements ImportShapeFileServiceInterface { 

    @Override 
    public void loadShapeFile(File shapeFile) throws MdfException { 

     FileDataStore store; 
     try { 
      store = FileDataStoreFinder.getDataStore(shapeFile); 
      SimpleFeatureSource featureSource = store.getFeatureSource(); 
      SimpleFeatureCollection collection = featureSource.getFeatures(); 

      ReferencedEnvelope env = collection.getBounds(); 
      double left = env.getMinX(); 
      double right = env.getMaxX(); 
      double top = env.getMaxY(); 
      double bottom = env.getMinY(); 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

私はshapFileの4つの境界を取得していますが、ではなく、それはそれを行うことが可能含まれているポリゴンのポイントですか?

ありがとうございます。あなたがいうだけの座標よりPointを持っている必要があります(そして、あなたができた後、ポリゴンを持っていることを確認している場合は

try(SimpleFeatureIterator itr1 = features.features()){ 
    while(itr1.hasNext()){ 
    SimpleFeature f = itr1.next(); 
    Geometry g = (Geometry)f.getDefaultGeometry(); 
    Coordinate[] coords = g.getCoordinates(); 
    // do something with the coordinates 
    } 
} 

+0

IポイントがIは、図の各点の緯度と経度を意味前記 –

+0

'SimpleFeatureIterator'と[例]のために、形状を調べ(http://docs.geotools.org/。 stable/userguide/tutorial/geometry/geometrycrs.html)? – trashgod

答えて

1

あなたがポイントで何をしたいのかに応じて、私のような何かをしたいです使用:

Geometry g = (Geometry)f.getDefaultGeometry(); 
    for(int i=0;i<g.getNumPoints();i++) { 
    Point p=((Polygon)g).getExteriorRing().getPointN(i); 
    } 
関連する問題