I am trying to use the Buffer method on a PolygonShape to create a buffer outside or inside the polygon. polygonShape.Buffer seems to correctly return the buffer outside the polygon when I use a positive distance giving me a larger “MultipolygonShape”. However when I make the distance negative, polygonShape.Buffer returns the same polygonShape vertices in the “MultipolygonShape”. My units are Geography.DecimalDegrees and DistanceUnit.Kilometer.
I found the Negative Buffering sample application so I cut and pasted the code from the sample. It gets the perimeter of the polygonShape as a Lineshape and then uses the lineShape.Buffer to get a MultipolygonShape. Then it does a GetDifference using the orignal polygonShape and the multipolygonShape returned from the lineShape.Buffer. Using this code doesn’t seem to work either as the lineShape.Buffer always returns “null” for the multipolygonShape when I use a distance that is negative. Note it does retrun a valid multipolygonShape when the distance is positive and the sample code as it donwloads is coded with a positive 50 in DistanceUnit.Meters.
I found the following note "
You can also pass a negative distance, Buffer will then decrease the perimeter of the BaseShape in all directions. A negative Distance will work with only BaseAreaShape and its derived classes (Polygon, StraightRectangle, Ellipse)
on a page for “BaseShape” on the Desktop Edition.
Does anyone have any idea what I am doing wrong? Can anyone give me an example that actually uses a negative distance and works? If the note above is correct, then how would the sample work by converting the polygonShape perimeter to a LineShape to do the Buffer when negative distance only works for polygon, StraightRectangle, and Ellipse?
Thanks for your post, I think we don’t support negative buffer render, we do support user input a negative value, but inside the core, we will translate any negative value or value less than 0.02 to 0.02 then caculate the buffer shape.
Could you please attach your negative buffer sample here and I can do some test?
The sample code that I would provide is just the code from the MapSuite samples for Negative Buffering. Here it is with a minor changes to test if the Buffer call returns null which was my original error. Since the code was not testing for null it would crash the app on the exception when the MultipolygonShape was null and it tried to do the GetDifference on an object that didn’t exist.
I believe I have figured it out. This routine always expects the distance as a positve number and only calculates a “Negative Buffer”. It will not work to create a buffer outside/larger than the original polygon. I have to use different code to create the larger/outside polygon buffer ( in particular when I need a “Positive” buffer (if that is the correct term), I just use the “polygonShape.Buffer” without doing the GetPerimeter or the GetDifference calls.
My issue with the sample was that the Buffer and GetDifference will return null for the MultipolygonShape when the distance value will result in “no polygon”. So when the distance specified is large enough that there is no area left inside of the original polygon, the returned Mulitpolygonshape is null. By testing the return values and handling them appropriately (in my code I assume that a null Multipolygonshape means the entire original polygon is included), I have my code working in a reasonable way and producing the “Negative Buffering” shape as well as a “Positive Buffering” shape.
I hope this might help anyone else who is working with this sample.