7

Is it possible to convert a PostGIS raster back to a line?

I'd like to generalize some vector data by converting it to raster and altering the cellsize to fix 'gaps' in the vector connectivity.

Once I've reached a good raster cellsize, I'd like to convert that raster back to a vector line, connecting all the cell centroids into continuous lines within a given tolerance (so as not to connect too many adjacent cells at intersections).

I figure the query would look something like this, but can't figure out what the outer function would be:

Convert To Vector (line) (
  Convert to Raster(cellsize)
  (
  Original Line (geom)
  )
)

One simple example would be to convert the raster 'line' back to a vector as in the ST_AsRaster documentation SQL:

ST_AsRaster(
        ST_Buffer(
            ST_GeomFromText('LINESTRING(50 50,150 150,150 50)'), 10,'join=bevel'), 
            200,200,ARRAY['8BUI', '8BUI', '8BUI'], ARRAY[118,154,118], ARRAY[0,0,0]);

1 Answer 1

3

You would use something like:

-- Dump As Polygons -- http://postgis.net/docs/RT_ST_DumpAsPolygons.html

or

-- ST_Polygon -- http://postgis.net/docs/RT_ST_Polygon.html

To convert your your raster back to a geometry. Except note that since rasters are tiny pixels, you get back an areal geometry.

In PostGIS 2.2.0 -- release is eminent, if you have built with SFCGAL, you can use

the ST_ApprovimateMedialAxis.html

http://postgis.net/docs/manual-dev/ST_ApproximateMedialAxis.html

the ST_StraightSkeleton function,

http://postgis.net/docs/manual-dev/ST_StraightSkeleton.html

I think ST_ApprovimateMedialAxis.html does close to what you want when applied to the polygon you get back from raster. I think others have plpgsql functions lying around that do something similar too if you can't get your hands on SFCGAL enriched PostGIS 2.2

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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