|     Blog    |     Wiki    |     Support

WPF LineShape Buffer is 0

When I pass buffer as 0 vertices are not generated and it throws an error while calling GetBoundingBox

The shape you provided does not pass our simple validation. This ring is not closed. To close a ring the last point must be the same as the first point. All rings must have at least four points.

Is there a way to create a bounding box when we pass buffer as 0?

Not a ThinkGeo employee, but are you creating a lineshape or polygon shape? Definitely shouldn’t be giving that error if it is a line shape.

If its polygon this is working as expected. when I pass the LineShape (with 2 vertices) it throws error only when the buffer is 0.If I change the buffer to 0.1 it works fine


I think this code is your scenario:

        LineShape line = new LineShape();
        line.Vertices.Add(new Vertex(0, 0));
        line.Vertices.Add(new Vertex(10, 10));

        MultipolygonShape mps = line.Buffer(0, GeographyUnit.Meter, DistanceUnit.Meter);

        RectangleShape rect = mps.GetBoundingBox();

It throw exception is because the buffer zero is invalid operation and the “mps” is invalid shape here.

You can add breakpoint here and see the “mps” contains nothing.

So if you want to get the BoundingBox, you should want to directly call line.GetBoundingBox().

Wish that’s helpful.



It works for me. thank you


Thanks for your update, I am glad to hear that works.



Code is working but functionality is not achieved.

I have a point and draw a line next to that point and distance between the point and the line is approx 5000 m.
when I draw a line I set the buffer as 1m. after a line is drawn I have to select the features near to the line with 1m buffer.
When I use GetBoundingBox and GetFeaturesInsideBoundingBox it covers the point as well which is not logically right.
I am not sure how the bounding box is drawn. Is there a way to restrict the area of that box?
Use case:
if a line with 2 points and distance is 0, I have to find the features within that 2 points.

if a line with 2 points and distance is > 0, I have to find the features within that 2 points + distance.

I have used this method GetFeaturesWithinDistanceOf whereas it’s not returning anything.
GetFeaturesWithinDistanceOf(trackShape, WpfMap.MapUnit, DistanceUnit.Meter, searchRadiusParam,


The BoundingBox means the smallest rectangle which contains all vertexes of target feature.

If your point is also in this area, it will be included also.

And for your user case, could you please describe it more detail? It looks I cannot understand it, for example:

if a line with 2 points and distance is 0, I have to find the features within that 2 points.

Do you means you have a line which contains 2 vertexes, and there is another feature which intersect this line(distance = 0), you need to find the intersection point. Does that the requirement?



Thanks for your reply. Sorry for the confusion.

let assume Point A has a feature. I am drawing a line near to it which has 2 vertices(start and end point). Then I set the buffer for the line as 0 which means I have to find the features near to that line with buffer 0.

if I set the buffer to 1m then I have to find the features from the line with buffer 1m.

if the buffer is 0 I have to find the features only on the line.Hope it’s clear.

IS there a way to restrict the size of the bounding box?


In fact I still don’t totally understand your scenario, but I think we can discuss it now.

In fact buffer equal zero is invalid, because the buffere return a area shape, if the value is zero, the return shape won’t be a areashape, it still be a line, so it’s invalid shape in our map.

That’s why it don’t works.

If you assume the point is included in the area which buffer zero, that means, you think the point is in the line shape. So I think you don’t need to adjust it like this, you can directly calculate the distance between point to line like this:

        PointShape pointA = new PointShape(5, 5);
        LineShape lineB = new LineShape(new Collection<Vertex>() { new Vertex(1, 1), new Vertex(10, 10) });

        double distance = pointA.GetDistanceTo(lineB, GeographyUnit.Meter, DistanceUnit.Meter);

Then you can adjust the position relationship by the distance value.

Wish that’s helpful.



Thanks, Ethan For your previous comments. I think still I didn’t get the solution for my requirement.
I will detail it here.
there are 2 cases:

  1. I am drawing a line. buffer is 0. In this case, I have to find the features along the line only.
  2. I am drawing a line. buffer is > 0. In this case, I have to pass this buffer in buffer method to get bounding box. After I get bounding box I used this GetFeaturesInsideBoundingBox to find the features along the line and within that bounding box as well.
    2 case is working as expected whereas the 1st case is not working.
    1st case in detail:
    GetFeaturesWithin(shape) - shape is a line and features present along the line but it returns no features.
    GetFeaturesInsideBoundingBox (shape.getboundingbox) - shape is a line and features present along the line but it returns no features.

Hope I make my requirement clear.

Hi Guy:

Your requirements are not clear, and we only guess it.
Case1: When the buffer of line is zero, you want to find the point features within the line.
Case2: When the buffer of line is larger zero, you want to find the point features within the buffer area of line.
As is shown in the graph:

Using the GetFeaturesWithinDistanceOf method only gets the features that are less than distance and don’t contain equals. So you can’t use it to get the zero distance features.
I tested the GetFeaturesInsideBoundingBox for case 1, and it works fine.
My test code is as below:

        LineShape lineShape = new LineShape();
        lineShape.Vertices.Add(new Vertex(0, 0));
        lineShape.Vertices.Add(new Vertex(10, 0));

        InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
        PointShape pointShape1 = new PointShape(5, 0);
        inMemoryFeatureLayer.InternalFeatures.Add(new Feature(pointShape1));
        PointShape pointShape2 = new PointShape(5, 1);
        inMemoryFeatureLayer.InternalFeatures.Add(new Feature(pointShape2));
        var features = inMemoryFeatureLayer.FeatureSource.SpatialQuery(lineShape, QueryType.Intersects, ReturningColumnsType.NoColumns);
        var bufferLineShape = lineShape.Buffer(1, GeographyUnit.Meter, DistanceUnit.Meter);
        features = inMemoryFeatureLayer.FeatureSource.SpatialQuery(bufferLineShape, QueryType.Intersects, ReturningColumnsType.NoColumns);

        //Test GetFeaturesInsideBoundingBox
        features = inMemoryFeatureLayer.FeatureSource.GetFeaturesInsideBoundingBox(lineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);