java - JTS Geometry.intersects() method produces infinite loop -


i'm trying check whether multipolygon intersects polygon in list, using jts library. however, method stucks in infinite loop , end out of heap space error.

the method works fine pairs apparently don't intersect. infinite loop starts when first pair that's intersect appears.

here coordinate sequence of 2 problematic geometry objects, (geojson format):

edit 1 - adding code:

multipolygon:

[ [ [ [ 24.899993263111575, 60.168590212519007, 0.0 ], [ 24.8921845577913, 60.170930189360085, 0.0 ], [ 24.906727352467691, 60.177129472862902, 0.0 ], [ 24.912750145776748, 60.178210672366426, 0.0 ], [ 24.915824674917332, 60.1759297188066, 0.0 ], [ 24.916581969097017, 60.175298383750082, 0.0 ], [ 24.921993683436096, 60.17592332951083, 0.0 ], [ 24.924298430649159, 60.176277074203171, 0.0 ], [ 24.925777801589089, 60.176578177900481, 0.0 ], [ 24.927069958749666, 60.176812746915481, 0.0 ], [ 24.934606301659603, 60.17770118209701, 0.0 ], [ 24.93829154797028, 60.17943631088842, 0.0 ], [ 24.943101975190991, 60.179746422785151, 0.0 ], [ 24.946157646983945, 60.177893553297686, 0.0 ], [ 24.949063929828164, 60.176872818864446, 0.0 ], [ 24.948884500413151, 60.176763003129317, 0.0 ], [ 24.947435273641268, 60.175810147107796, 0.0 ], [ 24.947645652172458, 60.174545608314318, 0.0 ], [ 24.953922745030216, 60.17465838879788, 0.0 ], [ 24.952114223411215, 60.172614801031834, 0.0 ], [ 24.952535692362105, 60.169038476544031, 0.0 ], [ 24.954301749734213, 60.168843140472724, 0.0 ], [ 24.954352635736257, 60.167875977512914, 0.0 ], [ 24.954382959437606, 60.167722794336058, 0.0 ], [ 24.94618172965189, 60.167514740158367, 0.0 ], [ 24.94537429422477, 60.167437294026875, 0.0 ], [ 24.946805477127789, 60.166445009469363, 0.0 ], [ 24.946239227186837, 60.166289851133151, 0.0 ], [ 24.94605715808019, 60.166369202625063, 0.0 ], [ 24.944895457595461, 60.165955522827154, 0.0 ], [ 24.943796685615666, 60.166732851647168, 0.0 ], [ 24.943804264808218, 60.16695638982231, 0.0 ], [ 24.94339656134855, 60.167013101789991, 0.0 ], [ 24.943005307041311, 60.1672873863494, 0.0 ], [ 24.942815762910648, 60.167233708186423, 0.0 ], [ 24.942650545385295, 60.167130925185603, 0.0 ], [ 24.9407231754085, 60.166436365685314, 0.0 ], [ 24.940722537913366, 60.166342333123318, 0.0 ], [ 24.940730039071539, 60.166232085046666, 0.0 ], [ 24.94054008676806, 60.166146432407373, 0.0 ], [ 24.940689883918264, 60.166032286309964, 0.0 ], [ 24.938850589801866, 60.165384512580708, 0.0 ], [ 24.938374768557253, 60.165445980685028, 0.0 ], [ 24.938302460409481, 60.165202578885371, 0.0 ], [ 24.937168766625486, 60.1648185467416, 0.0 ], [ 24.936325303890971, 60.164523435250963, 0.0 ], [ 24.935515249176746, 60.165055276075314, 0.0 ], [ 24.935162131372266, 60.165067012171299, 0.0 ], [ 24.935243484405692, 60.165243301611966, 0.0 ], [ 24.934771879418953, 60.165604942333808, 0.0 ], [ 24.935697179525107, 60.165921540021522, 0.0 ], [ 24.935678441330882, 60.16607022900051, 0.0 ], [ 24.93562630412751, 60.166223958343842, 0.0 ], [ 24.93432941740414, 60.16639906762866, 0.0 ], [ 24.934086151809726, 60.16643747924013, 0.0 ], [ 24.933996000970303, 60.166879775928571, 0.0 ], [ 24.933494220741714, 60.166503500060202, 0.0 ], [ 24.930639585658206, 60.166879026400828, 0.0 ], [ 24.930477360716871, 60.167021165775722, 0.0 ], [ 24.93012338167825, 60.166940112911924, 0.0 ], [ 24.926990522351048, 60.167324416451343, 0.0 ], [ 24.926831203850465, 60.167593482122442, 0.0 ], [ 24.92584998697993, 60.167800919963199, 0.0 ], [ 24.925440947757817, 60.167842026167428, 0.0 ], [ 24.925464402293027, 60.167636210840456, 0.0 ], [ 24.925057233085131, 60.167426343568081, 0.0 ], [ 24.924638431368617, 60.167314445885701, 0.0 ], [ 24.924653932101634, 60.166777681068048, 0.0 ], [ 24.924239526771945, 60.166656330235163, 0.0 ], [ 24.923909713383374, 60.166769702593491, 0.0 ], [ 24.919742746576386, 60.166669946668634, 0.0 ], [ 24.919486254229472, 60.168947489628216, 0.0 ], [ 24.917865586081348, 60.169052961010145, 0.0 ], [ 24.913389466202162, 60.169206955531649, 0.0 ], [ 24.908339577064975, 60.169298848862468, 0.0 ], [ 24.899993263111575, 60.168590212519007, 0.0 ] ], [ [ 24.936135087425775, 60.173864750028308, 0.0 ], [ 24.935822882124054, 60.173818038029538, 0.0 ], [ 24.935698898369246, 60.173449814747812, 0.0 ], [ 24.935042425364173, 60.172863964505616, 0.0 ], [ 24.934700282784398, 60.172293513337216, 0.0 ], [ 24.934235985164971, 60.171993255866646, 0.0 ], [ 24.93458616422809, 60.171768472366658, 0.0 ], [ 24.935119957047309, 60.171965193243153, 0.0 ], [ 24.935650390363076, 60.171879257705569, 0.0 ], [ 24.936025502093653, 60.171926942487744, 0.0 ], [ 24.936234782914752, 60.171605759312015, 0.0 ], [ 24.937662268667879, 60.172287296440999, 0.0 ], [ 24.936135087425775, 60.173864750028308, 0.0 ] ] ] ] 

polygon:

[ [ [ 24.94068318546399, 60.17336319841633 ], [ 24.93618043398334, 60.17329314372988 ], [ 24.936039655930326, 60.17553644290522 ], [ 24.940542714024545, 60.17560650391693 ], [ 24.94068318546399, 60.17336319841633 ] ] ] 

here's piece of code used generate polygon:

    public polygon topolygonjts(geometryfactory factory,         linearring polygonringholder, arraylist<linearring> holeholder,         arraylist<coordinate> coordinateholder) {     if (!this.jtsdrawn) {         boolean ishole = false;         // list of points stored in array list         (arraylist<arraylist<double>> linearring : this.geometry                 .getcoordinates()) {             (arraylist<double> point : linearring) {                 // add point array                 coordinateholder.add(new coordinate(point.get(0), point                         .get(1)));             }             if (!ishole) {                 // create linearring polygon                 polygonringholder = new linearring(                         new coordinatearraysequence(                                 coordinateholder                                         .toarray(new coordinate[coordinateholder                                                 .size()])), factory);             } else {                 // add linearring list of polygons specifying holes                 holeholder.add(new linearring(new coordinatearraysequence(                         coordinateholder                                 .toarray(new coordinate[coordinateholder                                         .size()])), factory));             }             // clear coordinate holder next loop             coordinateholder.clear();         }         // create polygon , store in object property         this.polygon = new polygon(polygonringholder,                 holeholder.toarray(new linearring[holeholder.size()]),                 factory);     }     return this.polygon; } 

for multipolygon:

    public multipolygon tomultipolygonjts(geometryfactory factory,         arraylist<polygon> polygonlist, linearring polygonringholder,         arraylist<linearring> holeholder,         arraylist<coordinate> coordinateholder) {     if (!this.jtsdrawn) {         boolean ishole = false;         (arraylist<arraylist<arraylist<double>>> polygon : this.geometry.coordinates) {             (arraylist<arraylist<double>> linearring : polygon) {                 (arraylist<double> point : linearring) {                     coordinateholder.add(new coordinate(new coordinate(((double) (point.get(0) * 100000)).intvalue(), ((double) (point                         .get(1) * 100000)).intvalue())));                 }                 if (!ishole) {                     polygonringholder = new linearring(                             new coordinatearraysequence(                                     coordinateholder                                             .toarray(new coordinate[coordinateholder                                                     .size()])), factory);                 } else {                     holeholder                             .add(new linearring(                                     new coordinatearraysequence(                                             coordinateholder                                                     .toarray(new coordinate[coordinateholder                                                             .size()])),                                     factory));                 }                 coordinateholder.clear();             }             // create polygon , add list             polygonlist.add(new polygon(polygonringholder, holeholder                     .toarray(new linearring[holeholder.size()]), factory));         }         // create multipolygon list of polygon, , store in object         this.multipolygon = new multipolygon(                 polygonlist.toarray(new polygon[polygonlist.size()]),                 factory);     }     return this.multipolygon; } 

check if 2 geometrys intersect:

    public boolean collidesjts(mapsquarepolygonfeature mapsquare, geometryfactory factory,         arraylist<polygon> polygonlist, linearring polygonringholder,         arraylist<linearring> holeholder,         arraylist<coordinate> coordinateholder) {     return this.multipolygon.intersects(mapsquare.topolygonjts(factory, polygonringholder, holeholder, coordinateholder)); } 

edit 2: code runs if create distance 2 geometrys, e.g. multiply polygon's x , y 10.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -