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

Only write XML rules that apply to minzoom/maxzoom of the containing layer #469

Closed
nimix opened this issue Mar 10, 2017 · 5 comments
Closed

Comments

@nimix
Copy link

nimix commented Mar 10, 2017

If a layer is restricted to certain zoom levels by minzoom/maxzoom properties it can get rule that can never apply for this layer because they only apply for scales outside minzoom/maxzoom. The following example output shows a case were only one of the rules is needed:

<Style name="place1" filter-mode="first">
  <Rule>
    <MaxScaleDenominator>50000</MaxScaleDenominator>
    <MinScaleDenominator>5000</MinScaleDenominator>
    <Filter>([type] = 'hamlet')</Filter>
    <TextSymbolizer fontset-name="fontset-1" fill="#000000" placement="point" wrap-width="65" minimum-distance="10" halo-radius="2" halo-fill="#ffffff" size="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>200000</MaxScaleDenominator>
    <MinScaleDenominator>50000</MinScaleDenominator>
    <Filter>([type] = 'suburb')</Filter>
    <TextSymbolizer fontset-name="fontset-1" fill="#000000" placement="point" wrap-width="65" minimum-distance="10" halo-radius="2" halo-fill="#ffffff" size="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>50000</MaxScaleDenominator>
    <MinScaleDenominator>5000</MinScaleDenominator>
    <Filter>([type] = 'village')</Filter>
    <TextSymbolizer size="12" fontset-name="fontset-1" fill="#000000" placement="point" wrap-width="65" minimum-distance="10" halo-radius="2" halo-fill="#ffffff"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>200000</MaxScaleDenominator>
    <MinScaleDenominator>50000</MinScaleDenominator>
    <Filter>([type] = 'village')</Filter>
    <TextSymbolizer fontset-name="fontset-1" fill="#000000" placement="point" wrap-width="65" minimum-distance="10" halo-radius="2" halo-fill="#ffffff" size="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>100000</MaxScaleDenominator>
    <MinScaleDenominator>12500</MinScaleDenominator>
    <Filter>([type] = 'town')</Filter>
    <TextSymbolizer size="12" halo-fill="#ffffff" placement="point" wrap-width="65" minimum-distance="10" fontset-name="fontset-0" halo-radius="2" fill="#222222"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>400000</MaxScaleDenominator>
    <MinScaleDenominator>100000</MinScaleDenominator>
    <Filter>([type] = 'town')</Filter>
    <TextSymbolizer halo-fill="#ffffff" placement="point" wrap-width="65" minimum-distance="10" size="10" fontset-name="fontset-0" halo-radius="2" fill="#222222"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>1500000</MaxScaleDenominator>
    <MinScaleDenominator>400000</MinScaleDenominator>
    <Filter>([type] = 'town')</Filter>
    <TextSymbolizer placement="point" wrap-width="65" minimum-distance="10" size="10" fontset-name="fontset-0" halo-radius="2" fill="#222222" halo-fill="#eeeeee"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>50000</MaxScaleDenominator>
    <MinScaleDenominator>25000</MinScaleDenominator>
    <Filter>([type] = 'city')</Filter>
    <TextSymbolizer size="14" placement="point" wrap-width="65" minimum-distance="10" fontset-name="fontset-0" halo-radius="2" fill="#222222" halo-fill="#eeeeee"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>1500000</MaxScaleDenominator>
    <MinScaleDenominator>50000</MinScaleDenominator>
    <Filter>([type] = 'city')</Filter>
    <TextSymbolizer size="12" placement="point" wrap-width="65" minimum-distance="10" fontset-name="fontset-0" halo-radius="2" fill="#222222" halo-fill="#eeeeee"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>50000000</MaxScaleDenominator>
    <MinScaleDenominator>1500000</MinScaleDenominator>
    <Filter>([type] = 'city')</Filter>
    <TextSymbolizer placement="point" wrap-width="65" minimum-distance="10" fontset-name="fontset-0" halo-radius="2" fill="#222222" size="10" halo-fill="#eeeeee"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>200000000</MaxScaleDenominator>
    <MinScaleDenominator>50000000</MinScaleDenominator>
    <Filter>([type] = 'country')</Filter>
    <TextSymbolizer size="10" fontset-name="fontset-1" halo-radius="2" fill="#222222" halo-fill="#eeeeee" placement="point" wrap-width="65" minimum-distance="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>200000000</MaxScaleDenominator>
    <MinScaleDenominator>100000000</MinScaleDenominator>
    <Filter>([type] = 'continent')</Filter>
    <TextSymbolizer size="14" fontset-name="fontset-0" halo-radius="2" fill="#222222" halo-fill="#eeeeee" placement="point" wrap-width="65" minimum-distance="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
  <Rule>
    <MaxScaleDenominator>500000000</MaxScaleDenominator>
    <MinScaleDenominator>200000000</MinScaleDenominator>
    <Filter>([type] = 'continent')</Filter>
    <TextSymbolizer size="12" fontset-name="fontset-0" halo-radius="2" fill="#222222" halo-fill="#eeeeee" placement="point" wrap-width="65" minimum-distance="10"><![CDATA[[name]]]></TextSymbolizer>
  </Rule>
</Style>
<Layer name="place1"
  maximum-scale-denominator="50000000"
  minimum-scale-denominator="1500000"
  srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">
    <StyleName>place1</StyleName>
  </Layer>
@nebulon42
Copy link
Collaborator

Interesting observation, thanks. For building a test case could you please add the relevant portions of the MML and MSS files?

@nimix
Copy link
Author

nimix commented Mar 26, 2017

Here you go:
MML

{
  "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": [
    "places.mms"
  ],
  "Layer": [
    {
      "geometry": "point",
      "extent": [
        -179.99999692067183,
        -84.96651228427098,
        179.99999692067183,
        84.96651228427099
      ],
      "Datasource": {
        "type": "postgis",
        "table": "(SELECT name, geom, type::text,\"type\" as \"order\" FROM oepnv_places WHERE type IN ('continent','country') ORDER BY \"order\" ASC, population DESC) AS places",
        "key_field": "",
        "geometry_field": "geom",
        "srid": "900913",
        "extent_cache": "custom",
        "extent": "-20037508,-19929239,20037508,19929239",
        "host": "localhost",
        "dbname": "gis",
        "user": "render",
        "port": "5432"
      },
      "properties": {
        "minzoom": 0,
        "maxzoom": 3
      },
      "id": "place0",
      "class": "place",
      "srs-name": "custom",
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over",
      "advanced": {
        "srid": "900913"
      },
      "name": "place0"
    },
    {
      "geometry": "point",
      "extent": [
        -179.99999692067183,
        -84.96651228427098,
        179.99999692067183,
        84.96651228427099
      ],
      "Datasource": {
        "type": "postgis",
        "table": "(SELECT name, geom, type::text,\"type\" as \"order\" FROM oepnv_places WHERE type IN ('continent','country','city') ORDER BY \"order\" ASC, population DESC) AS places",
        "key_field": "",
        "geometry_field": "geom",
        "srid": "900913",
        "extent_cache": "custom",
        "extent": "-20037508,-19929239,20037508,19929239",
        "host": "localhost",
        "dbname": "gis",
        "user": "render",
        "port": "5432"
      },
      "properties": {
        "minzoom": 4,
        "maxzoom": 8
      },
      "id": "place1",
      "class": "place",
      "srs-name": "custom",
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over",
      "advanced": {
        "srid": "900913"
      },
      "name": "place1"
    },
    {
      "geometry": "point",
      "extent": [
        -179.99999692067183,
        -84.96651228427098,
        179.99999692067183,
        84.96651228427099
      ],
      "Datasource": {
        "type": "postgis",
        "table": "(SELECT name, geom, type::text,\"type\" as \"order\" FROM oepnv_places ORDER BY \"order\" ASC, population DESC) AS places",
        "key_field": "",
        "geometry_field": "geom",
        "srid": "900913",
        "extent_cache": "custom",
        "extent": "-20037508,-19929239,20037508,19929239",
        "host": "localhost",
        "dbname": "gis",
        "user": "render",
        "port": "5432"
      },
      "properties": {
        "minzoom": 9,
        "maxzoom": 22
      },
      "id": "place2",
      "class": "place",
      "srs-name": "custom",
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over",
      "advanced": {
        "srid": "900913"
      },
      "name": "place2"
    }
  ],
  "scale": 1,
  "metatile": 2,
  "name": "oepnvkarte",
  "description": ""
}

MSS

@ozean: #a1cbea;
@land: #f1eee8;

@book-fonts: "DejaVu Sans Book","Unifont Medium";
@bold-fonts: "DejaVu Sans Bold","Unifont Medium";
@oblique-fonts: "DejaVu Sans Oblique","Unifont Medium";

Map {
  background-color: @ozean;
}

.place
{
    [type="continent"][zoom<=2]{
      [zoom>=1]{
        text-name: "[name]";
        text-size: 12;
        text-face-name: @bold-fonts;
        text-halo-radius: 2;
        text-fill: #222;
        text-halo-fill: #eee;
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
      }
      [zoom>=2]{text-size: 14;}
    }
    [type="country"][zoom<=3]{
      [zoom>=2]{
        text-name: "[name]";
        text-size: 10;
        text-face-name: @book-fonts;
        text-halo-radius: 2;
        text-fill: #222;
        text-halo-fill: #eee;
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
      }
      [zoom>=4]{
        text-face-name: @bold-fonts;
        text-size: 12;
      }
    }
    [type="city"][zoom<=14]{
      [zoom>=4]{
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
        text-name: "[name]";
        text-face-name: @bold-fonts;
        text-halo-radius: 2;
        text-fill: #222;
        text-size: 10;
        text-halo-fill: #eee;
      }
      [zoom>=9]{text-size: 12;}
      [zoom>=14]{text-size: 14;}
    }
    [type="town"][zoom<=15]
    {
      [zoom>=9]{
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
        text-size: 10;
        text-name: "[name]";
        text-face-name: @bold-fonts;
        text-halo-radius: 2;
        text-fill: #222;
        text-size: 10;
        text-halo-fill: #eee;
      }
      [zoom>=11] { text-halo-fill: #fff; }
      [zoom>=13]{
        text-size: 12;
      }
    }
    [type="village"][zoom<=16]{
      [zoom>=12]{
        text-face-name: @book-fonts;
        text-fill: #000;
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
        text-halo-radius: 2;
        text-halo-fill: #fff;
        text-name: "[name]";
        text-size: 10;
      }
      [zoom>=14]{text-size: 12;}
    }
    [type="suburb"][zoom<=13]{
      [zoom>=12]{
        text-face-name: @book-fonts;
        text-fill: #000;
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
        text-halo-radius: 2;
        text-halo-fill: #fff;
        text-name: "[name]";
        text-size: 10;
      }
    }
    [type="hamlet"][zoom<=16]{
      [zoom>=14]{
        text-face-name: @book-fonts;
        text-fill: #000;
        text-placement: point;
        text-wrap-width: 65;    
        text-min-distance: 10;
        text-halo-radius: 2;
        text-halo-fill: #fff;
        text-name: "[name]";
        text-size: 10;
      }
    }
}

@nebulon42 nebulon42 added this to the 0.18 milestone Mar 26, 2017
@nebulon42
Copy link
Collaborator

nebulon42 commented Mar 26, 2017

Was not that difficult to fix. What's great is that I noticed a nearly 3s shorter compile time for openstreetmap-carto on my machine, which is a speed increase of 20%.

But it is important to test that there are no rendering problems. A quick test with osm-carto revealed no problems so far.
@nimix Could you please test your style if it still looks as expected?

cc @pnorman @rory

@nebulon42
Copy link
Collaborator

Performance is a tricky topic for me. I did some benchmarking because I wanted to release 0.18 and while I got 14% improvement in processing time for osm-carto I got 97% degradation for OSM Bright. The lines decreased slightly by 100 or so for osm-carto but doubled for OSM Bright.

This is unacceptable for release. I have to investigate what causes this. Maybe I will have to revert the change.

@nebulon42 nebulon42 reopened this May 12, 2017
@nebulon42
Copy link
Collaborator

The problem described above was none. It was caused by the fact that a regression for OSM Bright reduced the parsing time by half.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants