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.

  • The second option would work if you attribute the polygons correctly - this should be done on the database. The use an SLD (Styled Layer Descriptor) like the example here - blog.geoserver.org/2010/04/09/sld-cookbook – Mapperz Sep 26 '12 at 13:36
  • the problem is, i don't have write access to db. so i cant add a new attribute for product types to table. actually there are lots of attributes that i gather dynamically which aren't on original table. so creating a new column for each of them is not an option i guess. is there a dynamic way? or if this is not possible, do i need to use external libraries for this operation? like sharpmap or etc? – bahadir Sep 26 '12 at 13:40
  • have a staging table that you do have read/write access. If not create your own databae (postgis/postgres recommended) then you have control. – Mapperz Sep 26 '12 at 13:43

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/

  • thanks, and for my first question i figured out acid maps plugin for geoserver, do you have any experiences about that plugin? – bahadir Oct 2 '12 at 10:54
  • unfortunately no, but it does say "you can use a WMS points layer to generate an AMS map". This says to me that not only do you need to install a plugin on GeoServer, but also GeoServer needs access to your points data to provide it as a layer. From your question I assumed you have no ability to alter the GeoServer configuration. – tomfumb Oct 2 '12 at 16:53
  • actually, i don't have access to underlaying database. i can alter geoserver configuration. But even with acid maps, i guess i need to add a table to db for points data. no dynamic way yet – bahadir Oct 3 '12 at 7:06
  • you do have another option but it might not be easy - if you can configure GeoServer that means you can create a new store that reads from WFS. Again this requires that GeoServer has HTTP access to your web service, but you could then serve up your own WFS representing your data points. Depending on the number of points that have to be transferred this could be quite slow. Also if you don't have a map server on your side this could mean manually coding GML responses which isn't pleasant. – tomfumb Oct 3 '12 at 16:20
  • and what if i can access database, do i need to collect data from web services, insert into db, and make geoserver draw newly inserted data from database? – bahadir Oct 4 '12 at 7:27

The short answer is - yes, its very much possible! There are actually a variety of ways you could tackle this problem. Here is one such way I can think of.

There are 2 parts to your question here.

1) Represent Static AND Dynamic data coming from external sources in GeoServer.

Create a layer group say "Regional Map" with 2 layers. Layer 1 (Static) is the "Regional Map - served from your read-only Database or Shapefile Layer 2 (Dynamic) is the "Weather" - which can be serve dynamic data through WMS cascading. The WMS cascade URL could actually be looped back to your GeoServer, and you can serve temperature or other dynamic attributes by calling remote services using whatever protocol you use - REST, SOAP, TCP etc.

This way you can add attributes to the layers dynamically in the future without adding stuff to DB.

2) Perform custom styling ** Your best bet here is to use **Style Layer Descriptor (SLD). There are a lot of documentation on how to style using SLD. Its very powerful! You can control styling using colors, zoom-levels, value thresholds (>40C is red, >35 is orange) and have rules based on values from multiple attributes and labels. Styling is available for most geometries - point, line, area etc. You can use style editors like Atlas, or the editor that comes with OpenGeo - GeoExplorer, to test various data conditions.

The beauty with this approach is that you can control styling of Layer1 and Layer2 independent of each other. You can do legends in your UI (JavaScript), outside GeoServer. GeoServer will merge all the styling rules to produce the correct overlay. Depending on the performance that you get from your layer and Styling you could also consider adding a tile caching solution like GeoWebCache or HTTP Cache like Varnish.



  • thanks, but i don't have chance to create new tables or layers in geoserver. – bahadir Oct 2 '12 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.