View on GitHub Sample viewer app

Find the union, difference, or intersection of two geometries.

Image of spatial operations

Use case

Determining the spatial relationships between points, lines or polygons is a fundamental concept in GIS. For example, a data analyst may need to find the intersection between areas with a high concentration of medical emergency situations and the service area of a hospital.

How to use the sample

The sample provides a drop down on the top, where you can select a geometry operation. When you choose a geometry operation, the application performs this operation between the overlapping polygons and applies the result to the geometries.

How it works

  1. Get the Geometry of the features you would like to perform a spatial operation on.
  2. Use the various static methods of GeometryEngine to determine the spatial relationships between the geometries. For example, use GeometryEngine.intersection(polygon1.getGeometry(), polygon2.getGeometry()) to find the intersection between two polygons.

Relevant API

  • Geometry
  • Graphic
  • GraphicsOverlay
  • MapView
  • Point
  • PointCollection
  • SimpleLineSymbol
  • SimpleFillSymbol

Tags

combine, difference, edit, intersect, intersection, modify, symmetric difference, union

Sample Code

module-info.java module-info.java SpatialOperationsSample.java
/*
* Copyright 2022 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module com.esri.samples.spatial_operations {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
exports com.esri.samples.spatial_operations;
}