携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第 2 天,点击查看活动详情
ArcGIS 学习笔记系列
1、Arcgis for Android 100 系列(一)、环境配置和地图加载
2、ArcGIS for Android 100 系列(二)、地图基本操作,放大缩小,加载点线面,标注
3、ArcGIS for Android 100 系列(三)、点、线、面等图斑的常见的空间操作
本篇介绍 ArcGIS 中图斑的一些操作,比如计算线的周长、多边形的面积、两个多边形相交的面积等等。
在 ArcGIS 中,这些操作都在 GeometryEngine.java
中,注意对两个 Geometry 进行操作时,坐标系要统一。
地图上的点转为屏幕上的点
Point screenPoint = mapView.locationToScreen(mapPoint);
屏幕坐标转地图坐标
// screenPoint 是 android.graphics.Point 类型
Point mapPoint = mapView.screenToLocation(screenPoint);
坐标系转换
// GeometryEngine.project(geometry, SpatialReference spatialReference)
// 将 point 转为 wgs84 坐标系下的点
// SpatialReference.create(4326) wgs84 坐标系
Geometry project = GeometryEngine.project(point, SpatialReference.create(4326));
计算线段的长度
// new LinearUnit(LinearUnitId.METERS) 计算结果单位米
double length = GeometryEngine.lengthGeodetic(polyline, new LinearUnit(LinearUnitId.METERS), GeodeticCurveType.GEODESIC);
计算多边形的面积
// AreaUnitId.SQUARE_METERS 计算结果单位平方米
double area = GeometryEngine.areaGeodetic(geometry, new AreaUnit(AreaUnitId.SQUARE_METERS), GeodeticCurveType.GEODESIC);
对于两个几何图形之间的空间操作,前提都是它们之间的坐标系都是统一的
计算两个几何图形的相交的部分
// 两个 Geometry 都必须是同一坐标系
// 判断两个图形是否相交
boolean result = GeometryEngine.intersects(geometry1, geometry2);
// 计算两个几何图形的交集
Geometry geo = GeometryEngine.intersection(geometry1, geometry2);
计算两个多边形的互斥的部分
// 计算两个 Geometry 之间不重叠的部分
Geometry geometry = GeometryEngine.difference(geometry1, geometry2);
合并两个几何图形
// 两个 Geometry 都必须是同一坐标系
Geometry union = GeometryEngine.union(geometry1, geometry2);
判断图形 1 是否包含图形 2
// 判断 geometry1 是否包含 geometry2
boolean contains = GeometryEngine.contains(geometry1, geometry2);