Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Wrong generated XML Style/Rule from MSS #110

Closed
andrewharvey opened this issue Oct 9, 2011 · 5 comments
Closed

Wrong generated XML Style/Rule from MSS #110

andrewharvey opened this issue Oct 9, 2011 · 5 comments

Comments

@andrewharvey
Copy link

This could be a dup of issue #20, but

When I use carto to convert the following mss/mml to xml...

#amenity[tourism='motel'] {
  [zoom = 20] {
    point-file: url('/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.24.png');
  }
  [zoom > 20] { 
    point-file: url('/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.32.png'); 
  }
}

#amenity[amenity='bench'] {
  [zoom = 20] { 
    point-file: url('/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.24.png'); 
  }
  [zoom > 20] { 
    point-file: url('/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.32.png'); 
  }
}
{
  "bounds": [
    -180,
    -85.05112877980659,
    180,
    85.05112877980659
  ],
  "center": [
    0,
    0,
    2
  ],
  "format": "png",
  "interactivity": false,
  "minzoom": 0,
  "maxzoom": 22,
  "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
  "Stylesheet": [
    "style.mss"
  ],
  "Layer": [
    {
      "geometry": "point",
      "name": "amenity",
      "id": "amenity",
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
      "class": "poi",
      "Datasource": {
        "table": "(\n  SELECT way, amenity, tourism\n  FROM planet_osm_point\n  WHERE (amenity IS NOT NULL OR tourism IS NOT NULL)\n) as amenitypoi",
        "key_field": "",
        "geometry_field": "way",
        "extent": "",
        "type": "postgis",
        "host": "localhost",
        "port": "5432",
        "user": "",
        "password": "",
        "dbname": ""
      }
    }
  ]
}

I get...

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">


<Style name="amenity" filter-mode="first">
  <Rule>
    <MaxScaleDenominator>500</MaxScaleDenominator>
    <Filter>([amenity] = 'bench')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.32.png" />
  </Rule>
  <Rule>
    <MaxScaleDenominator>750</MaxScaleDenominator>
    <MinScaleDenominator>500</MinScaleDenominator>
    <Filter>([amenity] = 'bench')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.24.png" />
  </Rule>
  <Rule>
    <MaxScaleDenominator>750</MaxScaleDenominator>
    <MinScaleDenominator>500</MinScaleDenominator>
    <Filter>([amenity] = 'bench') and ([tourism] = 'motel')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.24.png" />
  </Rule>
  <Rule>
    <MaxScaleDenominator>500</MaxScaleDenominator>
    <Filter>([amenity] = 'bench') and ([tourism] = 'motel')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.32.png" />
  </Rule>
  <Rule>
    <MaxScaleDenominator>500</MaxScaleDenominator>
    <Filter>([tourism] = 'motel')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.32.png" />
  </Rule>
  <Rule>
    <MaxScaleDenominator>750</MaxScaleDenominator>
    <MinScaleDenominator>500</MinScaleDenominator>
    <Filter>([tourism] = 'motel')</Filter>
    <PointSymbolizer file="/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.24.png" />
  </Rule>
</Style>
<Layer name="amenity"
  srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
    <StyleName>amenity</StyleName>
    <Datasource>
       <Parameter name="table"><![CDATA[(
  SELECT way, amenity, tourism
  FROM planet_osm_point
  WHERE (amenity IS NOT NULL OR tourism IS NOT NULL)
) as amenitypoi]]></Parameter>
       <Parameter name="key_field"><![CDATA[]]></Parameter>
       <Parameter name="geometry_field"><![CDATA[way]]></Parameter>
       <Parameter name="extent"><![CDATA[]]></Parameter>
       <Parameter name="type"><![CDATA[postgis]]></Parameter>
       <Parameter name="host"><![CDATA[localhost]]></Parameter>
       <Parameter name="port"><![CDATA[5432]]></Parameter>
       <Parameter name="user"><![CDATA[]]></Parameter>
       <Parameter name="password"><![CDATA[]]></Parameter>
       <Parameter name="dbname"><![CDATA[]]></Parameter>
    </Datasource>
  </Layer>

</Map>

Notice the XML has rules for ([amenity] = 'bench') and ([tourism] = 'motel') which given my original mss I can't see how these rules should be present.

@kkaefer
Copy link
Contributor

kkaefer commented Oct 9, 2011

Carto doesn't know that the columns amenity and tourism are mutually exclusive, so it can't know that it doesn't make sense to generate these rules. Carto generates all possible combinations, which includes a row where amenity == 'bench' and toursim == 'motel' (even if that combination never appears in your database). This is because Carto inherits rules:

#amenity[tourism='motel'][zoom = 20] {
  point-file: url('/usr/share/icons/sjjb/png/accommodation/motel.glow.0092DA.24.png');
}

is what it starts out with and merges in

#amenity[amenity='bench'][zoom = 20] { 
  point-file: url('/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.24.png'); 
}

This results in

#amenity[tourism='motel'][zoom = 20][amenity='bench'] {
  point-file: url('/usr/share/icons/sjjb/png/amenity/bench.glow.8E7409.24.png');
}

However, there's a slight inefficiency in carto as it wouldn't have to generate the second rule because the previous roule would already have rendered all those, so the ([amenity] = 'bench') and ([tourism] = 'motel') rule never matches. The behavior, however, is intended.

@andrewharvey
Copy link
Author

I'll use a different layer for each column then. ie. #amenity which just selects amenity, and #tourism which just selects tourism.

I realise now that this generated XML is exactly how I expected the rendering style to be applied. That is, if it finds tourism=motel AND amenity=bench then it will apply the style of the most recent one, which is what the rules generated do, I just didn't realise it needs to write this out to the XML file, as it just blows up the file size to a point that it can't be used. I thought Mapnik would implicitly decide this just from the ([amenity] = 'bench') rule and the ([tourism] = 'motel') rule without the need of another rule dealing with both.

Thanks anyway, at least I can fix it it my style sheet.

@kkaefer kkaefer reopened this Oct 10, 2011
@kkaefer
Copy link
Contributor

kkaefer commented Oct 10, 2011

You in fact found a valid bug (it generates too many styles), so I'll keep this open. However, this bug shouldn't affect rendering at all; it's only about the efficiency.

@gravitystorm
Copy link
Contributor

I'm pretty sure this is a dupe of #20 - it's describing the same situation and the same end result.

@tmcw
Copy link
Contributor

tmcw commented May 2, 2012

Yep, closing as a duplicate of #20

@tmcw tmcw closed this as completed May 2, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants