7

I am serving several vector tile layers of different geometries (point, line & polygon) in TileStache using VecTiles:Provider, with this cfgfile:

{
  "cache":
  {
    "name": "DISK",
    "path":"/tmp/stache",
    "umask": "0000" 
  },
  "layers": 
  {  
    "world":
    {       
        "allowed origin":"*",
        "projection": "spherical mercator",
        "provider":
        {
            "class": "TileStache.Goodies.VecTiles:Provider",      
            "kwargs":
            {
                "dbinfo":
                {
                    "host":"localhost",
                    "user":"postgres",
                    "password":"postgres123",
                    "database":"test"
                },
            "queries":
                {
                    "0":"SELECT geom AS __geometry__,name_0 FROM worldcountries1  -- zoom 0+"
                }
            }
        },
        "preview":{"ext":"json"}
    },
    "boundary":
    {       
        "allowed origin":"*",
        "projection": "spherical mercator",
        "provider":
        {
            "class": "TileStache.Goodies.VecTiles:Provider",      
            "kwargs":
            {
                "dbinfo":
                {
                    "host":"localhost",
                    "user":"postgres",
                    "password":"postgres123",
                    "database":"test"
                },
            "queries":
                {
                    "6":"SELECT geom AS __geometry__,name_2 FROM islamabad_bound  -- zoom 6+",
                    "7":"SELECT geom AS __geometry__,name_2 FROM islamabad_bound",
                    "8":"SELECT geom AS __geometry__,name_2 FROM islamabad_bound",
                    "9": null

                }
            }
        },
        "preview":{"ext":"json"}
    },
    "cartographic":
    {       
        "allowed origin":"*",
        "projection": "spherical mercator",
        "provider":
        {
            "class": "TileStache.Goodies.VecTiles:Provider",                        
            "kwargs":
            {
                "dbinfo":
                    {
                       "host":"localhost",
                       "user":"postgres",
                       "password":"postgres123",
                       "database":"test"                       
                    },
                "queries":
                {
                    "8":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water') -- zoom 8+",
                    "9":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water')",
                    "10":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water')",
                    "11":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water')",
                    "12":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water')",
                    "13":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water','industry','educational','graveyard','hospitals','religious places','parking places','port places','runway')",
                    "14":"SELECT geom AS __geometry__,name, priority,category, kind FROM cartographic WHERE kind IN ('parks','forests','water','industry','educational','graveyard','hospitals','religious places','parking places','port places','runway','building_low')"
                }

            }
        },
        "preview":{"ext":"json"}
    },
    "roads":
    {       
        "allowed origin":"*",
        "projection": "spherical mercator",
        "provider":
        {
            "class": "TileStache.Goodies.VecTiles:Provider",                        
            "kwargs":
            {
                "dbinfo":
                    {
                       "host":"localhost",
                       "user":"postgres",
                       "password":"postgres123",
                       "database":"test"                       
                    },
                "queries":
                {
                    "7":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4) -- zoom 7+",
                    "8":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4)",
                    "9":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4)",
                    "10":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4)",
                    "11":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4,3,2)",
                    "12":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4,3,2)",
                    "13":"SELECT geom AS __geometry__,name, priority FROM isl_roads WHERE priority IN (5,4,3,2)",
                    "14":"SELECT geom AS __geometry__,name, priority FROM isl_roads  -- zoom 14+"
                }

            }
        },
        "preview":{"ext":"json"}
    },
    "pois":
    {       
        "allowed origin":"*",
        "projection": "spherical mercator",
        "provider":
        {
            "class": "TileStache.Goodies.VecTiles:Provider",                        
            "kwargs":
            {
                "dbinfo":
                    {
                       "host":"localhost",
                       "user":"postgres",
                       "password":"postgres123",
                       "database":"test"                       
                    },
                "queries":
                {
                    "12":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level = 12 -- zoom 12+",
                    "13":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13)",
                    "14":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14)",
                    "15":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15)",
                    "16":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15,16)",
                    "17":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15,16,17)",
                    "18":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15,16,17,18)",
                    "19":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15,16,17,18,19)",
                    "20":"SELECT geom AS __geometry__,name, priority FROM isl_pois_priority WHERE zoom_level IN (12,13,14,15,16,17,18,19,20) -- zoom 20+"
                }

            }
        },
        "preview":{"ext":"json"}
    }
  }
}

To render the tiles on the web I am making use of The GeoJSON plugin in Leaflet to individually call the layers. Each tile layer corresponds to a single JSON layer.

var geojsonURL = 'http://localhost:8080/roads/{z}/{x}/{y}.json';
    var geojsonTileLayer = new L.TileLayer.GeoJSON(geojsonURL, {
            clipTiles: true,
            unique: function (feature) {
                return feature.id; 
            }
        }, {
            style: style,
            onEachFeature: function (feature, layer) {
                if (feature.properties) {
                    var popupString = '';
                    for (var k in feature.properties) {
                        var v = feature.properties[k];
                        popupString += k + ': ' + v + ' ';
                    }
                    popupString += '';
                    layer.bindPopup(popupString);
                }
                if (!(layer instanceof L.Point)) {
                    layer.on('mouseover', function () {
                        layer.setStyle(hoverStyle);
                    });
                    layer.on('mouseout', function () {
                        layer.setStyle(style);
                    });
                }
            }
        }
    );
    map.addLayer(geojsonTileLayer);

I have looked into the Composite and Sandwich providers in TileStache but they seem to only work for Raster data, I can't get them to work on my Vector Tile Layers.

Can I use the Composite provider to stack/merge the vector tile layers, or is there any other way to return all my tiles in a single JSON?

Update: I have found a way to merge multipleGeoJSONs using python , how can I integrate this into TileStache so that I can use this like the composite provider (something like custom provider perhaps, though I can't figure out how to make it work exactly)?

5

So I am able to get all the layers in a single layer, a "composite" by using the MultiProvider provider in the class and just passing it the layers I want in the composite as the arguments. It results in a single JSON file that contains all of my layers. This is the layer I added in the cfg


    "composite":
        {
            "allowed origin":"*",
            "provider":
            {
                "class": "TileStache.Goodies.VecTiles:MultiProvider",
                "kwargs":
                {
                    "names": [ "boundary", "cartographic", "roads", "pois"]
                }
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.