Friday 17 July 2015

wms - Can I do custom styling on GeoServer


I want to use GeoServer WMS server for custom styling. Let's say I have an area as polygon in a shapefile, but I don't have this area's temperature as an attribute. From a web service I gather temperature points inside that area. Now I want GeoServer to color this area according to these dynamic temperature points.


Here is an example:


Temperature Map


If it is possible, I even want to place these borders on image and some explanations about colors on right side. How can I send these temperature points to a GeoServer WMS. And can I do some custom coloring according to these dynamic parameters?


I don't know how to convert these point data to area colors.


My next question is similar but without points, can I colorize a polygon with dynamic attributes which isn't on the shapefile.


Here is an example I want to colorize these polygons according to their product type, but as earlier question, these product types are gathered dynamically.


enter image description here



I hope these are possible.



Answer



On your second question:


An SLD can be created dynamically, which means it can style maps using dynamic data. For this to work you will need to know the IDs of the polygons you're trying to style and you also need to alter / expand your web service.


Have your web service generate SLDs on-the-fly instead of just returning data. This is simple enough using .NET, Java, PHP etc. The SLD you generate will have a rule for each colour band you want to display. Each rule will identify the polygons that colour applies to by their ID. Each rule's filter block will contain PropertyIsEqualTo 1 OR PropertyIsEqualTo 2 OR .... Each rule styles its polygons with whichever colour you have chosen to represent the value. You then have two options for telling GeoServer to use your dynamic SLD.



  1. If GeoServer has HTTP access to your web service you can pass an encoded URL, for example (JS) 'http://geoserver/wms?request=GetMap...&sld=' + encodeURIComponent('http://web-service/generateSLD?and=any-parameters-that-influence-sld-generation'). When GeoServer gets the WMS request it will decode the parameters and query this URL for the SLD. From GeoServer's perspective this is no different to querying for a static SLD held on a file server.

  2. If GeoServer can't access your web service your client must first ask the web service for the dynamic SLD, then pass the SLD to GeoServer in the sld_body parameter of the WMS request. Beware any limits on URL length imposed by either your client (e.g. a browser) or your web server


Both approaches can be tested using a static SLD you create for testing, so you know how successful this is before putting in the effort on your web service. Both approaches could be used to ask GeoServer for the legend graphic, which will then represent the same rules (however if you use option 1 it's possible the data used to generate your SLD has changed after generating the map).



I think this is your best option for question 2.


On your first question:


Do the temperature points always represent the same locations? If yes, can you find out in advance which polygons those temperature points fall within? If yes you can simply re-use the approach outlined above, with your SLD-generation script translating points into polygon IDs.


EDIT I just saw this referenced in another question: http://pypi.python.org/pypi/python-sld/


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...