I have a point table containing values ranging from 0 to 100 and I would like to draw a contour line for the value 70. (See image below)

I know how to create contour lines in QGIS for raster data but now I would like to do it with vector data (my point table) using PostGIS so that it can be integrated in a python script.

Any idea on how to start?

EDIT: This question is different from Generating contour lines and filled contours from points as it doesn't involve raster data (neither in the input nor in the output)

enter image description here

  • this is a very complex clustering problem, and there isn't nearly enough information (afaik) to tackle it. For instance, how do you know both of those 70s aren't islands? – Evan Carroll Nov 2 '17 at 21:32
  • If you have a Python script that does contouring, you can create a fucntion in Postgis using pythonu extension – John Powell Nov 3 '17 at 12:43

I think what you want is something like gdal_contour.

gdal_contour: Builds vector contour lines from a raster elevation model.

Usage: gdal_contour [-b <band>] [-a <attribute_name>] [-3d] [-inodata]
                    [-snodata n] [-i <interval>]
                    [-f <formatname>] [[-dsco NAME=VALUE] ...] [[-lco NAME=VALUE] ...]
                    [-off <offset>] [-fl <level> <level>...]
                    [-nln <outlayername>]
                    <src_filename> <dst_filename>

But PostGIS doesn't seem to implement anything like that from GDAL.

GDAL expects a input raster elevation model (DEM). PostGIS has a few DEM functions but I don't believe they'll help you here.


To create contour in PostGIS I usually use ST_ConvexHull or ST_ConcaveHull

Usage of it is simple as that:

             FROM point_table 
             GROUP BY pointId;

But to create polygon like at your picture is not really easy.

You can try some other functions using this cheatsheet.

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.