Android GIS Development Series--Introductory season (Featurelayer) range query

Source: Internet
Author: User
Tags cos sin

Android GIS Development Series-Introductory season (5), in this article, we know how to find features. Now there is a need to find a point 5000 meters in the range of features, then how to do it? First we need to draw a circle with a radius of 5000 meters on the map and then query the relevant features based on the queryparameters. Specific as follows:

One, draw a circle with a radius of 5000 meters

1. Determine the center point: centerpoint
2. Radius of 5000
3. Divide a circle into 120 points (which can, of course, subdivide more), such as the first point angle of 0, find the sin and cos values, and then find the longitude and latitude respectively:

纬度= 中心点的纬度+半径*cos值*每米的纬度偏移量经度= 中心点的经度+半径*sin值*每米的经度偏移量

相关代码如下 :

/latitude per meter offset (presence error) Public Static Final DoubleOne_meter_offset = 0.00000899322; //offset of longitude when calculating current latitude     Public Static DoubleCalclongitudeoffset (Doublelatitude) {        returnOne_meter_offset/math.cos (Latitude * math.pi/180.0f); }    //Get a circle    PrivatePolygon addgraphiccricle (Point CenterPoint,Doublemeter) {List<Point> points =NewArraylist<point>(); Doublesin; DoubleCos; DoubleLon; Doublelat;  for(Doublei = 0; I < 120; i++) {            //Sin valueSin = Math.sin (Math.PI * 2 * i/120); //Cos valuecos = Math.Cos (Math.PI * 2 * i/120); //Latitude = latitude of Center point + radius *cos value * Latitude offset per metrelat = centerpoint.gety () + meter*cos*One_meter_offset; //Longitude = Longitude of Center point + radius *sin value * Longitude offset per metrelon = CENTERPOINT.GETX () + meter *sin*calclongitudeoffset (LAT); Point P=NewPoint (Lon,lat);        Points.Add (P); } Polygon Polygon=NewPolygon ();  for(inti = 0; I < points.size (); i++) {            if(i==0) {Polygon.startpath (Points.get (i)); }Else{Polygon.lineto (Points.get (i)); }        }        returnPolygon; }
View Code

Add the above polygon to the Graphicslayer:

SimpleFillSymbol fillSymbol = new SimpleFillSymbol(Color.parseColor("#88ff0000"));                fillSymbol.setOutline(new SimpleLineSymbol(Color.TRANSPARENT, 0)); Graphic g = new Graphic(polygon, fillSymbol); mLayer.addGraphic(g);



Calculate the area and length of the polygon separately:
Double area = Geometryengine. Geodesicarea (Polygon, spatialreference.create (Spatialreference; Log.E ( "Huang",  "area===" + Area) .geodesiclength ( Polygon, Spatialreference.create (spatialreference ; Log.E ( "Huang",  "area===" + Length)             

The result value is biased against the actual calculated value, but the deviation is not very large.
//面积:78128662.10079278//长度:31343.779712156855

Second, through the round polygon to query Featurelayer in this range of elements
Private voidqueryfeature (Geometry Geometry) {Try{queryparameters args=Newqueryparameters (); Args.setreturngeometry (true);//whether to return geometryArgs.setgeometry (geometry);//Query Range polygonsargs.setinspatialreference (spatialreference. Create (SPATIALREFERENCE.WKID_WGS84));            Args.setspatialrelationship (Spatialrelationship.within); //get query Results resultfuture<featureresult> result =featurelayer.getfeaturetable (). Queryfeatures (args,NULL); } Catch(Exception e) {e.printstacktrace (); }    }
Third, thinking

In fact Featurelayer's getfeatureids (float x, float y, int tolerance) and
Getfeatureids (float x, float y, int tolerance, int numberofresults),

Graphicslayer in Getgraphicids (float x, float y, int tolerance) and
Getgraphicids (float x, float y, int tolerance, int numberofresults)
These query methods are also queried by scope, except that x, Y is the screen coordinate, which is equivalent to the center coordinate, and tolerance is equivalent to the radius, the size of the range is determined by tolerance. What is the size of the 5DP search range?
Can get the scale of the current map * find radius gets to.


















 

Android GIS Development Series-The beginning of the season Featurelayer range query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.