You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you for putting together this library, it's been a great help for the project I'm working on at the moment.
I think I've spotted an issue with area calculation of some 2D polygons with an interior ring. To caveat this, I'm entirely new to working with geospatial data, so let me know if you think otherwise. If you agree with the issue I'm happy to open a PR to fix this.
The problem
In my testing I found that the polygon I included in GeoJSON to the bottom of this issue, which has an exterior and an interior ring, has a larger area if you take into account the interior ring than if you consider the polygon without the cutout of the interior ring.
The issue is that the area of the interior ring is negative, so when subtracted from the area of the exterior ring the overall area is larger, which is incorrect.
I found on Wikipedia that the area of a polygon will be considered negative if it's negatively oriented. If that's the case, you can take the absolute value to get the area of the polygon.
If the polygon is negatively oriented, then the result A of the formulas is negative. In any case |A| is the sought area of the polygon.
Potential solution
Wrapping math.Abs around doubleArea on line 263 should fix the issue.
The issue is a bit more subtle here. As you have identified, the orientation of the polygon determines whether its area is positive or negative. go-geom follows the convention that a polygon's outer ring has positive area and its inner rings have negative area, so the area can be calculated by a simple sum of all the ring areas: inner rings are subtracted without the need for a call to math.Abs.
In your case, the GeoJSON has incorrect polygon orientation for the inner rings. The GeoJSON spec states that holes are clockwise. So, the correct fix is either to fix the program that generated the GeoJSON or add a sanitization step when importing the data.
Ah that makes a lot of sense, thanks! That link to the GeoJSON spec is really useful.
The GeoJSON was generated by go-geom, but it's quite possible that the polygon I'm marshalling and calculating the area for is malformed. I'll have a look at that.
Hi there!
First of all, thank you for putting together this library, it's been a great help for the project I'm working on at the moment.
I think I've spotted an issue with area calculation of some 2D polygons with an interior ring. To caveat this, I'm entirely new to working with geospatial data, so let me know if you think otherwise. If you agree with the issue I'm happy to open a PR to fix this.
The problem
In my testing I found that the polygon I included in GeoJSON to the bottom of this issue, which has an exterior and an interior ring, has a larger area if you take into account the interior ring than if you consider the polygon without the cutout of the interior ring.
The issue is that the area of the interior ring is negative, so when subtracted from the area of the exterior ring the overall area is larger, which is incorrect.
I found on Wikipedia that the area of a polygon will be considered negative if it's negatively oriented. If that's the case, you can take the absolute value to get the area of the polygon.
Potential solution
Wrapping
math.Abs
arounddoubleArea
on line 263 should fix the issue.go-geom/flat.go
Lines 258 to 264 in 3538962
Example polygon that's affected by this issue
The text was updated successfully, but these errors were encountered: