chuyentt / geojson_vi

An Open-Source Dart and Flutter Library for Efficiently Handling GeoJSON Data in Compliance with RFC 7946
https://pub.dev/packages/geojson_vi
MIT License
15 stars 10 forks source link

For certain polygons the centroid coordinates have a wrong algebraic sign #22

Closed tobesucht closed 10 months ago

tobesucht commented 10 months ago

Hi and thanks a lot for this great library - it is really helpful!

I have found and issue with the caclulation of centroids for some polygons.

In some cases the centroid is calculated wrongly: It returns the correct position but with a wrong algebraic sign.

For example:

"geometry":{"type":"Polygon","coordinates":[[[11.504408,48.5300738],[11.5043411,48.5298856],[11.5045044,48.5298578],[11.5045017,48.5298478],[11.5045637,48.5298367],[11.5045684,48.5298463],[11.5046393,48.5298347],[11.5046361,48.5298246],[11.5047081,48.5298117],[11.5047115,48.5298221],[11.504932,48.529786],[11.5049734,48.5297792],[11.5049843,48.5298138],[11.5049874,48.5298132],[11.5049908,48.5298222],[11.5050429,48.529814],[11.5050458,48.5298037],[11.5050587,48.5298057],[11.5050564,48.5298166],[11.5050881,48.5298351],[11.5050994,48.5298276],[11.5051079,48.5298343],[11.5050971,48.529842],[11.5051094,48.5298702],[11.5051246,48.5298705],[11.5051236,48.5298803],[11.5051092,48.5298804],[11.5050929,48.529905],[11.5051034,48.5299119],[11.505095,48.5299183],[11.505084,48.5299115],[11.5050372,48.5299177],[11.5050653,48.5299939],[11.5049485,48.5300126],[11.5049373,48.5299829],[11.5047937,48.5300075],[11.5047977,48.5300183],[11.5047108,48.5300322],[11.5047074,48.5300221],[11.5046331,48.5300348],[11.5046361,48.5300432],[11.50458,48.5300531],[11.5045767,48.5300445],[11.5044831,48.5300607],[11.504408,48.5300738]]]}

returns:

[0]: -11.504723502784723
[1]: -48.52992432037955

It would be great if this issue could be fixed.

chuyentt commented 10 months ago

Hi and thanks a lot for this great library - it is really helpful!

I have found and issue with the caclulation of centroids for some polygons.

In some cases the centroid is calculated wrongly: It returns the correct position but with a wrong algebraic sign.

For example:

"geometry":{"type":"Polygon","coordinates":[[[11.504408,48.5300738],[11.5043411,48.5298856],[11.5045044,48.5298578],[11.5045017,48.5298478],[11.5045637,48.5298367],[11.5045684,48.5298463],[11.5046393,48.5298347],[11.5046361,48.5298246],[11.5047081,48.5298117],[11.5047115,48.5298221],[11.504932,48.529786],[11.5049734,48.5297792],[11.5049843,48.5298138],[11.5049874,48.5298132],[11.5049908,48.5298222],[11.5050429,48.529814],[11.5050458,48.5298037],[11.5050587,48.5298057],[11.5050564,48.5298166],[11.5050881,48.5298351],[11.5050994,48.5298276],[11.5051079,48.5298343],[11.5050971,48.529842],[11.5051094,48.5298702],[11.5051246,48.5298705],[11.5051236,48.5298803],[11.5051092,48.5298804],[11.5050929,48.529905],[11.5051034,48.5299119],[11.505095,48.5299183],[11.505084,48.5299115],[11.5050372,48.5299177],[11.5050653,48.5299939],[11.5049485,48.5300126],[11.5049373,48.5299829],[11.5047937,48.5300075],[11.5047977,48.5300183],[11.5047108,48.5300322],[11.5047074,48.5300221],[11.5046331,48.5300348],[11.5046361,48.5300432],[11.50458,48.5300531],[11.5045767,48.5300445],[11.5044831,48.5300607],[11.504408,48.5300738]]]}

returns:

[0]: -11.504723502784723
[1]: -48.52992432037955

It would be great if this issue could be fixed.

Thank you for reporting this issue. I have addressed the algebraic sign problem in the centroid calculation for specific polygons. The fix has been implemented and published in the latest release v2.2.1. Please update to the latest version, and let me know if the issue persists. Your feedback is greatly appreciated!

tobesucht commented 10 months ago

Hey, thanks you sooo much for your quick reaction! I can confirm that the centroid is now calculated corretly! Five stars! :-)

grafik