Hi,
After this discussion ( http://osgeo-org.1560.x6.nabble.com/Storing-styiling-properties-as-a-JSON-map-td5073329.html) on GeoServer users list (if you think this is a useful add) I would like to contribute the mapper function to GeoServer.
As already discussed, the goal of mapper function will be allowing the access of styling properties stored in a Map encoded as a JSON object. With this approach we can store all our styling properties in a single column (Feature property). Since their are not explicitly declared, the number and the type of styling properties is variable. The JSON object can be easily used in all architecture layers (javascript, java, scala, ruby, …).
As an example, lets consider this normal style:
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>
<ogc:PropertyName>MARK</ogc:PropertyName>
</WellKnownName>
<Fill>
<CssParameter name=“fill”>
<ogc:PropertyName>COLOR</ogc:PropertyName>
</CssParameter>
</Fill>
</Mark>
<Size>
<ogc:PropertyName>SIZE</ogc:PropertyName>
</Size>
</Graphic>
</PointSymbolizer>
Our Feature will need to have explicitly declared the properties “WELL_KNOWN_NAME”, “COLOR” and “ELEMENT_SIZE”.
Using the mapper function the style above will become:
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>
<ogc:Function name=“mapper”>
<ogc:PropertyName>JSON_STYLE</ogc:PropertyName>
<ogc:Literal>mark</ogc:Literal>
</ogc:Function>
</WellKnownName>
<Fill>
<CssParameter name=“fill”>
<ogc:Function name=“mapper”>
<ogc:PropertyName>JSON_STYLE</ogc:PropertyName>
<ogc:Literal>color</ogc:Literal>
</ogc:Function>
</CssParameter>
</Fill>
</Mark>
<Size>
<ogc:Function name=“mapper”>
<ogc:PropertyName>JSON_STYLE</ogc:PropertyName>
<ogc:Literal>size</ogc:Literal>
</ogc:Function>
</Size>
</Graphic>
</PointSymbolizer>
The Feature property “JSON_STYLE” will contain all JSON styling properties and could look like this:
‘{“color”:“##081931”,“size”:10,“mark”:“square”,“label”:“simple point”}’
I have done a quick benchmarking (in attach) and there is no performance cost in having the style stored in a JSON object. However, if the JSON object is not a Feature property, i.e. if it is obtained in a static context (literal, env function , …) we cannot cache its value. Since the object is not associated with any feature the cost of putting the deserialized object in cache (i.e. using the object himself to produce a hascode) is more costly that just parsing the object. But (at the moment) I don’t see any use case where the JSON object isn’t associated with any Feature. Anyway the cost of parsing the object is not so high we are talking about more ~150ms for 10000 point with three styling properties.
I have been out of GeoServer Dev for some time, but we already sign the contributing agreement for contributing W3DS module.
Currently we are using this function as a GeoServer extension (plugin).
Best regards,
Nuno Oliveira
(attachments)
MapperFunctionBenchMarking.pdf (38.6 KB)