如何从几何 arcgis android 中找到中心点?

How to find Center Point from geometry arcgis android?

我正在开发一个应用程序,因为我想在我的地图上的几何中心显示标注我是新手 arcgis.I 尝试了很多但我无法在中心显示标注,请任何人帮我解决这个问题

我的代码

SimpleFillSymbol sfs = new SimpleFillSymbol(
                                        Color.RED);
                                sfs.setAlpha(5);
                                graphic = new Graphic(feature.getGeometry(),
                                        sfs, feature.getAttributes());
                                Polygon polygon = (Polygon) graphic
                                        .getGeometry();




                                int polygonpointscount=polygon.getPointCount();
                                if(polygonpointscount!=0)
                                {
                                    pointsize=polygonpointscount/2;
                                }
                                Point midpoint = polygon.getPoint(pointsize);
                                Callout callout = mMapView.getCallout();  
                                if (callout != null
                                        && callout.isShowing()) {
                                    callout.hide();
                                }
                                //Set the content, show the view  
                                callout.setContent(adminsearchloadView(governorate_Name,                              
                                area_Name,
                                        block_Number)); 
                                callout.setStyle(R.xml.calloutstyle);  
                                callout.setMaxHeight(100000);
                                callout.setMaxWidth(100000);
                                callout.refresh();
                                callout.show(midpoint); 

如果您使用 arcgis server,您可以尝试 "feature to point": http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000003m000000 来计算质心图层。

简答:使用GeometryEngine.getLabelPointForPolygon(Polygon, SpatialReference)

长答案:

根据您的代码...

int polygonpointscount=polygon.getPointCount();
if(polygonpointscount!=0)
{
    pointsize=polygonpointscount/2;
}

Polygon.getPointCount() returns 多边形的顶点。例如,如果多边形是矩形,则 getPointCount() return 是角。因此,您的 Callout 将位于其中一个角而不是质心。

相反,使用GeometryEngine.getLabelPointForPolygon(Polygon, SpatialReference)。它不能保证 return 质心,但它 return 是一个适合标记的内部点(对我来说它看起来像质心)。确保你传递了一个 SpatialReference 对象来告诉 getLabelPointForPolygon 你的多边形的空间参考是什么。

如果您必须拥有质心,则需要基于 ArcGIS 的 Feature to Point 工具创建地理处理服务。但是,getLabelPointForPolygon 更容易实施,执行起来也更快,可能会满足您的需要。