0

I have a set of raster coverages. Some of them are really far from each other. When I use ST_Union function to union them, the function fill the area between them. I explain it in a simple example: I have a grid of polygons and select 2 of them (by their id) that are not neighbours.

enter image description here

Now, I have two different polygons in a table. Then, I used ST_AsRaster() to make two rasters out of the two polygons. At the end I used ST_Union() to make a union of those rasters.

select * 
INTO test1
from grid
where id= 277765 or id = 277762;

select st_asraster(tile_border,100,100, '8BSI'::text, 0, -1) as rast
into test1_rast_1
from test1 ;

select ST_Union(rast)
into test1_rast_1_union
from test1_rast_1;

I want the area between to be no-value but the ST_union fills it with 0. The created raster is as follows:

enter image description here

My real data consists of the raster coverages that are really far from each other and I have many layers that I want to union them. How can I use ST_Union in a way that it does not fill the area between the two geometries? because I think filling it for each iteration takes a long long time.

1

I found the answer. I just made 3 changes to the previous code:

  • I changed the pixel type from '8BSI' to '8BUI'
  • I changed the initial pixel values from 0 to 1
  • I changed the no-data value from -1 to 0

As you see only 3 parameters of the ST_AsRaster() are changed.

Now, the code results in a raster as follows:

enter image description here

As you see the area between the two rasters is not part of the final coverage. The code I used is:

select * 
INTO test1
from grid
where id= 277765 or id = 277762;

select st_asraster(tile_border, 100, 100, '8BUI'::text, 1, 0) as rast
into test1_rast_1
from test1 ;

select ST_Union(rast)
into test1_rast_1_union
from test1_rast_1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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