[postgis-devel] Regular expressions in PostGIS sources

Paul Ramsey pramsey at opengeo.org
Mon Nov 15 15:17:55 PST 2010


OK, that's what I thought / remembered-from-foss4g.
So expressions like this:

 'rast + 20'
 'rast / 2',
 'cos(rast)'
 '2*rast + 3/rast'
 '5'

As arguments to an ST_MapAlgebra function.

I have to admit that, given what I've been working on recently, I
would be tempted to suggest a simple flex/bison grammar. But since I
have invested the days necessary to understand WTF flex/bison are
doing that feels like a smaller investment to me than it perhaps is
for you. It would, however, allow you to get things like '2 *
(cos(rast)/(4-rast))' "for free" without writing a bunch of your own
stack management code.

(is there anything special about the 'rast' keyword in there? what
happens when you want to do MapAlgebra on two things at once? eg
'2*rast1 + 4*rast2')

Wait, backing up you say "The expression is any PostgreSQL valid
expression returning a number. This expression can contain conditional
expressions like CASE or any user-defined function." Do you have a
feel for how you are going to evaluate this stuff? Presumably with
hooks into the PostgreSQL backend, where the functions are actually
defined? Do you truly plan on handling every single function defined
in PostgreSQL or what? Is that a strict requirement or can you just
define a subset and handle them in your grammar (ala Mapserver
EXPRESSION syntax or CQL?)

How much scope are you biting off here? Maybe you have a magic easy
approach to this that I'm not seeing.

Paul

2010/11/15 Jorge Arévalo <jorge.arevalo at deimos-space.com>:
> On Mon, Nov 15, 2010 at 9:40 PM, Paul Ramsey <pramsey at opengeo.org> wrote:
>> Could you give me some richer examples of the syntax in the form of
>> full SQL statements?
>>
>
> Yes, of course. From current documentation: "The expression is any
> PostgreSQL valid expression returning a number. This expression can
> contain conditional expressions like CASE or any user-defined
> function. In the one raster version of ST_MapAlgebra, the value of the
> current pixel is expressed in the expression by "rast". E.g.
> 'cos(rast)' or 'rast / 2'"
>
> The calls to the MapAlgebra function will follow the syntax:
>
> ST_MapAlgebra(rast raster, band integer, expression text,
> nodatavalueexpr text, pixeltype text)
>
> And the expressions will be something like 'rast + 20', 'rast / 2',
> 'cos(rast)', '2*rast + 3/rast', '5', etc. Then, each pixel of the
> raster must be used in that operation, by replacing the word 'rast'
> for its value, and storing the resulting pixel value in the output
> raster. It's a basic MapAlgebra implementation, with only one raster,
> by now.
>
> You have a PL/pgSQL implementation at
> http://svn.osgeo.org/postgis/trunk/raster/scripts/plpgsql/st_mapalgebra.sql
>
> But we're working on a C implementation
>
>> 2010/11/15 Jorge Arévalo <jorge.arevalo at deimos-space.com>:
>>> On Mon, Nov 15, 2010 at 7:19 PM, Paul Ramsey <pramsey at opengeo.org> wrote:
>>>> There's some regex support in postgresql core. What do you need regex
>>>> for in raster?
>>>>
>>>> P
>>>
>>> Hi Paul,
>>>
>>> For MapAlgebra implementation at core level. The ST_MapAlgebra
>>> Pl/pgSQL function takes an input argument like "SELECT rast + 3",
>>> meaning "add 3 to all raster's pixels", and it calls a  core function
>>> (via postgresql function) to perform the operation.
>>>
>>> Should I parse the expression in PL/pgSQL function, at postgresql
>>> level or at core level? Now, I'm working only at core level.
>>>
>>> Thanks!
>>>
>>> --
>>> Jorge Arévalo
>>> Internet & Mobilty Division, DEIMOS
>>> jorge.arevalo at deimos-space.com
>>> http://mobility.grupodeimos.com/
>>> http://gis4free.wordpress.com
>>>
>>>
>>>>
>>>> 2010/11/15 Jorge Arévalo <jorge.arevalo at deimos-space.com>:
>>>>> Hi all,
>>>>>
>>>>> Is there any mechanism in PostGIS to deal with regular expressions and
>>>>> string replacement at core level (I mean, C functions)? I'm going to
>>>>> use string replacement in PostGIS Raster but I don't want to reinvent
>>>>> the wheel, if is invented
>>>>>
>>>>> Many thanks in advance,
>>>>>
>>>>> --
>>>>> Jorge Arévalo
>>>>> Internet & Mobilty Division, DEIMOS
>>>>> jorge.arevalo at deimos-space.com
>>>>> http://mobility.grupodeimos.com/
>>>>> http://gis4free.wordpress.com
>>>>> _______________________________________________
>>>>> postgis-devel mailing list
>>>>> postgis-devel at postgis.refractions.net
>>>>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>>>>>
>>>> _______________________________________________
>>>> postgis-devel mailing list
>>>> postgis-devel at postgis.refractions.net
>>>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>>>>
>>> _______________________________________________
>>> postgis-devel mailing list
>>> postgis-devel at postgis.refractions.net
>>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>>>
>> _______________________________________________
>> postgis-devel mailing list
>> postgis-devel at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>>
>
>
>
> --
> Jorge Arévalo
> Internet & Mobilty Division, DEIMOS
> jorge.arevalo at deimos-space.com
> http://mobility.grupodeimos.com/
> http://gis4free.wordpress.com
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-devel
>



More information about the postgis-devel mailing list