0

I'm writing a PostgreSQL extension that should do a certain mathematical operations on a geometry field. However all I really need to make it work is give it coordinates as std::vector<Point2d>.

So how can one extract coordinates from geometry column, either using PostGIS helper methods or directly? Is it even possible?

  • What is the geometry type? – CL. Mar 27 at 12:51
  • It is a lineString. – jayarjo Mar 27 at 12:58
1

If you were using SQL, you could use ST_DumpPoints to get at the points.

But inside an extension, you need a more direct access to the geometry object. The internal storage format used by PostGIS changes between versions, so you cannot use it unless you put your code into the PostGIS library (if that is even possible in your system). So the best method to get a geometry object is as a WKB-formatted blob; Postgres will automatically convert the geometry into WKB if you declare your function to have a bytea parameter. (WKB is defined in the OGC Simple Feature Access specification.)

|improve this answer|||||
  • I was already considering to either bundle liblwgeom part of postgis into my extension or load appropriate conversion methods from postgis.so dynamically. – jayarjo Mar 27 at 15:45
0

You can extract coordianates from a geometry column quite easily:

For x:

st_x(geometry_column)

For y:

st_y(geometry_column)

Documentation:

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

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.