Skip to content

ProGuide Relational Operations

UmaHarano edited this page May 6, 2024 · 19 revisions
Language:      C#
Subject:       Geometry
Contributor:   ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization:  Esri, http://www.esri.com
Date:          04/04/2024
ArcGIS Pro:    3.3
Visual Studio: 2022

This ProGuide shows how the Relate method of the GeometryEngine class can express existing relational operations. In this example, you're expressing the Overlap method by creating a pattern matrix string as described in the Geometry ProConcepts. Imagine polygon geometries in the following configuration:

ProGuide: Geometry - Spatial Relationship Overlap

In this example of testing the relationship between geometries, you're expressing the relationship where A-B evaluates to true and A-C evaluates to false.

Create overlapping geometries

You'll create polygon geometries similar to the configuration in the previous image. The coordinates in this example are in Redlands, California, and WebMercator is the projected coordinate system.

// create polygon A by creating a list of the corner coordinates
List<Coordinate2D> coordinatesPolygonA = new List<Coordinate2D>();
coordinatesPolygonA.Add(new Coordinate2D(-13046461, 4036405)); // top-left coordinate
coordinatesPolygonA.Add(new Coordinate2D(-13046423, 4036405)); // top-right coordinate
coordinatesPolygonA.Add(new Coordinate2D(-13046423, 4036380)); // bottom-right coordinate
coordinatesPolygonA.Add(new Coordinate2D(-13046461, 4036380)); // bottom-left coordinate

Polygon polygonA = PolygonBuilderEx.CreatePolygon(coordinatesPolygonA, SpatialReferences.WebMercator);

// create polygon B by creating a list of the corner coordinates
List<Coordinate2D> coordinatesPolygonB = new List<Coordinate2D>();
coordinatesPolygonB.Add(new Coordinate2D(-13046436, 4036421)); // top-left coordinate
coordinatesPolygonB.Add(new Coordinate2D(-13046410, 4036421)); // top-right coordinate
coordinatesPolygonB.Add(new Coordinate2D(-13046410, 4036395)); // bottom-right coordinate
coordinatesPolygonB.Add(new Coordinate2D(-13046436, 4036395)); // bottom-left coordinate

Polygon polygonB = PolygonBuilderEx.CreatePolygon(coordinatesPolygonB, SpatialReferences.WebMercator);

// create polygon C by creating a list of the corner coordinates
List<Coordinate2D> coordinatesPolygonC = new List<Coordinate2D>();
coordinatesPolygonC.Add(new Coordinate2D(-13046432, 4036372)); // top-left coordinate
coordinatesPolygonC.Add(new Coordinate2D(-13046420, 4036372)); // top-right coordinate
coordinatesPolygonC.Add(new Coordinate2D(-13046420, 4036360)); // bottom-right coordinate
coordinatesPolygonC.Add(new Coordinate2D(-13046432, 4036360)); // bottom-left coordinate

Polygon polygonC = PolygonBuilderEx.CreatePolygon(coordinatesPolygonC, SpatialReferences.WebMercator);

Test the spatial relationship

In the previous image, consider the relationship of interiors, boundaries, and exteriors for the combination of polygon A to polygon B and for polygon A to polygon C. The result should be similar to the following matrix. The union of interiors must be true and the union of the exterior and the interior must evaluate to true.

// test the spatial relationship by considering the following DE-9IM matrix
//       | I(B) | B(B) | E(B)
// ------|------|------|------
//  I(A) |  T   |  *   |  T
// ------|------|------|------
//  B(A) |  *   |  *   |  *
// ------|------|------|------
//  E(A) |  T   |  *   |  *

// returns true, as polygon A and B do overlap
bool doTheyOverlap = GeometryEngine.Instance.Relate(polygonA, polygonB, "T*T***T**");

// returns false, as polygon A and C do not overlap
doTheyOverlap = GeometryEngine.Instance.Relate(polygonA, polygonC, "T*T***T**");

Developing with ArcGIS Pro

    Migration


Framework

    Add-ins

    Configurations

    Customization

    Styling


Arcade


Content


CoreHost


DataReviewer


Editing


Geodatabase

    3D Analyst Data

    Plugin Datasources

    Topology

    Object Model Diagram


Geometry

    Relational Operations


Geoprocessing


Knowledge Graph


Layouts

    Reports


Map Authoring

    3D Analyst

    CIM

    Graphics

    Scene

    Stream

    Voxel


Map Exploration

    Map Tools


Networks

    Network Diagrams


Parcel Fabric


Raster


Sharing


Tasks


Workflow Manager Classic


Workflow Manager


Reference

Clone this wiki locally