Ticket #1293 (closed enhancement: fixed)

Opened 18 months ago

Last modified 6 months ago

[raster] ST_Resize to resize raster tiles

Reported by: robe Owned by: dustymugs
Priority: medium Milestone: PostGIS Future
Component: raster Version: trunk
Keywords: history Cc:

Description (last modified by pracine) (diff)

Bborie,

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.

e.g.

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

Changed 18 months ago by pracine

what would be the difference with ST_Rescale()?

Changed 18 months ago by dustymugs

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.

Changed 18 months 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?

Changed 18 months ago by bnordgren

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

Changed 18 months ago by dustymugs

  • summary changed from ST_Resize to resize raster tiles to [raster] ST_Resize to resize raster tiles

Changed 15 months ago by pracine

  • description modified (diff)

Changed 15 months ago by pracine

  • milestone changed from PostGIS Raster Future to PostGIS Future

Changed 6 months 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...

Changed 6 months ago by dustymugs

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...

Changed 6 months 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.

Changed 6 months ago by dustymugs

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

Changed 6 months ago by dustymugs

  • owner changed from pracine to dustymugs
  • status changed from new to assigned

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...

Changed 6 months ago by dustymugs

  • keywords history added
  • status changed from assigned to closed
  • resolution set to fixed

Added in r10774. Early Christmas gift for robe!

Changed 6 months ago by robe

Thanks. Now I can create my christmas montage.

Changed 6 months ago by robe

Works nicely even with out of db rasters:  http://www.bostongis.com/blog/index.php?/archives/205-Waiting-for-PostGIS-2.1-ST_Resize-not-just-for-GIS.html

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

Changed 6 months ago by dustymugs

Yay! Thanks for posting that it works.

Note: See TracTickets for help on using tickets.