[postgis-users] Contours of rasters without or with tiles
hugues.francois at irstea.fr
Mon Nov 26 22:43:20 PST 2012
There's no mess ! You used my firstname correctly and I thank you for that.
To (try to) answer your questions :
1. I would have use st_envelope to see what was the result and if the problem would comes from no data values. St_envelope will also give you one polygon by tile and the result will be totally different if you use it with a tiled or non tiled raster.
2. As st_envelope, I think the correct behaviour of st_polygon is to proceed tile by tile if you tiled your raster (a tile by row = a polygon by row).
2 rue de la papeterie
38400 Saint-Martin d'Hères
tel : +33 (0)126.96.36.199.44
port : +33 (0)188.8.131.52.31
fax : +33 (0)184.108.40.206.03
De : Mathieu Basille [mailto:basille at ase-research.org]
Envoyé : mardi 27 novembre 2012 00:14
À : Francois Hugues
Objet : Re: [postgis-users] Contours of rasters without or with tiles
[sorry for the mess, I mixed up your first and last name, and forgot to CC you... I think it's time to get back home]
Thank you for your answer. Answers below, in your mesage:
Le 26/11/2012 12:02, Francois Hugues a écrit :
> 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;
SELECT ST_Polygon(rast) FROM test.raster_tile;
SELECT ST_Union(ST_Polygon(rast)) FROM test.raster_tile;
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
> -----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 givenraster. 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 aworkaround to this problem?
> Thanks in advance for any hint!
> # SELECT 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
Mathieu Basille, PhD
~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
-- Paul Éluard
postgis-users mailing list
postgis-users at lists.osgeo.org
More information about the postgis-users