Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I newly turned to TileStache to render Mapnik tiles because of the caching option. Before, I was using Mapnik python bindings only and it was working perfectly. Now that I use TileStache, the tiles are rendered randomly at wrong position in wrong order, just like pieces of a puzzle. Only at zoom 0 the features are on the right spot on the map.

enter image description here

This make me think that the problem could be with the row (y) and column (x) used to generate the tiles with coord = ModestMaps.Core.Coordinate(y, x, zoom) or with the projection wich is EPSG 900913.

I use OpenLayers.Layer.TMS for the mapping.

Here some codes:

Tiling script:

def tile(request, version, shapefile, zoom, x, y):
        config = {
            "cache": {
            "name": "Disk",
             "path": "/mygeosite/stache",
             "umask": "0000"},
          "layers": {
            shapefile.filename: {
                "provider": {"name": "mapnik", "mapfile": "c:\\mygeosite\\geodjango\\test.xml"},
                "projection": "spherical mercator"

        # like
        # x = row , y = column , zoom = zoom level
        coord = ModestMaps.Core.Coordinate(y, x, zoom)
        config = TileStache.Config.buildConfiguration(config)
        bytes = TileStache.getTile(config.layers[shapefile.filename], coord, 'png')
        return HttpResponse(bytes[2], mimetype="image/png")


<?xml version="1.0" encoding="utf-8"?>
<Map 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" background-color="rgb(115,145,173)">
    <Style name="featureLayerStyle">
            <PolygonSymbolizer fill="rgb(247,237,238)"/>
            <LineSymbolizer stroke-width="0.5"/>
    <Layer name="featureLayer" 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">
            <Parameter name="dbname">ezmapping</Parameter>
            <Parameter name="geometry_field">geom_multipolygon</Parameter>
            <Parameter name="geometry_table">&quot;shapefile_feature&quot;</Parameter>
            <Parameter name="password">ogrant22</Parameter>
            <Parameter name="simplify_geometries">1</Parameter>
            <Parameter name="srid">900913</Parameter>
            <Parameter name="table">(select geom_multipolygon, id from &quot;shapefile_feature&quot; where shapefile_id=68) as geom</Parameter>
            <Parameter name="type">postgis</Parameter>
            <Parameter name="user">postgres</Parameter>


map = new OpenLayers.Map('map',
          {maxResolution: 156543.0399,
            projection: new OpenLayers.Projection("EPSG:3857"),
            units: 'm',
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
            numZoomLevels: 21});
tiledLayer = new OpenLayers.Layer.TMS('TMS',
                "{{ tmsURL }}",
                {serviceVersion: "1.0",
                layername: "{{ }}",
                type: 'png'});
share|improve this question
I would like to hear about the resolution to this. One thing I notice about your configuration is that OpenLayers is expecting data in a different projection, not Spherical Mercator. EPSG:3857 As for the tile ordering and how to control it, this example shows passing a Transformation() matrix into a TileStache set up with a custom projection. – user24526 Dec 2 '13 at 12:29
up vote 2 down vote accepted

Use OpenLayers.Layer.XYZ instead. TMS is just XYZ with the Y flipped for historical non-reasons.

share|improve this answer
what do you mean by Y flipped? Tile x=0 and y=0 is located lower left corner instead of top left? – Below the Radar May 29 '13 at 13:29
The reason why your zoom 0 looks right is because it is only one tile. It is still wrong! The reason why the others are wrong is because the order is unexpected, so try usingthe solution suggested by tmcw. I actually think that you may have both the Y flipped and X and Y in the wrong order! Take a look at the doco. – Alex Leith Dec 2 '13 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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