[mapserver-dev] Questions on MapServer architecture and attribute conversions

Even Rouault even.rouault at spatialys.com
Thu Mar 14 09:38:54 PDT 2019


Seth,

> 
> I've created a pull request to add a __geo_interface__ to the Python
> MapScript PointObj, LineObj, and ShapeObjs. This allows Python scripts to
> easily share MapScript objects with other Python geospatial libraries such
> as Shapely, QGIS, and ArcPy. It also completes a nice cycle as Sean Gillies
> was a core developer of the MapScript Python bindings and created
> __geo_interface__.  This only affects the Python MapScript bindings - do I
> need to create a RFC or ask for a vote to merge this for a 7.4 release?
> 
> I also have a few questions on the internal architecture of MapServer
> classes. Could other devs confirm (or correct) the following assumptions?
> 
> - the shapeObj has no link back to a layerObj - they are completely
> independent with no way to get a reference to a layer from a shape - all
> shapeObj attribute values are stored internally as strings

Yes that's my understanding too.

> 
> To get attribute names for a shapeObj I had to get retrieve them  from the
> relevant layerObj and store these in a new property on the shapeObj in
> Python MapScript. I can then output something like the following:
> 
>     "properties": {
>         "guid": "954BADBF-2891-48ED-A132-AED39C60E4C9",
>         "featureid": "203529",
>         "classid": "12"
>     }
> 
> It would be nice to be able to convert the property values to their relevant
> types e.g. integers and floats. Looking through the MapServer source they
> seem to only be converted to types using METADATA blocks and
> "gml_FIELD_NAME_type" "datatype" and in certain cases e.g. in
> mapogroutput.c Are these conversions all handled differently for different
> data inputs? Is there an easy way to reuse these conversions in MapScript?

Yes this lack of proper typing on layer attributes is a bit inconvenient and 
causes lot of adhoc coding in various areas of the code base: ogroutput, OGC 
filtering, WFS, GML output, MVT output, etc.
The fundamental issue is that layerObj::items is just an array of field names.

For brainstorming... A potential solution could take inspiration from what is 
done in GDAL where:
OGRLayer (~ equivalent of layerObj) -> contains a OGRFeatureDefn
OGRFeature (~ equivalent of shapeObj) -> points to a OGRFeatureDefn, and has 
an array of field values

A OGRFeatureDefn contains (among other things) an array of OGRFieldDefn
A OGRFieldDefn is a set of attribute: field name, field type, etc...

Or if not doing a majorhaul, have indeed a pointer from shapeObj back to 
layerObj (which interesting lifetime consideration, but I'm not sure MapScript 
really shines on maintaining object ownership), and use information returned 
by msGMLGetItems().


Even


-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the mapserver-dev mailing list