Search code examples
postgismeasurementmeasure

PostGIS Measure multiple linestrings


I'm new in postgis and i'm trying to mesasure linestrings giving two initial points, start and end point in the same layer (geometry type is linestring). This linestrings represents roads, rivers, underground pipes..etc.

Using postgis function named 'length3d' i can measure ONE line (one record of table), but i need measue multiple and contiguous line; something like this example (using the next annotations for the explanation example)

  • |S| --> Line Start point
  • |E| --> Line End point
  • @ --> Point in line
  • (s) --> user start point
  • (e) --> user end point

Example:

|S|===@===@===(s)==|E-S|===@==@===@==|E-S|===@===@===(e)==@==|E|

Linestring format:

LINESTRING(-6.366424 38.93301,-6.3625 38.938,-6.361 38.9572,-6.36158230284898 38.9397667955807,-6.36131118520776)

User points could be between two existing points that composed the line.

|S| to |E-S| is one record on DB |E-S| to |E-S| is other record and |E-S| to |E| is other record.

How i can measure distance from (s) to (e)?

Thanks in advance!


Solution

  • Using PL/pgSQL you can create a function that measures each of the components of your path (from (s) to [E-S], from [E-S] to [E-S] and so on).

    You can pre-process, and create an temporary linestring(or multilinestring) that represents the line between (s) and (e) and then use ST_Length3D directly on that.