Android GIS开发系列-- 入门季(14)FeatureLayer之范围查询
2017-10-29 23:54
495 查看
AndroidGIS开发系列--入门季(5),这篇文章中,我们知道如何去查找要素。现在有一个需求,查找某点5000米范围的要素,那如何来做呢?首先我们需要在地图上画个5000米半径的圆,然后根据QueryParameters来查询相关要素。具体如下:
将上面的Polygon添加到GraphicsLayer中:分别计算polygon的面积与长度:
一、画个5000米半径的圆
1.确定中心点:centerPoint2.半径为50003.将一个圆分为120个点(当然可以细分更多),比如第一个点角度为0,求出sin与cos值,再分别求出经度与纬度:纬度=中心点的纬度+半径*cos值*每米的纬度偏移量 经度=中心点的经度+半径*sin值*每米的经度偏移量 相关代码如下:
/纬度每米偏移量(存在误差) publicstaticfinaldoubleONE_METER_OFFSET=0.00000899322; //计算当前纬度时经度的偏移量 publicstaticdoublecalcLongitudeOffset(doublelatitude){ returnONE_METER_OFFSET/Math.cos(latitude*Math.PI/180.0f); } //获取一个圆 privatePolygonaddGraphicCricle(PointcenterPoint,doublemeter){ List<Point>points=newArrayList<Point>(); doublesin; doublecos; doublelon; doublelat; for(doublei=0;i<120;i++){ //sin值 sin=Math.sin(Math.PI*2*i/120); //cos值 cos=Math.cos(Math.PI*2*i/120); //纬度=中心点的纬度+半径*cos值*每米的纬度偏移量 lat=centerPoint.getY()+meter*cos*ONE_METER_OFFSET; //经度=中心点的经度+半径*sin值*每米的经度偏移量 lon=centerPoint.getX()+meter*sin*calcLongitudeOffset(lat); Pointp=newPoint(lon,lat); points.add(p); } Polygonpolygon=newPolygon(); for(inti=0;i<points.size();i++){ if(i==0){ polygon.startPath(points.get(i)); }else{ polygon.lineTo(points.get(i)); } } returnpolygon; }ViewCode
将上面的Polygon添加到GraphicsLayer中:
SimpleFillSymbolfillSymbol=newSimpleFillSymbol(Color.parseColor("#88ff0000")); fillSymbol.setOutline(newSimpleLineSymbol(Color.TRANSPARENT,0)); Graphicg=newGraphic(polygon,fillSymbol); mLayer.addGraphic(g);效果如下:[/code]
doublearea=GeometryEngine.geodesicArea(polygon,SpatialReference.create(SpatialReference.WKID_WGS84),newAreaUnit(AreaUnit.Code.SQUARE_METER)); Log.e("huang","area==="+area); doublelength=GeometryEngine.geodesicLength(polygon,SpatialReference.create(SpatialReference.WKID_WGS84),newLinearUnit(LinearUnit.Code.METER)); Log.e("huang","area==="+length);结果值为与实际计算值有偏差,但偏差不是很大。[/code]
//面积:78128662.10079278 //长度:31343.779712156855[/code]
二、通过圆polygon来查询FeatureLayer在此范围内的要素
privatevoidqueryFeature(Geometrygeometry){ try{ QueryParametersargs=newQueryParameters(); args.setReturnGeometry(true);//是否返回Geometry args.setGeometry(geometry);//查询范围面 args.setInSpatialReference(SpatialReference .create(SpatialReference.WKID_WGS84)); args.setSpatialRelationship(SpatialRelationship.WITHIN); //获取查询结果result Future<FeatureResult>result=featureLayer.getFeatureTable() .queryFeatures(args,null); }catch(Exceptione){ e.printStackTrace(); } }
三、思考
其实FeatureLayer的getFeatureIDs(floatx,floaty,inttolerance)与getFeatureIDs(floatx,floaty,inttolerance,intnumberOfResults)、GraphicsLayer中的getGraphicIDs(floatx,floaty,inttolerance)与getGraphicIDs(floatx,floaty,inttolerance,intnumberOfResults)这几个查询方法也是通过范围去查询,只不过x,y是屏幕坐标,相当于中心坐标,而tolerance相当于半径,范围的大小由tolerance决定。那5dp的查找范围相当于多少范围呢?可以获取当前地图的比例尺*查找半径获取到。相关文章推荐
- Android GIS开发系列-- 入门季(4) GraphicsLayer的点击查询要素
- Android GIS开发系列-- 入门季(3) GraphicsLayer添加点、线、面
- Android GIS开发系列-- 入门季(15) 网络图层加载
- Android GIS开发系列-- 入门季(5) FeatureLayer加载本地shp文件与要素查询
- Android GIS开发系列-- 入门季(10) MapView快速定位到Geometry
- Android GIS开发系列-- 入门季(12) 显示载天地图
- Android GIS开发系列-- 入门季(9) 定位当前的位置
- Android GIS开发系列-- 入门季(13)Gdal简单写个shp文件
- Android GIS开发系列-- 入门季(2) MapView与图层介绍
- Android GIS开发系列-- 入门季(6)GraphicsLayer添加文字与图片标签
- Android GIS开发系列-- 入门季(1) 起点
- Android GIS开发系列-- 入门季(11) Callout气泡的显示
- Android 源码开发系列(三) Android RIL(Radio Interface Layer)
- Android Arcgis(14)、FeatureLayer之范围查询
- Android官方开发文档Training系列课程中文版:后台加载数据之处理CursorLoader的查询结果
- Android GIS开发系列-- 入门季(7) 利用GeometryEngine坐标转换、计算距离与面积等
- Android GIS开发系列计划
- Android官方开发文档Training系列课程中文版:后台加载数据之使用CursorLoader进行查询
- Android GIS开发系列-- 入门季(8) Json与Geometry的相互转换
- 强烈推荐Android开发技术系列文,android底层架构,android核心框架