[postgis-devel] Regular expressions in PostGIS sources

Jorge Arévalo jorge.arevalo at deimos-space.com
Tue Nov 16 03:51:56 PST 2010


On Tue, Nov 16, 2010 at 12:17 AM, Paul Ramsey <pramsey at opengeo.org> wrote:
> 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.
>

Yes, I was thinking exactly in flex/bison, I used them some years ago,
and I'll need to refresh my memory. I had a look at wkt_parse.* files,
but I'm not sure it's a good starting point.


> (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')
>

No, it's only an easy way of naming raster objects in database, for
the user. Actually, the 2-raster version of MapAlgebra will use
'rast1', 'rast2' keywords.


> 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
>

Well, I have the same doubt. I'm not sure how far Pierre wants to go.
I think we should allow mathematical functions and boolean and
relational operations with rasters. Something similar to ArcGIS raster
calculator http://www.esri.com/software/arcgis/extensions/spatialanalyst/graphics/features/map_algebra-lg.jpg

The specs, IMHO, are referred to a pure PL/pgSQL implementation of
MapAlgebra, with the SQL executor behind, that allows evaluating user
defined functions over raster fields, and whatever. I hadn't time to
discuss this topic with Pierre.

My bet, after reading, thinking and your answers, is to implement a
simple grammar, like you suggested. Allow mathematical operations and
logical and comparison operators. Looks fine? Too difficult maybe?

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>:
>> 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
>>
> _______________________________________________
> 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