Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fix invalid geometries in django (without database)

I have polygon that I'm getting from external source. The polygon is not valid.

In [36]: p
Out[36]: <Polygon object at 0x7fec6bea6ac0>

In [37]: p.valid
[12/Dec/2017 19:13:19] WARNING [django.contrib.gis:85] GEOS_NOTICE: Hole lies outside shell at or near point 260561.40600000042 776052

I know that I can fix the polygon in the DB using the MakeValid() django function.

Is there a way to fix the polygon before it is inserted to the DB, just using geos API?

Thanks.

like image 955
eran Avatar asked Oct 26 '25 14:10

eran


1 Answers

I don't know that this will fix your hole error necessarily, but I have had luck eliminating self-intersecting geoms by performing a 0-width buffer:

p = p.buffer(0)
like image 54
spatialbits Avatar answered Oct 29 '25 06:10

spatialbits



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!