concept ST_AsRaster in category postgis

appears as: ST_AsRaster
PostGIS in Action, Third Edition

This is an excerpt from Manning's book PostGIS in Action, Third Edition.

The specialized ST_AsRaster function converts any 2D geometry into a PostGIS raster format. And from there into countless other raster formats. The SQL statement outputs an image of the geometries stored in ch04.osm_roads as a PNG file.

  • Convert PostGIS geometries to rasters with ST_AsRaster.
  • Figure 7.1. ST_AsRaster: the left line is fixed 50 ✕ 500 and the secondis proportional to the road but 200 px wide
    fig st asraster fixed
    PostGIS in Action, Second Edition

    This is an excerpt from Manning's book PostGIS in Action, Second Edition.

    Simpler functions to use if you just want to output in the common PNG, JPEG, or TIFF formats are the ST_AsPNG, ST_AsJPEG, and ST_AsTiff functions, which take fewer arguments because they have many of the common defaults set. In addition, the ST_AsRaster function allows you to convert any 2D (non-curved) geometry into a PostGIS raster format that can then be converted to any of the GDAL-supported formats, thus allowing you to render your geometries in many raster formats as well.

    In the next chapter, we’ll continue our study with raster functions, covering unary functions that work with rasters and grouping them in a similar way where applicable. One geometry output function we neglected to mention in this chapter is ST_AsRaster, which takes a 2D geometry (non-curved) and outputs to raster format. We’ll cover this function and many more raster-centric functions in the next chapter.

    Figure 7.1. ST_AsRaster: the left line is fixed 50 × 500 and the second is proportional to the road but 200 px wide.