Select to view content in your preferred language

Buffer on one side of feature only possible?

11789
4
04-13-2017 03:10 PM
Ravichandran_M_Kaushika
Regular Contributor

dear Readers,

i had followed the examples to call geometry services buffer function and to add the resulting graphic to the map. 

https://developers.arcgis.com/javascript/3/jssamples/util_buffergraphic.html and https://developers.arcgis.com/javascript/3/jsapi/bufferparameters-amd.html. it worked fine/

Our ArcMap users are used to having an ArcObjects function that specifically lets the users choose as to which side of the feature the buffer area needs to be drawn.  for example, for a line feature, the user will have the option to choose whether the buffer should be on:

1. left side of the line,

2. right side of the line, or

3. both sides of the line (default).

Similarly, a polygon buffer would let the users choose between 1. include polygon area while computing the buffer or 2. exclude.

Are there  sample code or any suggestions in this regard?  Any help would be appreciated/

regards

ravi.

0 Kudos
4 Replies
FreddieGibson
Honored Contributor

I would assume that you were using the out-of-the-box Buffer (Analysis) tool within ArcObjects to create the one-side buffer.

Buffer (Analysis)
http://desktop.arcgis.com/en/arcmap/latest/tools/analysis-toolbox/buffer.htm

In the above documentation for the tool you'll see that it line side parameter allows you to specify the side of the feature that will be buffered. Within the JS API there is no functionality available to the client that would allow this out-of-the-box. The suggested workflow to implement this would be to do one of the following:

1. Publish the Buffer (Analysis) tool as a Geoprocessing Service. You could then supply your features to this service along with the buffer side and the out-of-the-box GP tool would handle returning you the results you're seeking.
2. Implement logic in the JS API to cut the buffer returned by the client (i.e. when using GeometryEngine to buffer) or a service, such as using GeometryService to buffer. 

In regards to the second suggestion, we do not have an example of this and I cannot write one for you, but I can provide you with enough logic to implement this on your end. For example, let's say that you were buffering a straight line as shown below.

geometryEngine buffer Method
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#buffer

To get top half of this buffer I would start by first creating a line that bisects the buffer polygon. This could done in several ways depending on the API. In a simple case like shown above I could either move the x coordinate of the vertices or I could leverage the envelope of the geometry and extend the lines to them as shown below.

Polygon getExtent Method
https://developers.arcgis.com/javascript/3/jsapi/polygon-amd.html#getextent

geometryEngine nearestCoordinate Method
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.geometryengine-amd.html#nearestcoordi...

Polyline insertPoint Method
https://developers.arcgis.com/javascript/3/jsapi/polyline-amd.html#insertpoint

Now that I have a line that bisects the polygon I could use the cut method of the geometryEngine to cut the polygon into left and right halves. I would then need to decide on which halve to persist and whether I want to replace the existing geometry or insert the data as a new record into my GraphicsLayer or FeatureLayer.

Now as I stated before, I cannot implement the code for the second suggestion above. It would be your responsibility to handle the logic for this task. You'll also want to note that the workflow I describe was intended for situations where the line is straight in a cardinal direction. This will not be the case with most real world data and you will find situations where the lines are curved or at angles. You'll need to ensure that you logic takes these situations into account when creating the line to cut the polygon. I'll leave you with the last set of examples. After reviewing my suggested workflow thing about how you'd handle the following programmatically to determine the top and bottom halves of the polygon.

Ravichandran_M_Kaushika
Regular Contributor

Thank you Freddie for taking the time to write up the answer for everyone's benefit.

have a nice weekend.

regards

ravi Kaushika.

0 Kudos
DorianneDysart
Occasional Contributor

ArcGIS Pro Buffer Tool

DorianneDysart_0-1693518643800.png

have to have a special license to only buffer one side 😔

0 Kudos
MohammedHilal_K
Occasional Contributor

Hi, Have you found any way to do this.? 

0 Kudos