|
From: <db...@op...> - 2005-05-06 18:33:39
|
Jessie,
I read your message, and I wanted to make sure you were aware of some of
the JTS details involving intersection.
As you know, you may find that there are exceptions thrown by JTS when
you try to do an intersection(). Here's some notes that I hope will
help:
1. use EnhancedPrecisionOp. Its in JTS, and example is also in JTS -
com.vividsolutions.jtsexample.precision.EnhancedPrecisionOpExample.
Give it a quick read and also the EnhancedPrecisionOp class code.
I'm simplifying, but it basically works like this:
a) try to do a.intersection(b) -- if it works great, return the
result
b) if there was a topology exception, it will re-do the
intersection after translating the geometry to the origin (its actually
more complex - see CommonBitsOp). For example, your data may have
coordinate in the 1,000,000 range (like BC ALBERS) - you're basically
wasting 6 digits of precision on nothing!
NOTE: the java docs say that the results of #2 may produce an
invalid polygon (so be careful)
2. If you still get a topology exception, try making the bounding box
that you're clipping against a "wee bit" bigger (ie. expand it in all
direction by the size of a pixel or 2). Its likely that this will
solve any of your problems. If it doesnt you can try expanding your
bbox even more.
3. Finally, if you cannot actually do the intersection, you'll have to
use the entire geometry.
NOTE: whenever you do intersection(), and one of your geometries is
invalid, you have no idea what the result will be!! Its likely that
you'll be occationally given invalid geometries from your datastores.
NOTE: the results of a polygon-polygon intersection can end up with
lines and points (if the polygon just touches the bounding box) and
multi-polygons. You may want to either throw these away or buffer them
by a bit so they are actually drawn. line-polygon intersections can,
likewise, end up with points.
NOTE: when you decimate the geometry for rendering (removing points that
fall in the same pixel), you can easily make the polygon "invalid", so
you probably want to decimate AFTER intersection.
NOTE: intersection can be very slow! You might find, for large
polygons, thats its faster to decimate-and-draw than to do the
intersection...
NOTE: the latest JTS has optimized code for doing polygon-box
intersections. You might want to ask martin davis which version this
was introduced in.
NOTE: if the geometry is a geometrycollection (ie. contains 2 types of
geometries - ie. a polygon and a line OR two polygons that do not meet
multi-polygon validity) you'll find a.intersection(b) throws an
exception - you'll have to run each of the sub-components though the
intersection.
dave
----------------------------------------------------------
This mail sent through IMP: https://webmail.limegroup.com/
|