Skip to content

Instantly share code, notes, and snippets.

@mapsam
Last active October 5, 2016 20:56
Show Gist options
  • Save mapsam/8c1f86ed62a704fb2b47942899f5ad46 to your computer and use it in GitHub Desktop.
Save mapsam/8c1f86ed62a704fb2b47942899f5ad46 to your computer and use it in GitHub Desktop.
Mapnik zoom level issue test cases

Failure

Map XML (within tilelive bridge)

<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" buffer-size="256" base="/Users/mapsam/mapbox/tilelive-bridge/" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
  <Parameters>
    <Parameter name="bounds">-71.547459,42.834546,-71.534092,42.845709</Parameter>
    <Parameter name="center">-71.5407755,42.8401275,0</Parameter>
    <Parameter name="format">pbf</Parameter>
    <Parameter name="json">{&quot;vector_layers&quot;:[{&quot;id&quot;:&quot;test_case_fails&quot;,&quot;description&quot;:&quot;&quot;,&quot;minzoom&quot;:0,&quot;maxzoom&quot;:22,&quot;fields&quot;:{}}]}</Parameter>
    <Parameter name="maxzoom">13</Parameter>
    <Parameter name="minzoom">0</Parameter>
  </Parameters>
  <Layer name="test_case_fails" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" buffer-size="8">
    <Datasource>
      <Parameter name="cache_features">false</Parameter>
      <Parameter name="file">/Users/mapsam/data/unpacker-failures/bug_example/test_case_fails.geojson</Parameter>
      <Parameter name="layer">test_case_fails</Parameter>
      <Parameter name="type">geojson</Parameter>
    </Datasource>
  </Layer>
</Map>

Pyramid (generated in tilelive with XML and spherical mercator)

{ 
  '0': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
  '1': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
  '2': { minX: 1, minY: 1, maxX: 1, maxY: 1 },
  '3': { minX: 2, minY: 2, maxX: 2, maxY: 2 },
  '4': { minX: 4, minY: 5, maxX: 4, maxY: 5 },
  '5': { minX: 9, minY: 11, maxX: 9, maxY: 11 },
  '6': { minX: 19, minY: 23, maxX: 19, maxY: 23 },
  '7': { minX: 38, minY: 47, maxX: 38, maxY: 47 },
  '8': { minX: 77, minY: 94, maxX: 77, maxY: 94 },
  '9': { minX: 154, minY: 188, maxX: 154, maxY: 188 },
  '10': { minX: 308, minY: 376, maxX: 308, maxY: 376 },
  '11': { minX: 616, minY: 753, maxX: 617, maxY: 753 },
  '12': { minX: 1233, minY: 1507, maxX: 1234, maxY: 1507 },
  '13': { minX: 2467, minY: 3014, maxX: 2468, maxY: 3015 }
}

Success

Map XML (within tilelive-bridge)

<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" buffer-size="256" base="/Users/mapsam/mapbox/tilelive-bridge/" maximum-extent="-20037508.34,-20037508.34,20037508.34,20037508.34">
  <Parameters>
    <Parameter name="bounds">-71.544323,42.834546,-71.534092,42.843722</Parameter>
    <Parameter name="center">-71.5392075,42.839134,0</Parameter>
    <Parameter name="format">pbf</Parameter>
    <Parameter name="json">{&quot;vector_layers&quot;:[{&quot;id&quot;:&quot;test_case_works&quot;,&quot;description&quot;:&quot;&quot;,&quot;minzoom&quot;:0,&quot;maxzoom&quot;:22,&quot;fields&quot;:{}}]}</Parameter>
    <Parameter name="maxzoom">15</Parameter>
    <Parameter name="minzoom">0</Parameter>
  </Parameters>
  <Layer name="test_case_works" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" buffer-size="8">
    <Datasource>
      <Parameter name="cache_features">false</Parameter>
      <Parameter name="file">/Users/mapsam/data/unpacker-failures/bug_example/test_case_works.geojson</Parameter>
      <Parameter name="layer">test_case_works</Parameter>
      <Parameter name="type">geojson</Parameter>
    </Datasource>
  </Layer>
</Map>

Pyramid (generated in tilelive with XML and spherical mercator)

{ 
  '0': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
  '1': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
  '2': { minX: 1, minY: 1, maxX: 1, maxY: 1 },
  '3': { minX: 2, minY: 2, maxX: 2, maxY: 2 },
  '4': { minX: 4, minY: 5, maxX: 4, maxY: 5 },
  '5': { minX: 9, minY: 11, maxX: 9, maxY: 11 },
  '6': { minX: 19, minY: 23, maxX: 19, maxY: 23 },
  '7': { minX: 38, minY: 47, maxX: 38, maxY: 47 },
  '8': { minX: 77, minY: 94, maxX: 77, maxY: 94 },
  '9': { minX: 154, minY: 188, maxX: 154, maxY: 188 },
  '10': { minX: 308, minY: 376, maxX: 308, maxY: 376 },
  '11': { minX: 616, minY: 753, maxX: 617, maxY: 753 },
  '12': { minX: 1233, minY: 1507, maxX: 1234, maxY: 1507 },
  '13': { minX: 2467, minY: 3015, maxX: 2468, maxY: 3015 },
  '14': { minX: 4935, minY: 6030, maxX: 4936, maxY: 6030 },
  '15': { minX: 9871, minY: 12060, maxX: 9872, maxY: 12061 } 
}

Per tile analysis

>>>>>  test_case_fails
0/0/0 (features: 1) (painted: true) (empty: false)
1/0/0 (features: 0) (painted: false) (empty: true)
2/1/1 (features: 1) (painted: true) (empty: false)
3/2/2 (features: 1) (painted: true) (empty: false)
4/4/5 (features: 3) (painted: true) (empty: false)
5/9/11 (features: 4) (painted: true) (empty: false)
6/19/23 (features: 4) (painted: true) (empty: false)
7/38/47 (features: 4) (painted: true) (empty: false)
8/77/94 (features: 4) (painted: true) (empty: false)
9/154/188 (features: 4) (painted: true) (empty: false)
10/308/376 (features: 4) (painted: true) (empty: false)
11/616/753 (features: 4) (painted: true) (empty: false)
11/617/753 (features: 4) (painted: true) (empty: false)
12/1233/1507 (features: 3) (painted: true) (empty: false)
12/1234/1507 (features: 4) (painted: true) (empty: false)
13/2467/3014 (features: 2) (painted: true) (empty: false)
13/2467/3015 (features: 3) (painted: true) (empty: false)
13/2468/3014 (features: 2) (painted: true) (empty: false)
13/2468/3015 (features: 4) (painted: true) (empty: false)
total tiles:  19

>>>>>  test_case_works
0/0/0 (features: 0) (painted: false) (empty: true)
1/0/0 (features: 0) (painted: false) (empty: true)
2/1/1 (features: 1) (painted: true) (empty: false)
3/2/2 (features: 1) (painted: true) (empty: false)
4/4/5 (features: 2) (painted: true) (empty: false)
5/9/11 (features: 3) (painted: true) (empty: false)
6/19/23 (features: 3) (painted: true) (empty: false)
7/38/47 (features: 3) (painted: true) (empty: false)
8/77/94 (features: 3) (painted: true) (empty: false)
9/154/188 (features: 3) (painted: true) (empty: false)
10/308/376 (features: 3) (painted: true) (empty: false)
11/616/753 (features: 3) (painted: true) (empty: false)
11/617/753 (features: 3) (painted: true) (empty: false)
12/1233/1507 (features: 2) (painted: true) (empty: false)
12/1234/1507 (features: 3) (painted: true) (empty: false)
13/2467/3015 (features: 2) (painted: true) (empty: false)
13/2468/3015 (features: 3) (painted: true) (empty: false)
14/4935/6030 (features: 2) (painted: true) (empty: false)
14/4936/6030 (features: 3) (painted: true) (empty: false)
15/9871/12060 (features: 2) (painted: true) (empty: false)
15/9871/12061 (features: 1) (painted: true) (empty: false)
15/9872/12060 (features: 3) (painted: true) (empty: false)
15/9872/12061 (features: 1) (painted: true) (empty: false)
total tiles:  23
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var mapnik = require('mapnik');
var fs = require('fs');
mapnik.register_default_input_plugins();
var testcases = [
{
"file": "test_case_fails",
"pyramid": {
'0': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
'1': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
'2': { minX: 1, minY: 1, maxX: 1, maxY: 1 },
'3': { minX: 2, minY: 2, maxX: 2, maxY: 2 },
'4': { minX: 4, minY: 5, maxX: 4, maxY: 5 },
'5': { minX: 9, minY: 11, maxX: 9, maxY: 11 },
'6': { minX: 19, minY: 23, maxX: 19, maxY: 23 },
'7': { minX: 38, minY: 47, maxX: 38, maxY: 47 },
'8': { minX: 77, minY: 94, maxX: 77, maxY: 94 },
'9': { minX: 154, minY: 188, maxX: 154, maxY: 188 },
'10': { minX: 308, minY: 376, maxX: 308, maxY: 376 },
'11': { minX: 616, minY: 753, maxX: 617, maxY: 753 },
'12': { minX: 1233, minY: 1507, maxX: 1234, maxY: 1507 },
'13': { minX: 2467, minY: 3014, maxX: 2468, maxY: 3015 }
}
},
{
"file": "test_case_works",
"pyramid": {
'0': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
'1': { minX: 0, minY: 0, maxX: 0, maxY: 0 },
'2': { minX: 1, minY: 1, maxX: 1, maxY: 1 },
'3': { minX: 2, minY: 2, maxX: 2, maxY: 2 },
'4': { minX: 4, minY: 5, maxX: 4, maxY: 5 },
'5': { minX: 9, minY: 11, maxX: 9, maxY: 11 },
'6': { minX: 19, minY: 23, maxX: 19, maxY: 23 },
'7': { minX: 38, minY: 47, maxX: 38, maxY: 47 },
'8': { minX: 77, minY: 94, maxX: 77, maxY: 94 },
'9': { minX: 154, minY: 188, maxX: 154, maxY: 188 },
'10': { minX: 308, minY: 376, maxX: 308, maxY: 376 },
'11': { minX: 616, minY: 753, maxX: 617, maxY: 753 },
'12': { minX: 1233, minY: 1507, maxX: 1234, maxY: 1507 },
'13': { minX: 2467, minY: 3015, maxX: 2468, maxY: 3015 },
'14': { minX: 4935, minY: 6030, maxX: 4936, maxY: 6030 },
'15': { minX: 9871, minY: 12060, maxX: 9872, maxY: 12061 }
}
}
];
testcases.forEach(function(f) {
var gj = JSON.parse(fs.readFileSync('../' + f.file + '.geojson'));
console.log('\n>>>>> ', f.file);
tileThemAll(f.file, gj, f.pyramid);
});
function tileThemAll(name, geojson, pyramid) {
var totalTiles = 0;
for (var z in pyramid) {
for (var x = pyramid[z].minX; x <= pyramid[z].maxX; x++) {
for (var y = pyramid[z].minY; y <= pyramid[z].maxY; y++) {
totalTiles++;
// this is where it all happens
var vt = new mapnik.VectorTile(+z, +x, +y);
vt.addGeoJSON(JSON.stringify(geojson), name);
var vtgj = JSON.parse(vt.toGeoJSONSync('__all__'));
console.log(z + '/' + x + '/' + y, '(features:', vtgj.features.length + ') (painted:', vt.painted() + ')', '(empty:', vt.empty() + ')');
}
}
}
console.log('total tiles: ', totalTiles);
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment