I am trying to return the results of queryByShape call from a (large) raster file given a user specified polygon.
For example, when a user plots the following polygon on an openlayers layer as shown in this diagram, I send the coordinates of the polygon vertices to the python mapscript backend.
With python mapscript, I re-create the polygon as a mapscript shapeObj.
line = mapscript.lineObj()
line.add( mapscript.pointObj( 16.484375, 59.736328125 ) )
line.add( mapscript.pointObj( 17.4951171875, 55.1220703125 ) )
line.add( mapscript.pointObj( 24.74609375, 55.0341796875) )
line.add( mapscript.pointObj( 22.5927734375, 61.142578125) )
line.add( mapscript.pointObj( 16.484375, 59.736328125) )
poly = mapscript.shapeObj( mapscript.MS_SHAPE_POLYGON )
poly.add( line )
Then, I experiment with the queryByShape call like this:
mapfile = '/path/to/my/mapfile.map'
mymap = mapscript.mapObj( mapfile )
layer = mymap.getLayer(0)
layer.queryByShape( mymap, poly )
The returned result is an integer "1", which isn't what I was expecting.
Unfortunately, there isn't much by way of documentation for queryByShape so I am not sure what I am doing wrongly (http://mapserver.org/mapscript/querying.html#by-shape)
How does mapscript queryByShape work? I am actually trying to return a shape object where I can extract information about the selected shape (polygon defined by user) and determine
- The total area of this shape,
- The % in this shape which is of a specific RGB ("blue") value,
- The % in this shape which is of a specific RGB ("green") value etc.
Here's the LAYER definition in my mapfile.
LAYER
NAME 'GLOBCOVER_L4_200901_200912_V2.3.color'
TYPE RASTER
DUMP true
TEMPLATE 'fooOnlyForWMSGetFeatureInfo'
EXTENT -189.001389 -115.106069 188.998611 140.108847
DATA '/media/GLOBCOVER_L4_200901_200912_V2.3.color.tif'
METADATA
'ows_title' 'GLOBCOVER_L4_200901_200912_V2.3.color'
END
STATUS OFF
TRANSPARENCY 100
PROJECTION
'proj=longlat'
'ellps=WGS84'
'towgs84=0,0,0,0,0,0,0'
'no_defs'
END
END