Geometry engine

Once you have a geometry either from one constructed with code, as shown in the previous section, or one from clicking on (selecting) it, you can now perform geometric operations to derive other geometries by using the GeometryEngine class. What's powerful about this class is that it allows you to perform these operations in a connected and disconnected setting. It will also calculate the area or length of geometries such as polygons or polylines, respectively. With that said, there are too many options to describe, so we'll illustrate just a couple of them to give you a taste of what's possible.

Project

The Project method is one of the most important geometrical operations you will need from GeometryEngine, because it allows you to convert coordinates from one coordinate system to another. Users often want to enter coordinates in one coordinate system, but the basemap or layer in which the data will be stored will be in another coordinate system. As a result, you will need to re-project these coordinates. Also, in many apps, the user will enter data in one coordinate system, but the dialog they entered the data into will need to convert the units into another. Here is a typical use of this method:

MapPoint mapPointLatLon = new MapPoint(-80.845504, 35.211432, 
    SpatialReferences.Wgs84);

var webMercatorSpatialRef = new Geometry.SpatialReference(102100);
var webMercatorPoint = GeometryEngine.Project(mapPointLatLon,  
    webMercatorSpatialRef);

In this example, a set of coordinates in latitude/longitude have been converted to WebMercator. This is a very common projection for Web maps and the basemaps of Esri.

Buffering

Buffering is an analytical operation that allows you to do proximity analysis. For example, you can take a MapPoint class and buffer it to derive a polygon, which can then be used to select everything in a layer that touches or overlaps this buffer. Here's a code sample:

MapPoint mapPointLatLon = new MapPoint-80.845504, 35.211432, 
    SpatialReferences.Wgs84);

var webMercatorSpatialRef = new 
    Esri.ArcGISRuntime.Geometry.SpatialReference(102100);
var myWebMercPoint = GeometryEngine.Project(mapPointLatLon, 
    webMercatorSpatialRef);

Geometry buffer = GeometryEngine.Buffer(myWebMercPoint, 10000);

In this code, we've created a MapPoint class using latitude/longitude, re-projected it to Mercator, and then buffered the point with a distance of 10,000 meters. We needed to re-project the MapPoint class because we needed to use a linear distance in meters. Once that is done, we then buffered it and produced a geometry. A buffer always creates a resulting polygon, so it can be cast to polygon. Here's a nice diagram from Esri (https://developers.arcgis.com/net/desktop/guide/GUID-0D7163BF-1724-414F-A58C-F3361B648B36-web.png) that shows what happens when you buffer polygons, polylines, and points.

Buffering

Once you have a buffer, you can perform other operations on it using GeometryEngine, such as measure its area like this:

double polyArea = GeometryEngine.Area(buffer);

The GeometryEngine method contains the following operations that you will need to investigate to solve the problem you are trying to solve. Here's a complete list of operations:

  • Area
  • AutoComplete
  • Boundary
  • Buffer
  • Clip
  • Contains
  • ConvexHull
  • Crosses
  • Cut
  • Densify
  • Difference
  • Disjoint
  • Distance
  • Equals
  • Extend
  • Generalize
  • GeodesicArea
  • GeodesicBuffer
  • GeodesicDensify
  • GeodesicDistance
  • GeodesicEllipse
  • GeodesicLength
  • GeodesicMove
  • GeodesicSector
  • Intersection
  • Intersects
  • LabelPoint
  • Length
  • NearestCoordinate
  • NearestVertex
  • Offset
  • Overlaps
  • Project
  • Relate
  • Reshape
  • ShapePreservingArea
  • ShapePreservingLength
  • SymmetricDifference
  • Touches
  • Union
  • Within

It should be noted that the preceding buffer used Euclidean distance, which would not be accurate for large areas on a globe because the Earth is an ellipsoidal shape. To do this correctly, use GeodesicBuffer because it will account for the actual shape of Earth. An Euclidian buffer works fine for small areas, such as when all of the geometries are within one UTM zone. For larger areas, use GeodesicBuffer. Here's an example of the differences, which can also be seen at http://www.esri.com/news/arcuser/0111/graphics/geodesic_6.jpg:

Buffering

Difference in the buffers

As shown in the preceding screenshot, the Geodesic buffer is larger, and in this case accurate because it covers a larger area of the surface of Earth. These kinds of difference also apply to polyline geometry.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.151.164