Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#33 GeometryPrecisionReducer creates empty polygon

pending-later
Dr JTS
core (12)
5
2013-02-01
2013-02-01
btekab
No

Changed a multi polygon using the following code in geotools based on JTS 1.12 and got an empty polygon which was not expected:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader = new WKTReader(geometryFactory);

Geometry originalPolygon = null;
try {
originalPolygon = reader
.read("MULTIPOLYGON (((563539.9999829987 6395531.999987871, 558495.0908829987 6395531.999987871, 558495.0914829987 6395533.599987871, 558495.1972829987 6395837.757887871, 558496.0278829987 6395838.339487871, 558497.2604829987 6395839.572087871, 558498.2602829987 6395841.000087871, 558498.9968829987 6395842.579887872, 558499.4480829986 6395844.263487872, 558499.5996829987 6395845.920087871, 558499.9998829986 6395895.974887871, 558499.5998829987 6396031.229687871, 558499.4480829986 6396032.936487871, 558498.9968829987 6396034.620287871, 558498.2602829987 6396036.200087871, 558497.2604829987 6396037.627887871, 558496.0278829987 6396038.860487871, 558495.1938829987 6396039.444487872, 558494.8000829987 6396563.233287871, 558494.3998829987 6396631.258887871, 558494.2480829987 6396632.936487871, 558493.7968829987 6396634.620287871, 558493.0602829987 6396636.200087871, 558492.0604829987 6396637.627887871, 558490.8278829987 6396638.860487871, 558490.3932829987 6396639.164887872, 558490.0000829987 6397089.618487871, 558489.5998829987 6397231.228287871, 558489.4480829986 6397232.936487871, 558488.9968829987 6397234.620287871, 558488.2602829987 6397236.200087871, 558487.2604829987 6397237.627887871, 558486.0278829987 6397238.860487871, 558485.1890829987 6397239.447887871, 558484.4000829987 6397831.213287871, 558484.2480829987 6397832.936487871, 558483.7968829987 6397834.620287871, 558483.0602829987 6397836.200087871, 558482.0604829987 6397837.627887871, 558480.8278829987 6397838.860487871, 558479.9948829986 6397839.443887872, 558479.6000829986 6398431.206687871, 558479.4480829986 6398432.936487871, 558478.9968829987 6398434.620287871, 558478.2602829987 6398436.200087871, 558477.2604829987 6398437.627887871, 558476.0278829987 6398438.860487871, 558475.1890829987 6398439.447887871, 558474.4000829987 6399031.213287871, 558474.2480829987 6399032.936487871, 558473.7968829987 6399034.620287871, 558473.0602829987 6399036.200087871, 558472.0604829987 6399037.627887871, 558470.8278829987 6399038.860487871, 558470.3894829986 6399039.167487871, 558469.6000829986 6399631.213287871, 558469.4480829986 6399632.936487871, 558468.9968829987 6399634.620287871, 558468.2602829987 6399636.200087871, 558467.2604829987 6399637.627887871, 558466.0278829987 6399638.860487871, 558465.1890829987 6399639.447887871, 558464.4000829987 6400231.213287871, 558464.2480829987 6400232.936487871, 558463.7968829987 6400234.620287871, 558463.0602829987 6400236.200087871, 558462.0604829987 6400237.627887871, 558460.8278829987 6400238.860487871, 558459.9948829986 6400239.443887872, 558459.6000829986 6400831.206687871, 558459.4480829986 6400832.936487871, 558458.9968829987 6400834.620287871, 558458.2602829987 6400836.200087871, 558457.2604829987 6400837.627887871, 558456.0278829987 6400838.860487871, 558455.1940829987 6400839.444487872, 558454.7998829987 6401378.041287871, 558454.3996829987 6401431.275087872, 558454.2480829987 6401432.936487871, 558453.7968829987 6401434.620287871, 558453.0602829987 6401436.200087871, 558452.0604829987 6401437.627887871, 558450.8278829987 6401438.860487871, 558450.3936829987 6401439.164687871, 558450.0000829987 6401919.622087872, 558449.5998829987 6402031.235887871, 558449.4480829986 6402032.936487871, 558448.9968829987 6402034.620287871, 558448.2602829987 6402036.200087871, 558447.2604829987 6402037.627887871, 558446.0278829987 6402038.860487871, 558445.1890829987 6402039.447887871, 558444.4000829987 6402631.213287871, 558444.2480829987 6402632.936487871, 558443.7968829987 6402634.620287871, 558443.0602829987 6402636.200087871, 558442.0604829987 6402637.627887871, 558440.8278829987 6402638.860487871, 558439.9948829986 6402639.443887872, 558439.6000829986 6403231.206687871, 558439.4480829986 6403232.936487871, 558438.9968829987 6403234.620287871, 558438.2602829987 6403236.200087871, 558437.2604829987 6403237.627887871, 558436.0278829987 6403238.860487871, 558435.1890829987 6403239.447887871, 558434.4000829987 6403831.213287871, 558434.2480829987 6403832.936487871, 558433.7968829987 6403834.620287871, 558433.0602829987 6403836.200087871, 558432.0604829987 6403837.627887871, 558430.8278829987 6403838.860487871, 558430.3894829986 6403839.167487871, 558429.6000829986 6404431.213287871, 558429.4480829986 6404432.936487871, 558428.9968829987 6404434.620287871, 558428.2602829987 6404436.200087871, 558427.2604829987 6404437.627887871, 558426.0278829987 6404438.860487871, 558425.1890829987 6404439.447887871, 558424.4000829987 6405031.213287871, 558424.2480829987 6405032.936487871, 558423.7968829987 6405034.620287871, 558423.0602829987 6405036.200087871, 558422.0604829987 6405037.627887871, 558420.8278829987 6405038.860487871, 558419.9948829986 6405039.443887872, 558419.6000829986 6405631.206687871, 558419.4480829986 6405632.936487871, 558418.9968829987 6405634.620287871, 558418.2602829987 6405636.200087871, 558417.2604829987 6405637.627887871, 558416.0278829987 6405638.860487871, 558415.1940829987 6405639.444487872, 558414.7998829987 6406180.843287871, 558414.3996829987 6406231.279487872, 558414.2480829987 6406232.936487871, 558413.7968829987 6406234.620287871, 558413.0602829987 6406236.200087871, 558412.0604829987 6406237.627887871, 558410.8278829987 6406238.860487871, 558410.3936829987 6406239.164687871, 558410.0000829987 6406725.222887871, 558409.5998829987 6406831.237687871, 558409.4480829986 6406832.936487871, 558408.9968829987 6406834.620287871, 558408.2602829987 6406836.200087871, 558407.2604829987 6406837.627887871, 558406.0278829987 6406838.860487871, 558405.1890829987 6406839.447887871, 558404.4000829987 6407431.213287871, 558404.2480829987 6407432.936487871, 558403.7968829987 6407434.620287871, 558403.0602829987 6407436.200087871, 558402.0604829987 6407437.627887871, 558400.8278829987 6407438.860487871, 558400.3894829986 6407439.167487871, 558399.6000829986 6408031.213287871, 558399.4480829986 6408032.936487871, 558398.9968829987 6408034.620287871, 558398.2602829987 6408036.200087871, 558397.2604829987 6408037.627887871, 558396.0278829987 6408038.860487871, 558394.7946829987 6408039.724087872, 558394.4000829987 6408631.206687871, 558394.2480829987 6408632.936487871, 558393.7968829987 6408634.620287871, 558393.0602829987 6408636.200087871, 558392.0799829987 6408637.599987871, 558392.0604829987 6408637.627887871, 558390.8278829987 6408638.860487871, 558390.3894829986 6408639.167487871, 558390.3894829986 6408639.199987872, 563539.9999829987 6408639.199987872, 563541.5999829987 6408639.199987872, 563541.5999829987 6408637.599987871, 563541.5999829987 6395533.599987871, 563541.5999829987 6395531.999987871, 563539.9999829987 6395531.999987871)))");
} catch (ParseException e) {
e.printStackTrace();
}

GeometryPrecisionReducer geometryPrecisionReducer = new GeometryPrecisionReducer(new PrecisionModel(PrecisionModel.FLOATING_SINGLE));

System.out.println("Original: " + originalPolygon);

Geometry finalPolygon = geometryPrecisionReducer.reduce(originalPolygon);

System.out.println("Final: " + finalPolygon);

Discussion

  • Dr JTS
    Dr JTS
    2013-02-01

    • status: open --> pending-later
     
  • Dr JTS
    Dr JTS
    2013-02-01

    This is caused by a known issue with GeometryPrecisionReducer. The reason is that it uses the buffer(0) trick to fix the topology of reduced geometries, and sometimes this fails and causes an empty geometry to be created.

    The fix will be to provide a true topology cleaner - but this is somewhat complex and isn't on the immediate horizon.