gpt4 book ai didi

geotools - 如何在geotools中获取特征的顶点

转载 作者:行者123 更新时间:2023-12-02 22:15:35 27 4
gpt4 key购买 nike

有人可以告诉我如何通过 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???
}

任何帮助都是值得赞赏的!谢谢!

最佳答案

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

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

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

关于geotools - 如何在geotools中获取特征的顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19583034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com