Opened 10 years ago

Closed 9 years ago

Last modified 7 years ago

#1293 closed enhancement (fixed)

[raster] ST_Resize to resize raster tiles

Reported by: robe Owned by: Bborie Park
Priority: medium Milestone: PostGIS 2.1.0
Component: raster Version: master
Keywords: history Cc:

Description (last modified by pracine)


I'm ticketing what we discussed. As mentioned, it would be nice to have a resize function that provides the similar functionality to gdal_translate that can take a percentage reduction or max pixel dimensions.


what gdal_translate:

gdal_translate -of png -outsize 25% 25% original.png final.png
gdal_translate -of png -outsize 500 500 original.png final.png

Currently have to use ST_Resample for this which requires a lot more arguments, not to mention it doesn't seem to work for rasters with no srid information.

I'm envisioning the signature would look something like

ST_Resize(rast raster, width text, height text)

where width can be a numeric like '500' or can be a percentage like '50%' which is why I made it text.

This will make postgis raster useful for both GIS folks and non-GIS folks as having an easy function to resize a raster will speed up all kinds of analysis. Like I mentioned, my selfish need is that most of my raster projects do not involve objects that fit in a nice spatial reference landscape but the analysis functions we've got so far I'm finding very useful for those (e.g. image recognition, and just plotting and vectorizing non-GIS like things like anatomic parts, or construction objects)

Change History (17)

comment:1 Changed 10 years ago by pracine

what would be the difference with ST_Rescale()?

comment:2 Changed 10 years ago by Bborie Park

ST_Resize would use the same underlying function calls as gdal_translate. ST_Rescale (ST_Resample) makes use the of the same underlying function call as gdalwarp. To use ST_Resample, the raster must have a SRID. I ran some basic tests on random pictures I had lying around (no spatial reference) using gdalwarp (to test for behavior) and as expected returned an error.

By the looks of it, gdal_translate will resize any image for you regardless of spatial reference.

So for one of my random pictures

gdal_translate -of png outsize 25% 25% 0884Parkfl\ copy.jpg TEST.PNG

gdal_translate works.

gdalwarp -ts 1000 1000 0884Parkfl\ copy.jpg test.tif

gdalwarp doesn't. Error given is:

ERROR 1: Unable to compute a transformation between pixel/line
and georeferenced coordinates for 0884Parkfl copy.jpg.
There is no affine transformation and no GCPs.

comment:3 Changed 10 years ago by bnordgren

This still seems like a valid tool request. The requirements would be:

# ignore the affine transform if there is no SRID # "adjust" the affine transform to correctly map pixel indices to geopoints after the pixels have been resized (if an SRID is present).

Does gdal_translate perform function #2 if given a georeferenced image? Perhaps it would point to a set of function calls which allow us a greater degree of control over the data type?

comment:4 Changed 10 years ago by bnordgren

Argh! I used redmine wiki formatting by mistake. Function #2 is the "adjusting" of the affine transform...

comment:5 Changed 10 years ago by Bborie Park

Summary: ST_Resize to resize raster tiles[raster] ST_Resize to resize raster tiles

comment:6 Changed 10 years ago by pracine

Description: modified (diff)

comment:7 Changed 10 years ago by pracine

Milestone: PostGIS Raster FuturePostGIS Future

comment:8 Changed 9 years ago by pracine

That makes me say that all of the ST_resample(), ST_Rescale(), ST_ReSkew(), ST_SnapToGrid() should be based on the same underlying function as gdal_translate (and work even if they don't have a SRID) and only ST_Transform() should be based on the gdalwarp mechanic...

comment:9 Changed 9 years ago by Bborie Park

No can do to using what underlies gdal_translate for those functions. The big drawback of gdal_translate (and underlying functionality) is that there is no ability to select a resampling algorithm. I'm assuming it uses nearest neighbor...

comment:10 Changed 9 years ago by pracine

to fix the unknow SRID issue, isn't it possible to assign a temporary dummy SRID (maybe not that dummy) to the raster before passing it to gdalwarp and to remove it once we get the result? Since the requested SRID and the dummy one would be the same there should not be side issue.

comment:11 Changed 9 years ago by Bborie Park

That should work... would need significant testing though...

comment:12 Changed 9 years ago by Bborie Park

Owner: changed from pracine to Bborie Park
Status: newassigned

I just ran my go-to test raster through gdalwarp with a variety of SRSes (SRSs?) adjusting only the output pixel scale and the outputs from all are identical (including the raster's true SRS).

I'll go ahead and write this function so that others can start testing...

comment:13 Changed 9 years ago by Bborie Park

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r10774. Early Christmas gift for robe!

comment:14 Changed 9 years ago by robe

Thanks. Now I can create my christmas montage.

comment:15 Changed 9 years ago by robe

Works nicely even with out of db rasters:

I promise to do something less playful and more work-related in the future :)

comment:16 Changed 9 years ago by Bborie Park

Yay! Thanks for posting that it works.

comment:17 Changed 7 years ago by robe

Milestone: PostGIS FuturePostGIS 2.1.0

duh we never even marked this at 2.1.0

Note: See TracTickets for help on using tickets.