tminglei / slick-pg

Slick extensions for PostgreSQL
BSD 2-Clause "Simplified" License
839 stars 180 forks source link

Additional Postgis operators #346

Open kiambogo opened 7 years ago

kiambogo commented 7 years ago

It would be great if there were some additional Postgis operators supported. In particular, I find the need for 1) ST_LineLocatePoint (https://postgis.net/docs/ST_LineLocatePoint.html) 2) ST_DumpPoints (https://postgis.net/docs/ST_DumpPoints.html) 3) ST_LineSubstring (https://postgis.net/docs/ST_LineSubstring.html)

Any possibility of getting these included? I can perhaps take a shot at implementing if these wouldn't otherwise be supported.

tminglei commented 7 years ago

Yes, you can send me a pull request. I'd like to merge it.

kiambogo commented 7 years ago

ST_DumpPoints is tricky, as it returns a GeometryDump type:

https://postgis.net/docs/ST_DumpPoints.html

This set-returning function (SRF) returns a set of geometry_dump rows formed by a geometry (geom) and an array of integers (path).

The geom component of geometry_dump are all the POINTs that make up the supplied geometry

The path component of geometry_dump (an integer[]) is an index reference enumerating the POINTs of the supplied geometry. For example, if a LINESTRING is supplied, a path of {i} is returned where i is the nth coordinate in the LINESTRING. If a POLYGON is supplied, a path of {i,j} is returned where i is the ring number (1 is outer; inner rings follow) and j enumerates the POINTs (again 1-based index).

From this, it sounds like there would need to be support for Tuple2[Int, Geometry] for a linestring, or Tuple2[Seq[Int], Geometry] for a polygon/3d shape. For my use case I only need linestring support, so I'm tempted to just proceed with that given the added complexity for a polygon :).

In this case, I think I would like to define the return as a Tuple2[Int, Geometry]. What are your thoughts on that?

tminglei commented 7 years ago

Just define Tuple2[Int, Geometry], we can add Tuple2[Seq[Int], Geometry] support later if necessary.