ArcGIS for Android 10.2.9(8):計算距離,周長,面積
阿新 • • 發佈:2019-02-16
GeometryEngine是Arcgis的重要工具類,利用此工具類,可以計算地圖上的距離、面積,將點、線、面轉化為Json資料,將Json轉化為點線面,座標轉換作用非常強大。
1.計算距離:
//計算兩點距離:
Point point1 = new Point(113, 23);
Point point2 = new Point(113, 24);
double distance = GeometryEngine.geodesicDistance(point1, point2,
SpatialReference.create(SpatialReference.WKID_WGS84),
new LinearUnit(LinearUnit.Code.KILOMETER)); //單位
Log.e("xyh", "distance ==" + distance);
2.計算周長:
//計算周長
Polyline polyline = new Polyline();
polyline.startPath(new Point(110, 13));
polyline.lineTo(new Point(115, 13));
polyline.lineTo(new Point(115, 23));
double length = GeometryEngine.geodesicLength(polyline,
SpatialReference.create(SpatialReference.WKID_WGS84),
new LinearUnit(LinearUnit.Code.METER));
Log.e("xyh", "length==" + length);
//還可以用這種方法計算線段長度
double v = polyline.calculateLength 2D();
3.計算面積:
//計算面積
Polygon polygon = new Polygon();
polygon.startPath(new Point(110, 13));
polygon.lineTo(new Point(115, 13));
polygon.lineTo(new Point(115, 23));
double area = GeometryEngine.geodesicArea(polygon,
SpatialReference.create(SpatialReference.WKID_WGS84),
new AreaUnit(AreaUnit.Code.SQUARE_METER));//單位為平方米
Log.e("xyh", "area==" + area);
// 還可以用這種方法計算面積
double area2D = polygon.calculateArea2D();