dwins / mapnik2geotools

Using the Scala XML API to translate from Mapnik XML to GeoTools' SLD dialect
64 stars 22 forks source link

Support openstreetmap.org "Mapnik" style #26

Open nrenner opened 12 years ago

nrenner commented 12 years ago

Support the main OSM style osm.xml available at http://svn.openstreetmap.org/applications/rendering/mapnik.

Some of the issues are:

I am currently working on that (https://github.com/nrenner/mapnik2geotools).

dwins commented 12 years ago

one other issue is that that style is designed for mapnik 0.7 while the mapquest styles that I've been using with mapnik2geotools are designed for mapnik2. I think we'll want to do some version inspection to support both, since some names and some semantics have changed between the two versions. The most apparent change is the shift from underscore_separated_names to hyphen-separated-ones but there are some others that are less readily automatable.

I'll try and put together a little infrastructure for doing that over the weekend. The color stuff is looking good so far though!

nrenner commented 12 years ago

I used upgrade_map_xml.py for conversion to Mapnik2 (see Upgrade Guide). This requires entities (inc files) to be merged with generate_xml.py, which in turn requires a Mapnik installation. That seems to work for me, but is a bit of an effort, so supporting both Versions would be nice.

It might be even more convenient to be able to share generated SLDs and configure GeoServer from there, without the need for users to download the Mapnik style, but that is a separate topic.

dwins commented 12 years ago

Well, the configuration that is done includes more than just the SLDs - mn2gt also sets up various data connections and prepares a layergroup. I don't think it would be difficult to upload SLDs in bulk though. It's also possible to copy geoserver data directories around whole, with a little care regarding absolute vs. relative paths.

nrenner commented 12 years ago

fixed empty label: upgrade_map_xml.py converts to new TextSymbolizer syntax

nrenner commented 12 years ago

new issue: table column text_poly.ele of type unknown ("NULL as ele" in select) ignored by GeoServer Workaround: alter table text_poly alter column ele type text; or replace "NULL as ele" with "NULL::text as ele"

Not sure if and how this should be addressed in m2gt?

nrenner commented 12 years ago

About the issue: not tunnel=yes with null values

<Filter>(([railway]='rail') and not (([tunnel]='yes')))</Filter>

translates to:

<Filter xmlns="http://www.opengis.net/ogc">
  <And>
    <PropertyIsEqualTo>
      <PropertyName>railway</PropertyName>
      <Literal>rail</Literal>
    </PropertyIsEqualTo>
    <Not>
      <PropertyIsEqualTo>
        <PropertyName>tunnel</PropertyName>
        <Literal>yes</Literal>
      </PropertyIsEqualTo>
    </Not>
  </And>
</Filter>

This filter does not match when tunnel is null with GeoServer (2.1.1) - it does however with GeoTools (8-SNAPSHOT)?

A possible solution seems to be translating to:

<Filter xmlns="http://www.opengis.net/ogc">
  <And>
    <PropertyIsEqualTo>
      <PropertyName>railway</PropertyName>
      <Literal>rail</Literal>
    </PropertyIsEqualTo>
    <Or>
      <PropertyIsNull>
        <PropertyName>tunnel</PropertyName>
      </PropertyIsNull>
      <PropertyIsNotEqualTo>
        <PropertyName>tunnel</PropertyName>
        <Literal>yes</Literal>
      </PropertyIsNotEqualTo>
    </Or>
  </And>
</Filter>

What do you think?

dwins commented 12 years ago

I've run into this issue regarding nulls while working on the GeoServer CSS module and the solution you propose (ORing with an explicit null check) is exactly what I came up with as well.

dwins commented 12 years ago

If this behavior has changed with GeoTools 8, you could also start using GeoServer trunk for rendering - GeoTools 8 is already in use on that branch.

dwins commented 12 years ago

Ok, I've merged in your Color improvements and added some pretty basic version inspection in the Mapnik2GeoTools class (see the rulesFor method in Mapnik2Geotools.scala, https://github.com/dwins/mapnik2geotools/blob/26daebd438c004d616cee0ecfb8b6d9ed247e4d9/src/main/scala/Mapnik2GeoTools.scala#L197 )

Basically, we inspect the value and based on that change which SymTransformers to use for the file. I have started on TextSymbolizers a bit so those are the only transformers that are actually different right now.

dwins commented 12 years ago

I also put together some notes on how I do development: https://github.com/dwins/mapnik2geotools/wiki/Hacking

Hope you find them useful.

nrenner commented 12 years ago

Thanks for your notes, I didn't know about the sbt triggered tasks, that's a nice feature!

nrenner commented 12 years ago

On the nulls issue:

I tested GeoServer from trunk, but still the same issue. But I found out that the difference between GeoTools and GeoServer is that SQL pre-filtering is active in GeoServer but not in GeoTools. This is because of different default settings for the maxFiltersToSendToDatastore (5) and MAX_FILTER_RULES (20) parameters, where the filter number of some styles fall in between. The problem now is that the SQL and Java filters evaluate differently with not equals and null values. I opened an issue for that: http://jira.codehaus.org/browse/GEOT-3949.

The workaround is to set maxFiltersToSendToDatastore / MAX_FILTER_RULES = 0 to disable SQL pre-filtering, which is fine in our case, because we have pre-filtered tables per style anyway.