3

有人可以告诉我如何通过 java geotools api 获取特征顶点吗?

就我而言,我在 postgis 中有一个多边形层,我可以查询该层的所有特征,并且我需要知道每个特征的顶点。

        SimpleFeatureSource featureSource = pgDatastore.getFeatureSource("hb_thuadat");
        Filter filter = CQL.toFilter("sothua = 10");
        SimpleFeatureCollection collection = featureSource.getFeatures( filter );
        System.out.print("tong so:"+ collection.size());

        FeatureIterator iter=collection.features();
        while( iter.hasNext() ){
            Feature feature = iter.next();
            System.out.println( feature.getIdentifier());
            //how to get vertices of feature here???
        }

任何帮助表示感谢!感谢!

4

2 回答 2

5

通过将feature对象转换为SimpleFeature类型,您应该能够提取几何值,如下所示:

SimpleFeature sp = DataUtilities.simple(feature);
Geometry geom = (Geometry) sp.getDefaultGeometry();

可以像下面这样检索顶点:
Coordinate[] array_of_coords = geom.getCoordinates(); System.out.println(array_of_coords[0].x);//X Coordinate System.out.println(array_of_coords[0].y);//Y Coordinate

于 2013-10-25T07:36:48.390 回答
0

我通过这段代码找到了自己的解决方案

            Feature feature = iter.next();
            SimpleFeature sfeature = (SimpleFeature)feature;
            Geometry g = (Geometry)sfeature.getAttribute("the_geom");
            // System.out.print(g.getCoordinates().length);
            Coordinate coor = g.getCoordinate();
            System.out.println("x: " + coor.x);
            System.out.println("y: " + coor.y);
于 2013-10-25T07:25:28.960 回答