[postgis-users] Extract a part of a linestring

Brian Modra brian at zwartberg.com
Tue Sep 29 06:01:31 PDT 2009


2009/9/29 Nicolas Gillet - MARKET-IP <nicolas.gillet at market-ip.com>:
> Hello,
>
>
>
> I am new in postgis environment and start to discover this powerful tool.
>
>
>
> I am facing problem with the data I have and need to transform them.
>
> I use a library to render maps based on “painter’s algorithm”. (We are
> especially focused on roads transportation elements).
>
>
>
> So to be more accurate I need to represent road crossing properly with
> bridges above tunnels and not the opposite …
>
>
>
> I can match elevation points and road elements being able to see an “above /
> below” information but there is a big problem :
>
> One road element can match many elevation points because a long road element
> can be once above and, a few meters further, below another road. It becomes
> impossible to order them.
>
>
>
> My only solution is to split road elements into pieces which can have one
> and only one possible elevation.
>
>
>
> I think I will need a function in order to do this and .. I have never
> written any SQL function :’(
>
>
>
> The behavior I would reach is
>
> From one multilinestring extract the line segment that intersects my
> elevation point.
>
>
>
> e.g.
>
> POINT (2 2)
>
> MULTILINSTRING((0 0, 3 3, 6 6), (3 3, 3 4, 4 5))
>
> Returns would be
>
> LINESTRING(0 0, 3 3)
>
>
>
> So if I write it in pseudo code, function prototype should look like :
>
> LINESTRING get_matching_segment(MULTILINESTRING source, POINT needle)
>


Use ST_line_locate_poin and ST_line_substring

here's an extract from the manual:

ST_line_substring(linestring, start, end)

    Return a linestring being a substring of the input one starting
and ending at the given fractions of total 2d length. Second and third
arguments are float8 values between 0 and 1.

    If 'start' and 'end' have the same value this is equivalent to
line_interpolate_point().

    See line_locate_point() for computing the line location nearest to a Point.
    Note

    Since release 1.1.1 this function also interpolates M and Z values
(when present), while prior releases set them to unspecified values.

    Availability: 1.1.0
ST_line_locate_point(LineString, Point)

    Returns a float between 0 and 1 representing the location of the
closest point on LineString to the given Point, as a fraction of total
2d line length.

    You can use the returned location to extract a Point
(line_interpolate_point) or a substring (line_substring).

    Availability: 1.1.0
>
> I found something about how to split a MULTI* geometry (GeometryN(geometry,
> index)), getting points inside a geometry (PointN(geometry, index) or
> getting a part of a geometry (Line_SubString(geometry, double, double)), …
> but I can’t find a way to put them together to get what I want.
>
>
>
> Any tips about detailed existing functions’ documentation and the way to
> create custom SQL functions would be greatly appreciated.
>
>
>
> Thank you :-).
>
>
>
> Best regards.
>
>
>
> Nicolas
>
> Gillet
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>



-- 
Brian Modra   Land line: +27 23 5411 462
Mobile: +27 79 69 77 082
5 Jan Louw Str, Prince Albert, 6930
Postal: P.O. Box 2, Prince Albert 6930
South Africa
http://www.zwartberg.com/



More information about the postgis-users mailing list