MapAlgebra on three Rasters

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

MapAlgebra on three Rasters

JamesH
Hi all,

I have three Raster's stored in seperate tables which I am looking to perform a weighted calculation on all three to produce a single Raster as an output (or a visualisation through OpenJump or Quantum).

The calculation I am attempting is basically:
(raster1 * 0.2) + (raster2 * 0.5) + (raster3 * 0.3)

I know MapAlgebra has a two Raster version, but is it possible to do this with three rasters?
All three rasters are single band.

An alternative I've considered is to perform the calculation on the first two rasters and then a second on the new and the third raster but to be able to do it one query would be ideal.

Kind Regards,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

JamesH
Currently, I am using:
CREATE TABLE map2 AS(
SELECT
        ST_MapAlgebraExpr(ST_MapAlgebraExpr(a.rast,1, '32BF', '((67.6499557495117-[rast])/67.6499557495117)'), 1, ST_MapAlgebraExpr(b.rast,1, '32BF', '((14052.134765265-[rast])/14052.134765265)'), 1, '([rast1] * 0.5) + ([rast2] * 0.3)::float', '32BF').*
FROM
        density a, euclidean b
        );

But its not exporting correctly, and using .* returns as a syntax error.
Can anyone show me where I'm going wrong with this?

Much Appreciated,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

Pierre Racine-2
In reply to this post by JamesH
Imbricate two calls to ST_MapAlgebraExpr()

Pierre

> -----Original Message-----
> From: [hidden email] [mailto:postgis-users-
> [hidden email]] On Behalf Of JamesH
> Sent: Wednesday, April 25, 2012 2:53 PM
> To: [hidden email]
> Subject: [postgis-users] MapAlgebra on three Rasters
>
> Hi all,
>
> I have three Raster's stored in seperate tables which I am looking to
> perform a weighted calculation on all three to produce a single Raster as an
> output (or a visualisation through OpenJump or Quantum).
>
> The calculation I am attempting is basically:
> (raster1 * 0.2) + (raster2 * 0.5) + (raster3 * 0.3)
>
> I know MapAlgebra has a two Raster version, but is it possible to do this
> with three rasters?
> All three rasters are single band.
>
> An alternative I've considered is to perform the calculation on the first
> two rasters and then a second on the new and the third raster but to be able
> to do it one query would be ideal.
>
> Kind Regards,
> James
>
> -----
> GIS Undergraduate
> --
> View this message in context: http://postgis.17.n6.nabble.com/MapAlgebra-on-
> three-Rasters-tp4917643p4917643.html
> Sent from the PostGIS - User mailing list archive at Nabble.com.
> _______________________________________________
> postgis-users mailing list
> [hidden email]
> http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

JamesH
Hi Pierre,

Currently I think I'm close to acheiving this.

Ran successfully this query in PostGIS:
SELECT
        ST_MapAlgebraExpr(ST_MapAlgebraExpr((ST_Slope(c.rast,1,'32BF')),1,'32BF','((244-[rast])/244)::float'),1, ST_MapAlgebraExpr(ST_MapAlgebraExpr(a.rast,1, '32BF', '((67.6499557495117-[rast])/67.6499557495117)'), 1, ST_MapAlgebraExpr(b.rast,1, '32BF', '((14052.134765265-[rast])/14052.134765265)'), 1, '([rast1] * 0.5) + ([rast2] * 0.3)::float', '32BF'),1, '([rast1] * 0.2 + [rast2])::float', '32BF')
FROM
        density a, euclidean b, example_postgis20 c

And I'm now trying to view in OpenJump using:
SELECT ST_AsBinary((gv).geom), (gv).val
FROM (SELECT ST_DumpAsPolygons(ST_MapAlgebraExpr(ST_MapAlgebraExpr((ST_Slope(c.rast,1,'32BF')),1,'32BF','((244-[rast])/244)::float'),1, ST_MapAlgebraExpr(ST_MapAlgebraExpr(a.rast,1, '32BF', '((67.6499557495117-[rast])/67.6499557495117)'), 1, ST_MapAlgebraExpr(b.rast,1, '32BF', '((14052.134765265-[rast])/14052.134765265)'), 1, '([rast1] * 0.5) + ([rast2] * 0.3)::float', '32BF'),1, '([rast1] * 0.2 + [rast2])::float', '32BF')) gv
FROM density a, euclidean b, example_postgis20 c) foo

Its returning as no geometry to it.
Can you see where I'm going wrong with this?
This is one of the last pieces in my dissertation.

Kind Regards,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

JamesH
Sorry, I should have explained what I'm trying to do with the query.

I'm taking the two rasters density and euclidean, normalising them both
before multiplying normalised density by 0.5, multiplying normalised euclidean by 0.3 and then adding these together.

Then I am producing a slope surface, normalising that
and then multiplying the normalised slope by 0.2
before using it along with the result of the first calculation to add effectively all three rasters together.

Hope this explains better.

Kind Regards,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

JamesH
I have refined my query so that I am using MapAlgebraExpr on the normalised distance and density rasters and exporting as a new table.
Then I am using a second, new MapAlgerbaExpr query with this table and the normalised slope surface.

However it is returning, 'The two rasters provided do not have the same alignment.  Returning NULL'. Looking at the documentation, I tried ST_Resample the slope raster before passing it to the MapAlgebraExpr, using the table from the first MapAlgebra as the Resample reference.

The query ran but this new Raster returned as empty. Can anyone explain why?

Current query is:
CREATE TABLE Metro_location AS(
SELECT
        ST_MapAlgebraExpr(ST_Resample(ST_MapAlgebraExpr((ST_Slope(a.rast,1,'32BF')),1,'32BF','((244-[rast])/244)'), b.rast), 1, b.rast, 1, '([rast1] * 0.2) + [rast2]', '32BF') as rast, 1 as rid
FROM
        Slope a, DensDist b
                );

Kind Regards,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

JamesH
Have resolved this MapAlgebra issue, the issue was with the slope surface, I was trying to produce as a 32BF but it needed to be 32BSI to be visible.

Calculation and resample ran effectively using:

CREATE TABLE Metro_location2 AS(
SELECT
        ST_MapAlgebraExpr(ST_Resample(a.rast, b.rast), 1, b.rast, 1, '([rast1] * 0.2) + [rast2]', '32BF') as rast, 1 as rid
FROM
        Slope a, DensDist b
                );

To produce this final Raster:


This is the product of three standardises/Normalised Rasters: a Slope surface, Point Density and Euclidean Distance.
Each was then weighted and combined together into one Raster showing the most suitable locations in Newcastle for a proposed new Metro Station (in red).

Kind Regards,
James
GIS Undergraduate
Reply | Threaded
Open this post in threaded view
|

Re: MapAlgebra on three Rasters

Pierre Racine-2
In reply to this post by JamesH
I would suggest you create intermediate tables with CREATE TABLE xxx AS and see the result of each operation one after the other in order to isolate the problem.

Pierre

> -----Original Message-----
> From: [hidden email] [mailto:postgis-users-
> [hidden email]] On Behalf Of JamesH
> Sent: Wednesday, April 25, 2012 7:34 PM
> To: [hidden email]
> Subject: Re: [postgis-users] MapAlgebra on three Rasters
>
> Sorry, I should have explained what I'm trying to do with the query.
>
> I'm taking the two rasters density and euclidean, normalising them both
> before multiplying normalised density by 0.5, multiplying normalised
> euclidean by 0.3 and then adding these together.
>
> Then I am producing a slope surface, normalising that
> and then multiplying the normalised slope by 0.2
> before using it along with the result of the first calculation to add
> effectively all three rasters together.
>
> Hope this explains better.
>
> Kind Regards,
> James
>
> -----
> GIS Undergraduate
> --
> View this message in context: http://postgis.17.n6.nabble.com/MapAlgebra-on-
> three-Rasters-tp4917643p4918408.html
> Sent from the PostGIS - User mailing list archive at Nabble.com.
> _______________________________________________
> postgis-users mailing list
> [hidden email]
> http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
[hidden email]
http://postgis.refractions.net/mailman/listinfo/postgis-users