[postgis-users] Establish versus of a line

Nicolas Ribot nicolas.ribot at gmail.com
Fri Apr 30 02:31:49 PDT 2010


> Hi,
>
> I have a table with a geometry LineString.
> This Linestrings are a pseudo-copy of the boundaries of some polygon
> geometries hosted in another table.
>
> I say "pseudo-copy" because the geometry is identical but the versus can be
> changed (respect to the polygons).
>
> I need to fill a field of the linestrings table with the versus of the line.
> The versus of the linestring if defined like this:
>  "1" if starting from first vertex of the line and going forward last vertex
> , the polygon is on the left,
>  "0" if the polygon is on the rigth.
>
> I like to fill this field with a sql insert, but I don't understand if there
> really a method to understand the versus of the line respect to the
> polygons.
>
> Many thx,
>
> Andrea Peri.
>

Hi Andrea,
If I understand correctly, you want your linestrings to carry an
attribute telling if the polygons they come from is clockwise or
counter clockwise ?

You could compare the original polygons and the reversed version, to
determine their orientation:

select st_orderingEquals(geom, st_forceRHR(geom)) from

(select geometryFromText('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', -1) as geom
union
select geometryFromText('POLYGON ((2 2, 2 3, 3 3, 3 2, 2 2))', -1) as
geom) as foo
;

If you keep a link between linestrings and polygons they come from, an
update to the linestrings table should be easy, then.

HTH
Nicolas



More information about the postgis-users mailing list