[postgis-users] PostGIS and Section lines

Bill Thoen bthoen at gisnet.com
Fri Jan 26 08:58:59 PST 2007

```Bruce Rindahl wrote:
> Step one is to find the vertex that is the closest to the corners of the
> bounding box.  I plan on getting the extent of the section using envelope().
> Then for each point in the geometry I need to get the distance to the
> XMIN,YMIN point in the bounding box.  The point with the shortest distance
> is the South West corner of the section. I will update the table with the
> index of that point.  Each point can be found from:
> PointN(ExteriorRing(GeometryN(the_geom,1)),x) where x goes from 1 to
> NumPoints(ExteriorRing(GeometryN(the_geom,1))).
> Is there a straight forward way to get this index?  I need them for each
> corner of the polygon (section).  This is done once and the table will be
> updated with the indexes for the SW, SE, NE and NW corners of the section.
>
In the easy cases, you'll be able to find the closest point to corner of
the minimum bounding rectangle (which you get from envelope() I guess)
by testing each point's distance to the four points of the enclosing
rectangle. But as you probably know, there are "triangular" sections and
other pathological oddities (especially near rivers and at the survey
borders). So you'll have to make sure you have four DIFFERENT corner
points when you identify your section corners.
> Step two is to create lines on the fly from these indexes.  If the index for
> the NE corner is say 3 and the SE corner is 6, then the East line of the
> section is the line from point(3) to point(4) to point(5) to point(6).  If a
> location is defined as 500 feet from the east section line and 1000 feet
> from the south section line (very typical in my application) the I can
> create the east line and the south line as above, translate the east line
> 500 feet west, the south line 1000 feet north, and the result is the
> intersection of these translated lines.  Given a point the distances to the
> lines is easy - distance(the point , a section line).  The question here is
> what is the easiest way to generate a line from specified vertexes of a
> polygon?
>
I think you've got the right algorithm... do you just need to know how
to create a line by copying points from a subset of your section polygon
(while also translating each point's X-coordinate by -500 ft in the case
of the east line)? I know this algorithm, but I've not implemented it in
PostGIS yet, but I think it's partly a matter of finding each PointN
from one vertex to the other, translating each coordinate and building a
new line from them. The other tricky bit is transforming the coordinates
to a local system of feet so that the translations are straight-forward.
If I get some time today I'll see if I can dig up something on that
because I'd like to know the PostGIS details on it too.

- Bill Thoen

```