Android Arcgis入门(七)、利用GeometryEngine坐标转换、计算距离与面积等
2017-05-06 15:37
603 查看
GeometryEngine是Arcgis的重要工具类,利用此工具类,可以计算地图上的距离、面积,将点、线、面转化为Json数据,将Json转化为点线面,坐标转换作用非常强大。
将上面的代码运行,发现distance为110.75107527319621,我们带入的单位是km也就是110km,而1纬度相差110KM左右。计算还是比较准确的。
另外,GeometryEngine还有许多的方法都非常实用,这里就不一一讲解了。
一、坐标转化
将用到方法 GeometryEngine.project(Geometry geometry, SpatialReference inputSR, SpatialReference outputSR),第二个为Geometry的坐标,第三个参数为要转换的坐标。如果将84坐标转换为墨卡托坐标代码如下:Point point1 = new Point(113,23); Point point2 =(Point)GeometryEngine.project(point1,SpatialReference.create(SpatialReference.WKID_WGS84), SpatialReference.create(SpatialReference.WKID_WGS84_WEB_MERCATOR));
二、GeometryEngine计算两点的距离
用到 GeometryEngine.geodesicDistance(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference, LinearUnit distanceUnit)方法。注意最好不要用GeometryEngine.distance方法,此方法是计算2D长度的,计算不准确。代码如下:Point point1 = new Point(113,23); Point point2 = new Point(113,24); double distance = GeometryEngine.geodesicDistance(point3,point4, SpatialReference.create(SpatialReference.WKID_WGS84), new LinearUnit(LinearUnit.Code.KILOMETER)); Log.i("TAG","distance ==="+distance );
将上面的代码运行,发现distance为110.75107527319621,我们带入的单位是km也就是110km,而1纬度相差110KM左右。计算还是比较准确的。
三、GeometryEngine计算面积
用到的方法是 GeometryEngine.geodesicArea(Geometry geometry, SpatialReference spatialReference, AreaUnit areaUnit),做个测试的代码。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));//单位为平方米
四、计算周长
如果我们要计算一条线或一个面的周长是,可以用到这个方法 GeometryEngine.geodesicLength(Geometry geometry, SpatialReference spatialReference, LinearUnit lengthUnit),直接上代码: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));
另外,GeometryEngine还有许多的方法都非常实用,这里就不一一讲解了。
相关文章推荐
- Android GIS开发系列-- 入门季(7) 利用GeometryEngine坐标转换、计算距离与面积等
- arcgis for ios 计算距离和面积
- ArcGIS for Android Runtime100 基本操作(一)——点线面测距离长度和面积
- ArcGIS for Android地图上实际距离与对应的屏幕像素值计算
- ArcGIS for Android地图上实际距离与对应的屏幕像素值计算
- 随机计算TFIDF作为权重,然后利用余弦距离进行聚类,用的是简单k-means算法。
- 利用经纬度计算距离
- 利用JavaScript实现的根据经纬度计算地球上两点之间的距离
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- c#中利用google map距离计算公式实现两点间距离的计算
- ArcGis中投影的方法以及计算面积的方法
- 转载 Android计算地图上两点距离
- 利用google map api计算两地距离
- Android获取经纬度、计算距离、方位角
- Android 计算地球上两点的距离
- 在ArcGIS中,利用“行政单元面积权重法”实现人口数据格网化
- 利用google directions api计算距离
- ArcGIS 图斑椭球面积计算,零星面积计算,线扣除检查,线状扣除面积扣除计算
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- Android-x86入门之--如何利用android-x86取代模拟器进行应用程序的开发