2

I'm trying to get vector tiles from Nextzen (Mapzen) repository with simplified layers (not all group). They don't have an API to download only earth, buildings, etc. Guys from support say that I can decode MVT binary files, then remove some layers that I don't want to use and save it to new MVT. How can I do it right?

I just used this Python script. I decoded one MVT file with this script. I have an example of MVT decoded to TXT.

It looks like JSON and I don't know how to make it human readable without pain

Masoud Rahimi
  • 5,785
  • 15
  • 39
  • 67
Anzipex
  • 69
  • 10
  • 1
    Define human readable :) You can "pretty print" JSON, see for example https://stackoverflow.com/a/32228333/1335237. You could change the Python script to output pretty JSON directly. There are also websites that can do it (google "pretty print json"). Usually, using a website will become more cumbersome the larger files get. – snwflk Apr 25 '19 at 10:55

1 Answers1

1
import mapbox_vector_tile
import json

with open('0.mvt', 'rb') as f:
    data = f.read()
decoded_data = mapbox_vector_tile.decode(data)

sorted_data = json.dumps(decoded_data, indent=4, sort_keys=True)

with open('0.json', 'w') as f:
f.write(sorted_data)
Anzipex
  • 69
  • 10
  • Also https://jsonformatter.org/ can make 2 tab space and save it to file – Anzipex Apr 25 '19 at 14:30
  • For those who googled here: run `brew install geos` and `pip3 install mapbox_vector_tile`, then run this code with python3. – zbycz Jun 03 '21 at 09:32