Skip to content

Instantly share code, notes, and snippets.

@hanbyul-here
Last active December 24, 2017 00:52
Show Gist options
  • Save hanbyul-here/f856d8d466604e0fcb40a6827658072e to your computer and use it in GitHub Desktop.
Save hanbyul-here/f856d8d466604e0fcb40a6827658072e to your computer and use it in GitHub Desktop.
Making custom geojson tiles with Tile Stache

How to

This assumes you already successfully installed TileStache on your machine, then placed the data file in /data folder. Let's say our data file name is test.geojsonand we want to put generated geojson tiles under /built-tiles.

Open the tilestache.cfg and edit the content of it like this: (If you don't want to gzip your tile, take geojsonout from gzipfield.)

{
  "cache":
  {
    "name": "Disk",
    "path": "built-tiles/",
    "umask": "0000",
    "dirs": "portable",
    "gzip": ["xml", "geojson"]
  },
  "layers":
  {
    "test-tiles":
    {
      "provider": {
          "name": "vector", "driver": "GeoJSON",
          "parameters": {"file": "data/test.geojson"}
      }
    }
  }
}

Then you should be able to excute command like this (This command assumes the tiles need to be generated in the bound of NorthEast: [37.7627, 127.3975] SouthWest: [37.3633, 126.6268], and in 14, 15 zoom level) :

  sudo python ./scripts/tilestache-seed.py -b 37.7627 127.3975  37.3633 126.6268 -c tilestache.cfg -l test-tiles 14 15

If you decided to gzip your tile, you would notice that built tiles have geojson.gz extension. Not all browsers know how to deal with gzip encoding, (only applying via Accepts header) I needed to change these extension to just geojson via a command below. (on Mac OS X)

find . -name '*.geojson.gz' -exec sh -c 'mv "$0" "${0%.geojson.gz}.geojson"' {} \;

When serving the tile, make sure Content-Encoding set as gzip. (If you are using s3 bucket gui, it lets you choose it while uploading)

Alternative

Lesson learned

If your data is bigger than 100mb, and you need high zoom tiles, you are going to be suprised how long time it takes to generate static vector tiles. So, plan what you would/wouldn't need from tiles and prepare your data accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment