Hi Everyone,
I'm wondering if this is possible: I have a bunch of postal code polygons that are pretty complex. I'd like to simplify them, then cause the adjacent points of polygons to snap together so that there is no overlap. (Pre-simplify, they align to one another perfectly.) Here is the code I'm currently trying: ----- GeometryCollection geomColl = createGeometryCollectionFromWKT(polygonsAsWTK); GeometryCollectionIterator iter = new GeometryCollectionIterator(geomColl); while (iter.hasNext()) { Geometry g = (Geometry)iter.next(); Geometry simpleG = TopologyPreservingSimplifier.simplify(g, 0.01); if (snappyGeometries.size() > 0) { GeometrySnapper snapper = new GeometrySnapper(simpleG); Geometry lastGeometry = snappyGeometries.get(snappyGeometries.size()-1); double snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(lastGeometry, simpleG); simpleG = snapper.snapTo(snappyGeometries.get(snappyGeometries.size()-1), snapTolerance); } snappyGeometries.add(simpleG); } Geometry[] geometriesAsArray = (Geometry[]) snappyGeometries.toArray(new Geometry[snappyGeometries.size()]); Geometry snappyGeomCollection = new GeometryCollection(geometriesAsArray, geometriesAsArray[0].getFactory()); ----- And here is what "snappyGeomCollection" looks like in OpenJUMP: http://drop.io/mapster/asset/snaptest-jpg The code above assumes that the GeometryCollectionIterator will return Geometries in an order that will snap appropriately. I'm pretty much flying blind on this though, because I don't clearly know the capabilities of the Iterator or the GeometrySnapper. Any pointers would be very welcome! Thanks, Doug --- Doug Smith ELP Web Developer http://www.daveramsey.com "Life is an occasion, rise to it" -- Mr. Magorium _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
I think you're heading down a hard road here, Doug. I think you're
going to have a hard time preventing vertices from snapping to things they shouldn't. IMO the best way to simplify polygonal coverages like this is to convert the coverage to an edge-node topology, simplify the edges, and then repolygonize. There's bits and pieces in JTS to help you do this, but nothing "off-the-shelf". (I also have experimental code to do this, but it's not ready for release.) You can also use existing tools in JUMP to at least experiment with this - and if you're keen you can always look at how they work and bundle the code into a library for your own use. Try extracting all the unique, line segments, merging them, simplify, then repolygonize. Doug Smith wrote: > Hi Everyone, > > I'm wondering if this is possible: I have a bunch of postal code polygons that are pretty complex. I'd like to simplify them, then cause the adjacent points of polygons to snap together so that there is no overlap. (Pre-simplify, they align to one another perfectly.) > > Here is the code I'm currently trying: > > ----- > GeometryCollection geomColl = createGeometryCollectionFromWKT(polygonsAsWTK); > GeometryCollectionIterator iter = new GeometryCollectionIterator(geomColl); > > while (iter.hasNext()) { > Geometry g = (Geometry)iter.next(); > Geometry simpleG = TopologyPreservingSimplifier.simplify(g, 0.01); > if (snappyGeometries.size() > 0) { > GeometrySnapper snapper = new GeometrySnapper(simpleG); > Geometry lastGeometry = snappyGeometries.get(snappyGeometries.size()-1); > double snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(lastGeometry, simpleG); > simpleG = snapper.snapTo(snappyGeometries.get(snappyGeometries.size()-1), snapTolerance); > } > snappyGeometries.add(simpleG); > } > > Geometry[] geometriesAsArray = (Geometry[]) snappyGeometries.toArray(new Geometry[snappyGeometries.size()]); > Geometry snappyGeomCollection = new GeometryCollection(geometriesAsArray, geometriesAsArray[0].getFactory()); > ----- > > And here is what "snappyGeomCollection" looks like in OpenJUMP: > > http://drop.io/mapster/asset/snaptest-jpg > > The code above assumes that the GeometryCollectionIterator will return Geometries in an order that will snap appropriately. I'm pretty much flying blind on this though, because I don't clearly know the capabilities of the Iterator or the GeometrySnapper. > > Any pointers would be very welcome! > > Thanks, > > Doug > --- > Doug Smith > ELP Web Developer > http://www.daveramsey.com > > "Life is an occasion, rise to it" -- Mr. Magorium > > _______________________________________________ > jts-devel mailing list > [hidden email] > http://lists.refractions.net/mailman/listinfo/jts-devel > > -- Martin Davis Senior Technical Architect Refractions Research, Inc. (250) 383-3022 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
I like the plan of trying this in JUMP, then looking at the code to see
how it works. However, I'm having a hard time making it work in JUMP and wonder if you can provide a bit more guidance. I have attached my GeometryCollection WKT here: http://drop.io/mapster/asset/d-postal-codes-wkt-zip Here is what I have tried: 1. Open the WKT file in OpenJUMP. 2. Tools -> Edit Geometry -> Extract Segments - Click "Remove segments appearing more than one time" and "Merge resulting segments" 3. Make the extracted segments layer editable 4. Select all of the features in the extracted segments layer with the "select parts" tool. 5. Tools -> Generalization -> Simplify (JTS algorithm) - point displacement = 0.01 The result is simplification similar to the screen capture I posted earlier, where the polygons overlap one another -- the edges don't line up. Can you please let me know what I'm missing? Thanks! Doug -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Martin Davis Sent: Thursday, February 05, 2009 12:22 PM To: JTS Topology Suite Development Subject: Re: [jts-devel] Simplify & Snap? I think you're heading down a hard road here, Doug. I think you're going to have a hard time preventing vertices from snapping to things they shouldn't. IMO the best way to simplify polygonal coverages like this is to convert the coverage to an edge-node topology, simplify the edges, and then repolygonize. There's bits and pieces in JTS to help you do this, but nothing "off-the-shelf". (I also have experimental code to do this, but it's not ready for release.) You can also use existing tools in JUMP to at least experiment with this - and if you're keen you can always look at how they work and bundle the code into a library for your own use. Try extracting all the unique, line segments, merging them, simplify, then repolygonize. Doug Smith wrote: > Hi Everyone, > > I'm wondering if this is possible: I have a bunch of postal code polygons that are pretty complex. I'd like to simplify them, then cause the adjacent points of polygons to snap together so that there is no overlap. (Pre-simplify, they align to one another perfectly.) > > Here is the code I'm currently trying: > > ----- > GeometryCollection geomColl = createGeometryCollectionFromWKT(polygonsAsWTK); > GeometryCollectionIterator iter = new GeometryCollectionIterator(geomColl); > > while (iter.hasNext()) { > Geometry g = (Geometry)iter.next(); > Geometry simpleG = TopologyPreservingSimplifier.simplify(g, 0.01); > if (snappyGeometries.size() > 0) { > GeometrySnapper snapper = new GeometrySnapper(simpleG); > Geometry lastGeometry = snappyGeometries.get(snappyGeometries.size()-1); > double snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(lastGeometry, simpleG); > simpleG = snapper.snapTo(snappyGeometries.get(snappyGeometries.size()-1), snapTolerance); > } > snappyGeometries.add(simpleG); > } > > Geometry[] geometriesAsArray = (Geometry[]) snappyGeometries.toArray(new Geometry[snappyGeometries.size()]); > Geometry snappyGeomCollection = new GeometryCollection(geometriesAsArray, geometriesAsArray[0].getFactory()); > ----- > > And here is what "snappyGeomCollection" looks like in OpenJUMP: > > http://drop.io/mapster/asset/snaptest-jpg > > The code above assumes that the GeometryCollectionIterator will return Geometries in an order that will snap appropriately. I'm pretty much flying blind on this though, because I don't clearly know the capabilities of the Iterator or the GeometrySnapper. > > Any pointers would be very welcome! > > Thanks, > > Doug > --- > Doug Smith > ELP Web Developer > http://www.daveramsey.com > > "Life is an occasion, rise to it" -- Mr. Magorium > > _______________________________________________ > jts-devel mailing list > [hidden email] > http://lists.refractions.net/mailman/listinfo/jts-devel > > -- Martin Davis Senior Technical Architect Refractions Research, Inc. (250) 383-3022 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Doug, your dataset appears not to be a true polygonal coverage. The
polygons look like they've been buffered by a small amount, so that they overlap one another along the edges. The technique I described will only work if the input is a true coverage. I think you'll need to look for a version of the dataset which is a true coverage (e.g. hasn't been buffered). Failing that, you're into a conflation exercise, which can get complicated. Doug Smith wrote: > I like the plan of trying this in JUMP, then looking at the code to see > how it works. However, I'm having a hard time making it work in JUMP and > wonder if you can provide a bit more guidance. > > I have attached my GeometryCollection WKT here: > http://drop.io/mapster/asset/d-postal-codes-wkt-zip > > Here is what I have tried: > > 1. Open the WKT file in OpenJUMP. > 2. Tools -> Edit Geometry -> Extract Segments > - Click "Remove segments appearing more than one time" and > "Merge resulting segments" > 3. Make the extracted segments layer editable > 4. Select all of the features in the extracted segments layer with the > "select parts" tool. > 5. Tools -> Generalization -> Simplify (JTS algorithm) > - point displacement = 0.01 > > The result is simplification similar to the screen capture I posted > earlier, where the polygons overlap one another -- the edges don't line > up. > > Can you please let me know what I'm missing? > > Thanks! > > Doug > > -----Original Message----- > From: [hidden email] > [mailto:[hidden email]] On Behalf Of Martin > Davis > Sent: Thursday, February 05, 2009 12:22 PM > To: JTS Topology Suite Development > Subject: Re: [jts-devel] Simplify & Snap? > > I think you're heading down a hard road here, Doug. I think you're > going to have a hard time preventing vertices from snapping to things > they shouldn't. > > IMO the best way to simplify polygonal coverages like this is to convert > > the coverage to an edge-node topology, simplify the edges, and then > repolygonize. > > There's bits and pieces in JTS to help you do this, but nothing > "off-the-shelf". (I also have experimental code to do this, but it's > not ready for release.) > > You can also use existing tools in JUMP to at least experiment with this > > - and if you're keen you can always look at how they work and bundle the > > code into a library for your own use. Try extracting all the unique, > line segments, merging them, simplify, then repolygonize. > > Doug Smith wrote: > >> Hi Everyone, >> >> I'm wondering if this is possible: I have a bunch of postal code >> > polygons that are pretty complex. I'd like to simplify them, then cause > the adjacent points of polygons to snap together so that there is no > overlap. (Pre-simplify, they align to one another perfectly.) > >> Here is the code I'm currently trying: >> >> ----- >> GeometryCollection geomColl = >> > createGeometryCollectionFromWKT(polygonsAsWTK); > >> GeometryCollectionIterator iter = new >> > GeometryCollectionIterator(geomColl); > >> while (iter.hasNext()) { >> Geometry g = (Geometry)iter.next(); >> Geometry simpleG = TopologyPreservingSimplifier.simplify(g, >> > 0.01); > >> if (snappyGeometries.size() > 0) { >> GeometrySnapper snapper = new GeometrySnapper(simpleG); >> Geometry lastGeometry = >> > snappyGeometries.get(snappyGeometries.size()-1); > >> double snapTolerance = >> > GeometrySnapper.computeOverlaySnapTolerance(lastGeometry, simpleG); > >> simpleG = >> > snapper.snapTo(snappyGeometries.get(snappyGeometries.size()-1), > snapTolerance); > >> } >> snappyGeometries.add(simpleG); >> } >> >> Geometry[] geometriesAsArray = (Geometry[]) >> > snappyGeometries.toArray(new Geometry[snappyGeometries.size()]); > >> Geometry snappyGeomCollection = new >> > GeometryCollection(geometriesAsArray, > geometriesAsArray[0].getFactory()); > >> ----- >> >> And here is what "snappyGeomCollection" looks like in OpenJUMP: >> >> http://drop.io/mapster/asset/snaptest-jpg >> >> The code above assumes that the GeometryCollectionIterator will return >> > Geometries in an order that will snap appropriately. I'm pretty much > flying blind on this though, because I don't clearly know the > capabilities of the Iterator or the GeometrySnapper. > >> Any pointers would be very welcome! >> >> Thanks, >> >> Doug >> --- >> Doug Smith >> ELP Web Developer >> http://www.daveramsey.com >> >> "Life is an occasion, rise to it" -- Mr. Magorium >> >> _______________________________________________ >> jts-devel mailing list >> [hidden email] >> http://lists.refractions.net/mailman/listinfo/jts-devel >> >> >> > > -- Martin Davis Senior Technical Architect Refractions Research, Inc. (250) 383-3022 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Martin, you are correct, thank you very much! I did have a small buffer
on each of the polygons that I had forgotten about. I removed it and tried the procedure below ... and it worked! Now I have to figure out how to do that in code, and how I'm going to maintain a relationship between the original polygon and the simplified one so that I can use them individually. On my way! :-) Thanks again for your great help, Doug -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Martin Davis Sent: Thursday, February 05, 2009 4:29 PM To: JTS Topology Suite Development Subject: Re: [jts-devel] Simplify & Snap? Doug, your dataset appears not to be a true polygonal coverage. The polygons look like they've been buffered by a small amount, so that they overlap one another along the edges. The technique I described will only work if the input is a true coverage. I think you'll need to look for a version of the dataset which is a true coverage (e.g. hasn't been buffered). Failing that, you're into a conflation exercise, which can get complicated. Doug Smith wrote: > I like the plan of trying this in JUMP, then looking at the code to see > how it works. However, I'm having a hard time making it work in JUMP and > wonder if you can provide a bit more guidance. > > I have attached my GeometryCollection WKT here: > http://drop.io/mapster/asset/d-postal-codes-wkt-zip > > Here is what I have tried: > > 1. Open the WKT file in OpenJUMP. > 2. Tools -> Edit Geometry -> Extract Segments > - Click "Remove segments appearing more than one time" and > "Merge resulting segments" > 3. Make the extracted segments layer editable > 4. Select all of the features in the extracted segments layer with the > "select parts" tool. > 5. Tools -> Generalization -> Simplify (JTS algorithm) > - point displacement = 0.01 > > The result is simplification similar to the screen capture I posted > earlier, where the polygons overlap one another -- the edges don't > up. > > Can you please let me know what I'm missing? > > Thanks! > > Doug > > -----Original Message----- > From: [hidden email] > [mailto:[hidden email]] On Behalf Of Martin > Davis > Sent: Thursday, February 05, 2009 12:22 PM > To: JTS Topology Suite Development > Subject: Re: [jts-devel] Simplify & Snap? > > I think you're heading down a hard road here, Doug. I think you're > going to have a hard time preventing vertices from snapping to things > they shouldn't. > > IMO the best way to simplify polygonal coverages like this is to > > the coverage to an edge-node topology, simplify the edges, and then > repolygonize. > > There's bits and pieces in JTS to help you do this, but nothing > "off-the-shelf". (I also have experimental code to do this, but it's > not ready for release.) > > You can also use existing tools in JUMP to at least experiment with this > > - and if you're keen you can always look at how they work and bundle the > > code into a library for your own use. Try extracting all the unique, > line segments, merging them, simplify, then repolygonize. > > Doug Smith wrote: > >> Hi Everyone, >> >> I'm wondering if this is possible: I have a bunch of postal code >> > polygons that are pretty complex. I'd like to simplify them, then > the adjacent points of polygons to snap together so that there is no > overlap. (Pre-simplify, they align to one another perfectly.) > >> Here is the code I'm currently trying: >> >> ----- >> GeometryCollection geomColl = >> > createGeometryCollectionFromWKT(polygonsAsWTK); > >> GeometryCollectionIterator iter = new >> > GeometryCollectionIterator(geomColl); > >> while (iter.hasNext()) { >> Geometry g = (Geometry)iter.next(); >> Geometry simpleG = TopologyPreservingSimplifier.simplify(g, >> > 0.01); > >> if (snappyGeometries.size() > 0) { >> GeometrySnapper snapper = new GeometrySnapper(simpleG); >> Geometry lastGeometry = >> > snappyGeometries.get(snappyGeometries.size()-1); > >> double snapTolerance = >> > GeometrySnapper.computeOverlaySnapTolerance(lastGeometry, simpleG); > >> simpleG = >> > snapper.snapTo(snappyGeometries.get(snappyGeometries.size()-1), > snapTolerance); > >> } >> snappyGeometries.add(simpleG); >> } >> >> Geometry[] geometriesAsArray = (Geometry[]) >> > snappyGeometries.toArray(new Geometry[snappyGeometries.size()]); > >> Geometry snappyGeomCollection = new >> > GeometryCollection(geometriesAsArray, > geometriesAsArray[0].getFactory()); > >> ----- >> >> And here is what "snappyGeomCollection" looks like in OpenJUMP: >> >> http://drop.io/mapster/asset/snaptest-jpg >> >> The code above assumes that the GeometryCollectionIterator will >> > Geometries in an order that will snap appropriately. I'm pretty much > flying blind on this though, because I don't clearly know the > capabilities of the Iterator or the GeometrySnapper. > >> Any pointers would be very welcome! >> >> Thanks, >> >> Doug >> --- >> Doug Smith >> ELP Web Developer >> http://www.daveramsey.com >> >> "Life is an occasion, rise to it" -- Mr. Magorium >> >> _______________________________________________ >> jts-devel mailing list >> [hidden email] >> http://lists.refractions.net/mailman/listinfo/jts-devel >> >> >> > > -- Martin Davis Senior Technical Architect Refractions Research, Inc. (250) 383-3022 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
In reply to this post by Doug Smith-3
Hei Doug,
not sure if this hint helps since Martin wrote that your coverage seems to have overlaps. However, I just recently added to OpenJUMP source code a function to simplify polygonal tesseleations: see Tools/Generalization/Simplify Polygon Coverage It does more or less what Martin describes: extracting the common edges, simplify those, and polygonize them again. Unfortunately we have a problem with the nightly built of OpenJUMP .. so you need to pull the last code via SVN. I hope this helps a bit stefan _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Nice, thanks Stefan! I'll check it out!
Doug -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Stefan Steiniger Sent: Friday, February 06, 2009 12:22 AM To: [hidden email] Subject: [jts-devel] Re: Simplify & Snap? Hei Doug, not sure if this hint helps since Martin wrote that your coverage seems to have overlaps. However, I just recently added to OpenJUMP source code a function to simplify polygonal tesseleations: see Tools/Generalization/Simplify Polygon Coverage It does more or less what Martin describes: extracting the common edges, simplify those, and polygonize them again. Unfortunately we have a problem with the nightly built of OpenJUMP .. so you need to pull the last code via SVN. I hope this helps a bit stefan _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Free forum by Nabble | Edit this page |