ArcGIS API for Android case 12

Source: Internet
Author: User
I. geometric object operations and geographic Processing

Geometry operations and geoprocessing/GP are essential functions for implementing more complex GIS capabilities on the basis of maps, in this chapter, let's take a look at how the ArcGIS Android API operates on geometric objects and how to use the GP service.

Operations on geometric objects

The ArcGIS Android API is very different from other ArcGIS Web APIs in operations on geometric objects. It is not dependent on the geometry service of ArcGIS Sever, the api library contains the definition and processing of geometric objects.

If we perform the buffer operation on a geometric object, you do not need to specify a geometry service address. Instead, you can use the geometryengine class provided by ArcGIS Android API to implement these similar functions.

For example, the following code implements a buffer function:

Map. setonlongpresslistener (New Onlongpresslistener (){

Public VoidOnlongpress (FloatX,FloatY ){

Point Pt = map. tomappoint (NewPoint (x, y ));

Polygon Pg = geometryengine.Buffer(PT, map

. Getspatialreference (), 1000000,Null); // Null indicates that the unit of the map is used.

Graphic G =NewGraphic ();

G. setgeometry (PG );

Agsgeometryengine.This. Glayer. addgraphic (g );

Agsgeometryengine.This. Glayer. postinvalidate ();

}

});

In this way, when I am on the map for a long time, the program will capture the coordinates on the map, and then buffer this point through the static method buffer of geometryengine, finally, draw the result to graphicslayer. The execution result of this program is as follows:

Figure 29 result of using geometryengine to buffer a point

If you want to crop the generated polygon, you can still use geometryengine:

Map. setonlongpresslistener (New Onlongpresslistener (){

Public VoidOnlongpress (FloatX,FloatY ){

Point Pt = map. tomappoint (NewPoint (x, y ));

Polygon Pg = geometryengine.Buffer(PT, map

. Getspatialreference (), 2000000,Null);

Geometry GEO = geometryengine.Clip(PG, map. getextent (), map

. Getspatialreference (); // crops the data within the current map range.

Graphic G =NewGraphic ();

G. setgeometry (GEO );

Agsgeometryengine.This. Glayer. addgraphic (g );

Agsgeometryengine.This. Glayer. postinvalidate ();

}

});

In this way, when a circular polygon is generated by the Director near the upper left corner of the program according to the screen, the program will also call geometryengine to perform a clip operation, by performing this operation, the polygon will only be retained in the current program window. Therefore, if you drag the map, you can see that the polygon has become a pie chart, 30.

Figure 30 result of using geometryengine to crop a polygon

Related Article

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.