openjump-gis / openjump

OpenJUMP, the Open Source GIS with more than one trick in its kangaroo pocket, takes the leap from svn to git. join the effort!
http://openjump.org
GNU General Public License v2.0
28 stars 14 forks source link

Geometry type converter turns some valid polygons into invalid ones #52

Closed mukoki closed 2 years ago

mukoki commented 2 years ago

The tool converting geometries from a geometry type to another sometimes turn a valid geometry into invalid. In JTS, exterior ring and interior rings can have any orientation. So that a polygon with CW exterior ring and CW interior rings is valid. If we convert such a polygon with the polygon to multi-polygon converter, it produces an invalid multipolygon.

Here are two example to try POLYGON (( 600643.0195598739 7030104.134067804, 600643.0195598739 7031464.3477121005, 602668.8696684012 7031464.3477121005, 602668.8696684012 7030104.134067804, 600643.0195598739 7030104.134067804 ), ( 600980.6612446284 7031001.296258723, 601202.5400660385 7030967.532090248, 601202.5400660385 7031199.057816937, 600990.308149907 7031199.057816937, 600980.6612446284 7031001.296258723 ), ( 601868.176530269 7030552.7151632635, 601872.9999829083 7030253.661099624, 602340.8748889253 7030282.60181546, 602326.4045310073 7030562.362068542, 601868.176530269 7030552.7151632635 ), ( 601791.0012880394 7030948.23827969, 601795.8247406787 7031271.409606527, 602258.8761940564 7031237.645438051, 602254.052741417 7030933.767921772, 601791.0012880394 7030948.23827969 ))

POLYGON (( 604313.6670184198 7031488.464975297, 604328.1373763379 7030244.014194345, 603064.392784828 7030244.014194345, 603146.391479697 7031449.877354182, 604313.6670184198 7031488.464975297 ), ( 603344.1530379103 7031039.883879838, 603382.7406590251 7031256.939248608, 603643.2071015501 7031266.586153887, 603614.2663857139 7030986.825900805, 603344.1530379103 7031039.883879838 ), ( 604168.9634392393 7030388.717773526, 604135.1992707638 7030678.124931887, 603826.4983018454 7030682.948384526, 603855.4390176815 7030383.894320887, 604168.9634392393 7030388.717773526 ))

edeso commented 2 years ago

if we are talking GeometryConverter, then polygon to (multi)polygon conversion implementation is somehat hackish. see https://github.com/openjump-gis/openjump/blob/21033dd0241d9290634ecaba670c7ee0166bdc9b/src/de/soldin/jumpcore/geomconv/GCPlugin.java#L691

do you know of any JTS-API to reliably reuse/expose?