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