8

I am using TileStache to serve my own vector tiles using a postgis datasource. First I re-projected the shapefiles I had using ArcMap ( reprojected to Web Mercator (Auxilary Sphere)) and loaded them in Postgres using shp2pgsql (SRID:900913).

I am able to generate the Tiles using this config file:

{
  "cache":
  {
    "name": "test",
    "path":"/tmp/stache",
    "umask": "0000"

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

I am rendering the tiles generated using Leaflets TileLayer.GeoJSON. The problem I have is that the tiles dont overlay with the basemap, there is pretty large gap between my tiles and the features on the basemap.Incorrect Overlay

When I use WGS84 as the projection in the config file (using data in WGS84) I get empty tiles, no other errors.

How can I get the tiles to overlay correctly? Why does WGS84 not work?

  • Check this thread, it might help, I think it's due to the difference between spherical mercator end mercator. gis.stackexchange.com/questions/34276/… – Glenn Plas Feb 2 '16 at 12:10
  • I looked through the thread before and I don't think that is the issue because Leaflet (which I am using to display the tiles) takes Spherical Mercator as the default projection – Hasan Mustafa Feb 2 '16 at 12:21
  • 1
    Open your postgis db in QGIS and check the properties for the layer. I bet your data is not stored as +proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs . Or check with a qry: SELECT * FROM geometry_columns, see if srid is indeed 900913 – Glenn Plas Feb 2 '16 at 15:58
  • 1
    That was what I thought at first too, but I was pretty careful when I imported the data in Postgres, my SRID is indeed 900913. I tried it with SRID 3857 as well (after chaging the projection to 3857 in QGIS) but that just gives me an error saying that tilestache doesn't work with mixed SRIDs. – Hasan Mustafa Feb 3 '16 at 4:35
5

I got the tiles to overlay correctly. The problem was in the re-projection done by both ArcMap and QGIS. When I was checking the reprojected shapefiles in ArcMap and QGIS, they were overlaying correctly and had the correct SRIDs.

So I imported the shapefiles in WGS84 in PostgreSQL using the SRID4326 with shp2pgsql then used ST_Transfrom to reproject the tables in 900913 the tables using a query:

ALTER TABLE isl_roads 
   ALTER COLUMN geom 
   TYPE Geometry(MultiLineString, 900913) 
   USING ST_Transform(geom, 900913);

Overlaid

But I am still not able to generate the tiles in WGS84, What is it that I am missing?

2

Tx for the feedback, this is important for others who find this question in the future. Are you using WGS84 in your tilestache configuration? There is also a 'projected' attribute you might have to set.

You are using VecTile class, I haven't played with that one yet, but you might be able to get it work (or atleast it will give you some clue/ideas to troubleshoot) with a different provider, like this. You can change the driver to postgresql instead of postgis and give the queries instead of tablename. But the reason I showed it for the 'projected' attribute.

                    "vector-postgis-polygon":
                {
                        "projection": "WGS84",
                        "allowed origin": "*",
                        "provider": {"name": "vector", "driver": "postgis",
                                "parameters": {
                                        "dbname": "database",
                                        "user": "username",
                                        "password": "password",
                                        "table": "planet_osm_polygon"
                                }
                        },
                        "projected": true,
                        "clipped": false,
                        "verbose": true,
                        "preview": { "lat": 50.97513, "lon": 4.46905, "zoom": 18, "ext": "geojson" }
                }
  • I tried using WGS84 with different providers and the projected attribute as well but that still gives me the same result, no errors but empty features. Now that I have spherical mercator tiles overlaying properly I think I can make do without using WGS84 but still I'd like to figure out what the problem is. – Hasan Mustafa Feb 4 '16 at 4:22
  • what I understood from the docs is that you use spherical mercator as projection and set projected to true. But in all honesty, can't get it to work either. I can generate the correct tiles but once I try to create vectors, it seems that the bounding box it uses is not correct. was worth a try though. – Glenn Plas Feb 4 '16 at 9:09
  • 1
    I am using spherical mercator without defining the projected attribute (its false by default) and that works fine for me. For WGS84it could be a problem with the bounding box but I'm not sure, I have the same issue with the vectors. Thanks for the feedback though, you set me on the right path. – Hasan Mustafa Feb 4 '16 at 9:35

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.