In the recent project, the client required to obtain the area comparison of the cross-province of the patch according to the patch of the selected map. After specific analysis, the intersection of topology in GIS was used to determine the area of the intersection part

First of all, how do we find the intersection of two geometric elements in Arcgis For Js Api

Method one: ‘Client’s geometryEngine’

Reference module: “esri/geometry/geometryEngine”

Use the INTERSECT method of this module.

So let’s see

Method name: ‘intersect’

Parameters:

  • Geometry (The data type is a single geometry or array of geometry, and the parameter is the geometry element for intersection)
  • Intersector (Data type is single Geometry, and this element is the target element)

The return value

Geometry | Geometry [] (return to the intersection of geometric elements/Geometry elements in an array)

According to THE API, we know that only one geometry and one geometry or geometry array can be used to solve the intersection, so we can solve the intersection by using the geometry of the patch and the geometry of the whole province

Details are as follows:

 // Get the intersecting values

            var interPloy = geometryEngine.intersect(geomboj.geom1, geomboj.geom2)



            for (let i = 0; i < interPloy.length; i++) {

                // Because it does the intersection calculation based on all subsets of parameter 2, some return data, none return null

                // Make a judgment call

                if(! (interPloy[i] ===null)) {

                    // I is the index of the intersecting items

                    // To get the attributes or styles, you need to turn it into a graphic

                    // Change it to graphic

                    let graphic =new Graphic(interPloy[i])

                    // Create a new GraphicsLayer to store the graphic

                    let GraphicsLayer = new GraphicsLayer()

                    // Put graphic in raphicsLayer

                    GraphicsLayer.add(graphic)

                    // Put the graphic on the map

                    map.addLayer(GraphicsLayer)



                    // Then, do whatever you want, add styles, bind attributes, whatever

                }

Copy the code

Method two: ‘the server’s GeometryService GeometryService’

The intersect function is used in GeometryService

Reference module for: “esri/tasks/GeometryService”

So let’s see

Method name: ‘intersect’

Parameters:

  • Geometries (Data type is Geometry[], which is the Geometry element for intersection)
  • Geometry (Data type is Geometry, and this element is the target element)
  • Callback (successful callback function)
  • Error (failed callback function)

Intersect is similar to the first client. Let’s see

          //Create a new geometry service class and pass in the address of the geometry service

            let geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

            geometryService.intersect(geomboj.geom1, geomboj.geom2,(res)= >{

                //Res is the intersecting element



            })

Copy the code