在ArcGIS SOE開發中,由前端繪製並傳遞一個Polygon作爲參數,在ArcGIS SOE中進行後續處理,具體代碼如下:
IPolygon boundaryPolygon = Conversion.ToGeometry(summaryBoundaryJSO, esriGeometryType.esriGeometryPolygon)
as IPolygon;
IArea pArea = boundaryPolygon as IArea;
double area = pArea.Area;
實際測試中,發現有時候解析到的Polygon中,有時候面積竟然爲負數。
比如下述複雜的多邊形(紫色)
而且多邊形的面積爲負數時,該多邊形進行空間檢索時,結果也很不可預測,應當空間查詢到的對象有時候會查詢不到。
推測可能是前端傳遞的Geometry對象存在某種幾何錯誤。
所以,在對Geometry進行處理之前,增加了如下代碼:
IPolygon boundaryPolygon = Conversion.ToGeometry(summaryBoundaryJSO, esriGeometryType.esriGeometryPolygon)
as IPolygon;
boundaryPolygon.Close();
ITopologicalOperator pBoundaryTop = boundaryPolygon as ITopologicalOperator;
pBoundaryTop.Simplify();
問題解決,沒有出現面積爲負數的情況。