4

@Sorin helped me putting raster into PostGIS at Changing table name of command using raster2pgsql?

Now, I want to output raster tile, then view it on QGIS. But the problem is the output of ST_RasterToWorldCoord(raster rast, integer x, integer y) makes me confused. I have 2 questions here:

  1. According to the docs, the function returns (long,lat) of the upper left corner of raster. So what is the use of the last 2 params (x,y)?
  2. I run the sql, and got the result of a raster (long,lat) = (563985, 2346615). I don't understand the result here. I think the long, lat values should be with in (-90 -> 90, -180 -> 180).
    I output the raster to file, and view it on a map. But the coordinate of the raster seems to be wrong, so it cannot be displayed.

Here my query:

SELECT st_rastertoworldcoord(rast,1,1)
FROM landsat

I have a raster before putting in postGIS. I can display it in QGIS, and it interscts/overlap some polygons, which come from a SHP file.
However, after cutting it into tiles and putting it into postGIS then run ST_Intersects(rast, geom). The function return 'false' in all rows.

My raster was imported with SRID 4326

(long,lat) = (-180 -> 180, -90 -> 90).  

1 Answer 1

4

Note the following sentence in the documentation:

Returned X and Y are in geometric units of the georeferenced raster

This explains why your coordinates are not in the range you expect. It is because your raster is in a coordinate system where the unit is not degrees (I'm guessing it is almost certainly meters). On this note, also be warned! Your quoted expectation of "-90 -> 90, -180 -> 180" is incorrect because the function returns X then Y (that is Longitude first and then Latitude) - you appear to be expecting Lat then Long (which would be Y,X). So, if you have used the value returned by the st_rastertoworldcoord in any georeferencing or affining calculation as Lat and Long (instead of Long and Lat), then your data will be misplaced.

This brings us to your second question. ST_RasterToWorldCoord gives you the location in realworld coordinates of the upper left corner of row/column combination you provide. So (1,1) will be the UL of the whole raster and (2,2) will be one pixel down and one across (whose location will depend on the raster resolution). See the converse function ST_WorldToRasterCoord which gives you the row/column within a raster based on real world coordinates.

6
  • Thank @Mappa, your answer helps me alot. I'm really sorry about wrong coordinate format. I really meant (Long,Lat) (-180->180, -90->90)
    – Jackie
    Commented Jan 24, 2014 at 2:36
  • In addition, do you know any way to check whether the raster overlap any polygon in table or not?
    – Jackie
    Commented Jan 24, 2014 at 3:19
  • You could try ST_Overlaps Commented Jan 24, 2014 at 8:54
  • I tried ST_Overlaps(geom, rast), it says the function doesn't exist. I tried ST_Overlaps(geom, ST_Polygon(rast)), it returns false in all rows
    – Jackie
    Commented Jan 24, 2014 at 9:08
  • What version of PostGIS are you using? Commented Jan 24, 2014 at 9:23

Your Answer

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

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