GeoServer Blog

Dynamic Symbolizers (Part 1)

When GeoServer 1.7.0 was released in October of 2008, it included some new features that many people might find useful.  One of those new features is support for dynamic symbolizers.

Dynamic symbolizers, which originated from a GeoTools styling subsystem improvement from this past summer, allows you to do three things:

  • Create external references that contain feature attributes as variables__

  • Use decorative true type fonts as markers in your map

  • Program your own dynamic symbolizer to extend existing ones, with full access to all of the current feature attributes

In this post we’ll cover the first item, and in the next post we’ll consider the other two.

**Dynamic Symbolizers With External References **

Say you want to make a map of the USA that shows each state’s flag superimposed on the state.  (You can use the topp:states layer, which comes standard with GeoServer.)  With the old symbolizer approach, you would have to do two things:

  • Find all the flags as images, possibly as small PNG/GIF images.

  • Write a different rule for each state, connecting each state with its respective flag.

Now, having to find the flags is a challenge, but it can be done.   This site, for example, has small flag graphics in JPEG format. The really time-consuming part is writing 50 different rules, each matching a state with its flag.

If we look closely at the image names, we can see a pattern.  The file names are all of the form:

tn_.jpg

And we happen to have the same state abbreviations in the STATE_ABBR attribute. Wouldn’t it be great if we could just link the attribute to the external graphics link?

With dynamic symbolizers, this can be done. You can embed CQL (Common Query Language) expressions inside a external graphics link or inside a well-known mark name, and have the expression be expanded dynamically.  To embed a CQL expression, all you have to do is to type it between the brackets in this form:  ${ }.

Let’s apply this to our case. The external graphics link might originally look like:

> > > > image/gif > > >

Note the file name:  tn_${STATE_ABBR}.jpg.  For each feature, the attribute name will be expanded, generating a different link for every feature. Unfortunately, that’s still not good enough, because the abbreviations are upper case, and the site links are case-sensitive and require lower case names. However, as we mentioned above, you can leverage the full power of CQL expressions in the dynamic symbolizer elements.  In this case, we can use the strToLowerCase function to change the values of our attributes to lower case.  With that, we have an instant flag map.

Sample USA states maps with flags

Here is the full SLD to generate this at home.

<span class="cp"><?xml version="1.0" encoding="ISO-8859-1"?></span>
<span class="nt"><StyledLayerDescriptor</span> <span class="na">version=</span><span class="s">"1.0.0"</span>
  <span class="na">xmlns=</span><span class="s">"http://www.opengis.net/sld"</span>
  <span class="na">xmlns:ogc=</span><span class="s">"http://www.opengis.net/ogc"</span>
  <span class="na">xmlns:xlink=</span><span class="s">"http://www.w3.org/1999/xlink"</span>
  <span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span>
  <span class="na">xsi:schemaLocation=</span><span class="s">"http://www.opengis.net/sld</span>
<span class="s">                      http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"</span><span class="nt">></span>
  <span class="nt"><NamedLayer></span>
    <span class="nt"><Name></span>Default Polygon<span class="nt"></Name></span>
    <span class="nt"><UserStyle></span>
      <span class="nt"><Title></span>Flags of USA<span class="nt"></Title></span>
      <span class="nt"><FeatureTypeStyle></span>
        <span class="nt"><Rule></span>
          <span class="nt"><Name></span>Solid black outline<span class="nt"></Name></span>
          <span class="nt"><LineSymbolizer></span>
            <span class="nt"><Stroke/></span>
          <span class="nt"></LineSymbolizer></span>
        <span class="nt"></Rule></span>
      <span class="nt"></FeatureTypeStyle></span>
      <span class="nt"><FeatureTypeStyle></span>
        <span class="nt"><Rule></span>
          <span class="nt"><Name></span>Flags<span class="nt"></Name></span>
          <span class="nt"><Title></span>USA state flags<span class="nt"></Title></span>
          <span class="nt"><PointSymbolizer></span>
            <span class="nt"><Graphic></span>
              <span class="nt"><ExternalGraphic></span>
                <span class="nt"><OnlineResource</span> <span class="na">xlink:type=</span><span class="s">"simple"</span>
                  <span class="na">xlink:href=</span><span class="s">"http://www.usautoparts.net/bmw/images/states/tn_${strToLowerCase(STATE_ABBR)}.jpg"</span> <span class="nt">/></span>
                <span class="nt"><Format></span>image/gif<span class="nt"></Format></span>
              <span class="nt"></ExternalGraphic></span>
            <span class="nt"></Graphic></span>
          <span class="nt"></PointSymbolizer></span>
        <span class="nt"></Rule></span>
      <span class="nt"></FeatureTypeStyle></span>
    <span class="nt"></UserStyle></span>
  <span class="nt"></NamedLayer></span>
<span class="nt"></StyledLayerDescriptor></span>
Read More

Raster Symbolizer tricks - part 1

I am going to bother for a few mins in order to show a few things about the raster symbolizer implementation that has landed on 1.7. Ideally this should the first of a series of more posts, but I can’t guarantee on that :-).

Anyway, today I have been playing with some bathymetry data for the geoSDI project. I cannot share them since it is classified data but I have been told that I can show some snapshots :-).

Here below you have the gdalinfo on one of the datasets:

Driver: GTiff/GeoTIFF Files: DEM_Vulcano_Lipari_Salina4326.tif Size is 3718, 3600 Coordinate System is: GEOGCS[“WGS 84”, …. AUTHORITY[“EPSG”,”4326”]] Origin = (14.747192412574043,38.660954215168857) Pixel Size = (0.000090196304703,-0.000090196304703) Metadata: AREA_OR_POINT=Point Image Structure Metadata: INTERLEAVE=BAND Corner Coordinates: …. Band 1 Block=3718x1 Type=Float32, ColorInterp=Gray

As you can see we are talking about Float data. First of all I retiled it with gdal_transalte (striped tiff are pretty bad performance-wise) then I added a few overview using gdaladdo with nearest neighbor interpolation. Once this was done I just throw it at the GeoServer and here is the result for an untiled request (here a detailed request ) and for a tiled request. Quick explanation, when you set up a raster with no real raster symbolizer element in its style (like for the raster.sld that ships with GeoServer) you can get strange results in case your data is raw, like bathymetries, DEMs and the like. What we do is trying to render something useful by doing a local contrast stretch, hence a tiled request can have the checkerboard approach and an untiled request can look fuzzy since maximum and minimum values are used for the stretch. In the future we might computer approximated statistics for a layer at configuration time and use them for the subsequent renderings.

Beside this I wanted to show a nice extension we implemented for the raster symbolizer element. Check this style as well as this one (notice that to use the secondo you have to uncheck SLD validation since the extension is not recognized by OGC schemas). They look like the same but if you check the second one you’ll see that the color map element looks like this while in the other one it looks like this . Well, long story short this is an extension I implemented in order to allow people to ask the GeoServer to symbolize raster data using as many colors as possible (specifically 65k) instead of limiting itself to 256. This results in much better looking images but you have to give away some performances. I guess it is something nice to have for layer that you want to cache with TileCache or GeowebCache.

To see you the differences, check the following:

I guess I have bothered enough.

Ciao a tutti.

PS. I found a minor bug today on the SLDParser which was not parsing the extended attribute. It is now fixed but unless you build things yourself, you won’t be able to test these things on 1.7.0. Drop me a few lines in case you want to try the differences and I’ll tell you how to fix this problem.

Read More

Italian Civil Protection National Spatial Data Infrastructure trusts GeoServer!

Quoting from the geoSDI web site,

“geoSDI is the complete solution for Spatial Data Infrastructure used by the Italian National Civil Protection Department.

The geoSDI solution is based on Open Source Technologies and was born to allow the real time geospatial data sharing between the Functional Centers of the Italian Civil Protection Department, being OGC (Open Geospatial Consortium) standard compliant, INSPIRE Directive compliant and CNIPA Repertorio Nazionali dei Dati Territoriali specifications compliant.”

The  geoSDI infrastructure aims to provide a coherent National Spatial Data Infrastructure (NSDI) which is compliant with national and internal recognized standard as outlined by organizations like ISO and OGC as well as by initiatives like INSPIRE.

We are glad to announce that a core role in the geoSID inititive will be played by the GeoServer framework and that GeoSolutions SAS has been selected to provide professional support for the developments and customizations required.  Stay tuned for more information on the topic.

Read More

Beware of Raster styling changes with 1.7 series

Starting with the 1.7.0 release GeoServer comes with a pretty decent (well, at least IMHO :-) ) implementation of the SLD 1.0 RasterSymbolizer element (check here for a technical discussion on the implementation). On a side this means that we can try to style raster data as well as verctor data. On the other side, this means that if you update GeoServer from an older installation, let’s say 1.6.4 you can get into troubles with preexisting raster data since the old default raster.sld in no longer legal. Here you can find the old raster.sld, while here you can find the new one. which works for 1.7.x and successive releases. Long story short, rationale behind this is that with older geoServer releases we did not have a RasterSymbolizer implementation hence we were simply ignoring most elements of the raster.sld file. From 1.7.0 and on we have a decent RasterSymbolizer implementation, hence the old raster.sld style can no longer be used lightly since it makes assumptions on the underlying data. As a result the new default raster style is just an empty stub.

Summarising, if you are updating GeoSerber from 1.6.x or older, make sure to check to replace the raster.sld with the new onw.

Ciao a tutti.

Read More

Support for SQL Server

The GeoServer team is happy to announce an extension for Microsoft SQL Server, currently available as a nightly build. Instructions for getting the extension up and running are available on the wiki.

At this point the extension is still quite young and is missing some key features like spatial indexing and support for well known binary. By trying it out and providing us with feedback you can help drive development of these features.

The extension is based on the recent re-architecture in GeoTools for database backed data stores. Code named “JDBC Next Generation”, it provides a framework for building new data store implementations quickly and robustly. Also based on this architecture are soon to come improved extensions for MySQL, Oracle, and DB2. A new extension for SpatiaLite is also in the works.

Download the SQL Server extension and try it out. We are very eager to here any feedback on the mailing list. You can also help us make it better by reporting any issues in our bug tracker.

Read More