0

I believe I am doing a common operation where I am trying to clip a a Raster with a Geometry. They both share the same srid and I can successfully perform st_clip and st_intersection with the crop option set to true.

The result is what I expected which a raster where all the values that are outside of the geometry have been given a null value.

What I can't figure out is if I have a rectangular geometry, how I can align the cropping such that the resulting raster is the same shape without any null values?

2

Try ST_Clip instead, it is designed for this task. By default it will also crop the result to the geometries extend.

Basic usage (for all bands in a [multiband] raster):

SELECT ST_Clip(rast, geom)
FROM <your_raster_table>

Or do I get this wrong, do you use it and it doesn't work? Note: the extend will always be rectangular in the sense of pixel space, so if your raster's CRS is not in geodetic coordinates (e.g. EPSG:4326), it will most likely have areas along it's sides where NULL values had to be added.

  • I think I mispoke in my question. I am using ST_CLIP to clip the raster by a geometry. It is true we should always expect a rectangular pixel space. However I would like this rectangular pixel space to be transformed align with the axis of my Geometry. So for instance if my geometry is not axis aligned with the raster, but is itself rectangular I would like it rotated so that I don't have all these null data values. – Mimyck Feb 8 '18 at 20:12
  • @Mimyck what's the data's CRS? – ThingumaBob Feb 8 '18 at 20:25
  • I am not sure why the specific CRS matters as long as they are in the same one, but lets go with 4326 for this example. My issue is that when it performs the crop it seems to take the rectangular envelop of the raster orientation which I would like to perform a transformation on so it is aligned with the longer axis of the rectangular geometry. My suspicion is I could perform a rotate function or transformation afterwards to get it into proper format? – Mimyck Feb 8 '18 at 20:37

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.