如何在geotools中获取特征顶点

如何在geotools中获取特征顶点,geotools,Geotools,有人能告诉我如何通过JavaGeoToolsAPI获取特征的顶点吗 在我的例子中,我在postgis中有一个多边形层,我可以查询该层的所有特征,我需要知道每个特征的顶点 SimpleFeatureSource featureSource = pgDatastore.getFeatureSource("hb_thuadat"); Filter filter = CQL.toFilter("sothua = 10"); SimpleFeatureCol

有人能告诉我如何通过JavaGeoToolsAPI获取特征的顶点吗

在我的例子中,我在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???
        }

任何帮助都是感激的!谢谢!

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

            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);

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

SimpleFeature sp = DataUtilities.simple(feature);
Geometry geom = (Geometry) sp.getDefaultGeometry();
可以按如下方式检索顶点:
coordination[]数组的坐标=geom.getCoordinates()
System.out.println(坐标的数组[0].x)//X坐标
System.out.println(坐标数组[0].y)//Y坐标