[Mapserver-dev] Raster Queries

Frank Warmerdam warmerdam at pobox.com
Fri Mar 19 13:09:58 EST 2004


Woot!

I can now do some very simple raster queries.  The following simple
query script executes properly against a raster layer.

#!/usr/bin/env python

import mapscript
import sys

map = mapscript.Map('rquery.map')
layer = map.getLayer(0)

rect = mapscript.Rect()
rect.minx = 440720
rect.maxx = 440780
rect.miny = 3751260
rect.maxy = 3751320

layer.queryByRect( map, rect )

layer.open()
for i in range(1000):
     result = layer.getResult( i )
     if result is None:
         break

     print '(%d,%d,%s)' % (result.shapeindex, result.tileindex,result.classindex)

     s = layer.getShape( result.shapeindex, result.tileindex )
     print s
     for i in range(layer.numitems):
         print '%s: %s' % (layer.getItem(i), s.getValue(i))

layer.close()

map = None
mapscript.msCleanup()

And reports the following for the small 2x2 query rectangle:
(0,0,)
<C shapeObj instance at _808d1808_p_shapeObj>
x: 440720
y: 3751320
value: 107
(1,0,)
<C shapeObj instance at _b8231908_p_shapeObj>
x: 440780
y: 3751320
value: 123
(2,0,)
<C shapeObj instance at _808d1808_p_shapeObj>
x: 440720
y: 3751260
value: 115
(3,0,)
<C shapeObj instance at _f0961a08_p_shapeObj>
x: 440780
y: 3751260
value: 132

As you can see, I have taken the approach of turning raster query results
into internal data arrays that can then be access normally via the opening
the layer and reading the shapes.  I haven't tested it yet, but the query
template engine should work without any special knowledge about rasters.

I haven't yet added red, green, blue and class into the query results.  Does
it make more sense to return the class number or the class name in the query
results?

I also haven't gotten the histogramming support working yet or some of the
query types (at a point, within a polygon, etc). However, I felt the need to
good a Woot somewhere for my breakthrough.  The problem with working in my
basement is it is hard to impress the cat when I get something working. :-)

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the mapserver-dev mailing list