[postgis-users] Exception in Poligonizer
Martin Davis
mbdavis at refractions.net
Tue Apr 10 09:04:26 PDT 2007
This is really a JTS question, so I'm cross-posting to that list.
The problem is that the last input linestring (LINESTRING (83.2 276.6,
83.2 276.6) ) has only one unique coordinate. Currently this is not
handled by the polygonizer code. If you remove this item, the test code
runs fine.
Since the polygonizer already filters out empty linestrings, I've added
another check to discard single-point linestrings as well.
Leticia wrote:
>
> Hi Community,
>
>
>
> I have to make polygons from linestrings. When I run the
> following code (I extracted the affected source code) I obtain the
> following runtime error:
>
> Exception in thread "main" _java.lang.ArrayIndexOutOfBoundsException_: 1
>
> at
> com.vividsolutions.jts.operation.polygonize.PolygonizeGraph.addEdge(_PolygonizeGraph.java:120_)
>
> at
> com.vividsolutions.jts.operation.polygonize.Polygonizer.add(_Polygonizer.java:133_)
>
> at
> com.vividsolutions.jts.operation.polygonize.Polygonizer.access$000(_Polygonizer.java:58_)
>
> at
> com.vividsolutions.jts.operation.polygonize.Polygonizer$LineStringAdder.filter(_Polygonizer.java:69_)
>
> at
> com.vividsolutions.jts.geom.LineString.apply(_LineString.java:248_)
>
> at
> com.vividsolutions.jts.operation.polygonize.Polygonizer.add(_Polygonizer.java:120_)
>
> at
> com.vividsolutions.jts.operation.polygonize.Polygonizer.add(_Polygonizer.java:106_)
>
> at Proof.main(_Proof.java:100_)
>
>
>
>
>
>
>
> *import* java.util.*;
>
> *import* com.vividsolutions.jts.geom.*;
>
> *import* com.vividsolutions.jts.io.*;
>
> *import* com.vividsolutions.jts.operation.polygonize.*;
>
>
>
> *public* *class* Proof
>
> {
>
>
>
> *public* *static* *void* main(String[] argv) *throws* ParseException
>
> {
>
> String wktB[] =
>
> {
>
> "LINESTRING (59.5 71.5, 59.5 74)", "LINESTRING
> (59.5 74, 59.5 87.3)",
>
> "LINESTRING (59.5 87.3, 59.5 96.6)", "LINESTRING
> (59.5 96.6, 59.5 118)",
>
> "LINESTRING (59.5 118, 59.5 131.5)", "LINESTRING
> (59.5 131.5, 59.5 147.6)",
>
> "LINESTRING (59.5 147.6, 59.5 148.7)", "LINESTRING
> (59.5 148.7, 59.5 149.7)",
>
> "LINESTRING (59.5 149.7, 59.5 152.4)", "LINESTRING
> (59.5 152.4, 59.5 155.9)",
>
> "LINESTRING (59.5 155.9, 59.5 171.7)", "LINESTRING
> (59.5 171.7, 59.5 172.2)",
>
> "LINESTRING (59.5 172.2, 59.5 173)", "LINESTRING
> (59.5 173, 59.5 174.7)",
>
> "LINESTRING (59.5 174.7, 59.5 180.6)", "LINESTRING
> (59.5 180.6, 59.5 190.2)",
>
> "LINESTRING (59.5 190.2, 59.5 210.9)", "LINESTRING
> (59.5 210.9, 59.5 211.4)",
>
> "LINESTRING (59.5 211.4, 59.5 223)", "LINESTRING
> (59.5 223, 59.5 240)",
>
> "LINESTRING (59.5 240, 59.5 242.9)", "LINESTRING
> (59.5 242.9, 59.5 246.7)",
>
> "LINESTRING (59.5 246.7, 59.5 249.9)", "LINESTRING
> (59.5 249.9, 59.5 257.5)",
>
> "LINESTRING (59.5 257.5, 59.5 280)", "LINESTRING
> (59.5 280, 59.5 282.8)",
>
> "LINESTRING (59.5 282.8, 59.5 293.6)", "LINESTRING
> (25.9 148.7, 35.1 148.7)",
>
> "LINESTRING (35.1 148.7, 45.9 148.7)", "LINESTRING
> (45.9 148.7, 46 148.7)",
>
> "LINESTRING (46 148.7, 46.8 148.7)", "LINESTRING
> (46.8 148.7, 54.3 148.7)",
>
> "LINESTRING (54.3 148.7, 58.4 148.7)", "LINESTRING
> (58.4 148.7, 58.6 148.7)",
>
> "LINESTRING (58.6 148.7, 59.1 148.7)", "LINESTRING
> (59.1 148.7, 59.5 148.7)",
>
> "LINESTRING (59.5 148.7, 60.4 148.7)", "LINESTRING
> (60.4 148.7, 64.7 148.7)",
>
> "LINESTRING (64.7 148.7, 69.9 148.7)", "LINESTRING
> (69.9 148.7, 75 148.7)",
>
> "LINESTRING (75 148.7, 79 148.7)", "LINESTRING (79
> 148.7, 80.5 148.7)",
>
> "LINESTRING (80.5 148.7, 81.8 148.7)", "LINESTRING
> (81.8 148.7, 83.2 148.7)",
>
> "LINESTRING (83.2 148.7, 85.4 148.7)", "LINESTRING
> (85.4 148.7, 91.4 148.7)",
>
> "LINESTRING (91.4 148.7, 92.1 148.7)", "LINESTRING
> (92.1 148.7, 98 148.7)",
>
> "LINESTRING (98 148.7, 105.2 148.7)", "LINESTRING
> (105.2 148.7, 115.8 148.7)",
>
> "LINESTRING (83.2 71.5, 83.2 85.9)", "LINESTRING
> (83.2 85.9, 83.2 115.2)",
>
> "LINESTRING (83.2 115.2, 83.2 120.2)", "LINESTRING
> (83.2 120.2, 83.2 143.4)",
>
> "LINESTRING (83.2 143.4, 83.2 147.1)", "LINESTRING
> (83.2 147.1, 83.2 148.7)",
>
> "LINESTRING (83.2 148.7, 83.2 150.5)", "LINESTRING
> (83.2 150.5, 83.2 164.8)",
>
> "LINESTRING (83.2 164.8, 83.2 170)", "LINESTRING
> (83.2 170, 83.2 173)",
>
> "LINESTRING (83.2 173, 83.2 173.2)", "LINESTRING
> (83.2 173.2, 83.2 215.7)",
>
> "LINESTRING (83.2 215.7, 83.2 220.2)", "LINESTRING
> (83.2 220.2, 83.2 223)",
>
> "LINESTRING (83.2 223, 83.2 236)", "LINESTRING
> (83.2 236, 83.2 246.7)",
>
> "LINESTRING (83.2 246.7, 83.2 252)", "LINESTRING
> (83.2 252, 83.2 276.6)",
>
> "LINESTRING (83.2 276.6, 83.2 276.6)"
>
> };
>
>
>
> GeometryFactory fact = *new* GeometryFactory(*new*
> PrecisionModel (1E1), 0);
>
>
>
> WKTReader wktRdr = *new* WKTReader(fact);
>
>
>
> ArrayList lines= *new* ArrayList();
>
>
>
> *for*(*int* rec= 0; rec < wktB.length; rec++)
>
> {
>
> Geometry a = wktRdr.read(wktB[rec]);
>
> lines.add(a);
>
> }
>
>
>
> Polygonizer polygonizer = *new* Polygonizer();
>
> polygonizer.add(lines);
>
> }
>
> }
>
>
>
>
>
> I cannot understand the exception and how can I solve it.
>
>
>
>
>
> Thanks in advance,
>
> Leticia
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022
More information about the postgis-users
mailing list