[postgis-users] Contours of rasters without or with tiles

Mathieu Basille basille at ase-research.org
Mon Nov 26 15:10:36 PST 2012


Dear François,

Thank you for your answer. Answers below, in your mesage:

Le 26/11/2012 12:02, Francois Hugues a écrit :
> Hello,
>
> Did you try with the bounding boxes of your tiles using st_envelope ? I operated numerous tiles and unioned them with this function.

I'm not quite sure to understand your suggestion. I don't see how bounding 
boxes could be useful for my problem: What I would like to get is the 
polygon surrounding not null pixels of the raster, not bounding boxes of 
the tiles. Could you elaborate here please?

> Your picture does not show us how many lines your last query returns. Here, it could be a multipolygon.

Here are the results for the three commands:

SELECT ST_Polygon(rast) FROM test.raster;
1 line

SELECT ST_Polygon(rast) FROM test.raster_tile;
9 lines

SELECT ST_Union(ST_Polygon(rast)) FROM test.raster_tile;
1 line

Indeed, the last one seems to be a multipolygon. I admit that I'm 
completely sure about the consequences of that, and how I could solve it. 
But I see what you mean. From what I understand, ST_Union is unable to 
correctly 'merge' all the polygons of the main land, but only three of 
them, but correctly 'union' them. My assumption that ST_Union was wrong was 
then maybe misleading.

But the bottom line is that I get different results from tiled and not 
tiled rasters, which should not happen IMHO (or I'm just misunderstanding 
the rationale of using tiles). I just used ST_Union as an attempt to solve 
the behaviour of ST_Polygon, which gives different results on tiled and not 
tiled rasters. In my example, I think ST_Polygon should return one line in 
both cases with the same output (here a multipolygon with three polygons 
for the 2 islands and the main land).
My question ("Is this an expected behaviour?") should thus rather apply to 
ST_Polygon.

Mathieu.


> Hugues.
>
>
>
> -----Message d'origine-----
> De : postgis-users-bounces at lists.osgeo.org [mailto:postgis-users-bounces at lists.osgeo.org] De la part de Mathieu Basille
> Envoyé : vendredi 23 novembre 2012 21:53
> À : PostGIS-users
> Objet : [postgis-users] Contours of rasters without or with tiles
>
> Dear PostGIS users,
>
> Here is a simple case: I'd like to extract the contour polygon of a given raster. The dedicated function should be ST_Polygon. If I run it on the raster imported without tiles, I get one polygon per island/continent, which is exactly what I want. However, if the raster uses tiles, I get one polygon per island/continent for each tile (which makes sense). I could merge them using ST_Union, but I was unable to do that completely: some polygons do get merged, but not all. This can be fairly problematic in my case, since I'm using buffers of the resulting polygon, which means I need one polygon per island/continent.
>
> Example case, with the simple raster attached:
>
> Importation without tiles:
>
> raster2pgsql -s 4326 -I -C -M raster.tif test.raster | psql -h localhost -d database -U pguser
>
> Importation with tiles:
>
> raster2pgsql -s 4326 -t 5x5 -I -C -M raster.tif test.raster_tile | psql -h localhost -d database -U pguser
>
> Using ST_Polygon:
>
> CREATE TABLE test.pol AS
> SELECT ST_Polygon(rast) FROM test.raster;
>
> CREATE TABLE test.pol_t AS
> SELECT ST_Polygon(rast) FROM test.raster_tile;
>
> Using ST_Union on the result:
>
> CREATE TABLE test.pol_tu AS
> SELECT ST_Union(ST_Polygon(rast)) FROM test.raster_tile;
>
> See the picture attached to see the result. 'pol' and 'pol_t' give the expected results, but not 'pol_tu'. Is this an expected behaviour? Is there a workaround to this problem?
>
> Thanks in advance for any hint!
> Mathieu.
>
>
> # SELECT PostGIS_Full_Version();
>
>       postgis_full_version
>
> -----------------------------------------------------------------------
>    POSTGIS="2.1.0SVN r10597" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 2.0dev, released 2011/12/29" LIBXML="2.8.0"
> LIBJSON="UNKNOWN" TOPOLOGY RASTER
>
>

-- 

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard


More information about the postgis-users mailing list