Saturday, September 21, 2013

ArcGis JavaScript API - Extending an existing editing tool

 

Extending an existing editing tool


1      Introduction


I got a question how an existing editing tool could be used for another type of geometric operation. In a previous document I showed how the use of the ‘cut’ method of the ArcGIS geometry service can be used to split a geometry into different parts. The tool consists of selecting a geometry and  using a polyline drawn. A split operation can be initiated through a REST call to the ArcGIS geometry service with the two geometries or collection of geometries.

In this document I will explain how you can use the ‘cut’ method of the ArcGIS geometry service to do a similar operation but using a polygon instead of a polyline. You could consider this tool as a kind of punch tool for a geometry. Below is the illustration of the different steps involved in the special split command. I start with a geometry shown below:


 
After a polygon has been drawn inside the geometry to be split, the result is shown below:


 
The two polygons looks like this:


2      Using the ‘cut’ method


Given the polygon as input, I want to use to border line of the polygon for cutting a geometry out of the selected polygon. In the tool described hereafter I assumed that the polygon has a simple structure consisting of one solid block.

In the ArcGIS JavaScript API you can see that a polygon consists of an array of rings. A ring consists of an array of points. If we are looking at a polyline, you can see that a polyline consists of an array of paths. A path consists of an array of points. So the common data structure of polyline and polygon is that both consists of arrays of points. What we basically must do is converting the polygon drawn into a polyline. This can simply done by creating an empty polyline and adding a path consisting of the array of points of the first ring of the polygon.

     var polyline = new esri.geometry.Polyline(polygon.spatialReference);

     polyline.addPath(polygon.rings[0]);

 

And as in the split command, do a REST call to the cut command of the ArcGIS geometry service by using the previous defined split function based on a polyline and a set of polygons.

     this.splitOperation(featureLayer, selectGraphics, polyline, 
       geometryServiceComplete, geometryServiceFailed);

3      Conclusion


In ArcGIS desktop you can use built-in tools and commands to write extensions on ArcGIS desktop  to create more powerful tools and commands. This makes it for the user easier to do editing on geometries by using this custom tools and commands.

For web editing you can do exactly the same thing. For web, the built-in tools are the different geometry tools available in the ArcGIS geometry service. You can also create new tools on the server

2 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..
    I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai .
    or Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

    ReplyDelete
  2. I appreciate the explanation in your document about using the 'cut' method of the ArcGIS geometry service for a unique geometric operation.
    Also Read: Java Spring Boot Simplifying Enterprise Application Development

    ReplyDelete