[mapserver-users] Apply style to geojson based on property in geojson data

Tuffa chris at wherryengineering.co.uk
Wed Oct 25 01:08:20 PDT 2017


Hello Richard!

> I haven't used geojson as a data source, but maybe if you shared a small
> example of your map file and the data it would help.

Here's some more information....

mapfile.map (excerpt):

  LAYER
    NAME "countries"
    STATUS OFF
    TYPE POLYGON
    CONNECTIONTYPE OGR
    CONNECTION "africa.geojson"
    DATA "select * from africa"  
    CLASS STYLE OUTLINECOLOR "#ff0000" END END
    CLASS EXPRESSION ([value] >= 0 AND [value] <= 1000000) STYLE COLOR
"#FFE397" END END
  END

I have tried numerous types of select statement in the DATA definition, but
have failed to influence the styling based on the ‘value’ property added to
the geojson file.  Of course, this may have all been in vain, if the GDAL
driver does not support anything other than ‘select * from <layer>’, but I
cannot tell from the documentation - MapServer, or GDAL - what is allowed.

Here is an excerpt of the africa.geojson file, with the additional property
‘value’ added.  Following is the output from ogrinfo.

{
    "features": [
        {
            "geometry": {
                "coordinates": [
                    [
                        [
                            [
                                8.621624,
                                36.941797
                            ],
                            [
                                8.621624,
                                36.941797
                            ]
                        ]
                    ]
                ],
                "type": "MultiPolygon"
            },
            "properties": {
                "cartodb_id": 1,
                "created_at": "2013-11-12T16:15:59+0100",
                "name": "Algeria",
                "updated_at": "2013-11-12T16:15:59+0100",
                "value": 10000          <<<<<<<<<<<<<<<<<<<<<<<<<<<< custom
property
            },
            "type": "Feature"
        }
    ],
    "type": "FeatureCollection"
}


chris:tmp chris$ ogrinfo -summary -al africa.geojson 
INFO: Open of `africa.geojson'
      using driver `GeoJSON' successful.

Layer name: africa
Geometry: Multi Polygon
Feature Count: 1
Extent: (8.621624, 36.941797) - (8.621624, 36.941797)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
value: Integer (0.0)          <<<<<<<<<<<<<<<<<<<<<<<< here’s the additional
property
cartodb_id: Integer (0.0)
created_at: DateTime (0.0)
name: String (0.0)
updated_at: DateTime (0.0)


I haven't used geojson as a data source, but maybe if you shared a small
example of your map file and the data it would help.




--
Sent from: http://osgeo-org.1560.x6.nabble.com/Mapserver-User-f4226646.html


More information about the mapserver-users mailing list