Skip to main content

Reading ESRI Vector Tile Package (vtpk) files.

Project description

vtpk-reader

CI Coverage Status

A library to read ESRI Vector Tile Package (.vtpk) files

Installation

pip install vtpk_reader

Getting started

Read vtpk file and extract some features

from vtpk_reader import Vtpk

vtpk = Vtpk("path/to/your/vtpk/file.vtpk")
# Get all tiles at LOD (level of detail) zero, there should only be one tiles
tiles = vtpk.get_tiles(0, None)  
# Get the one of the tiles
one_tile = list(tiles)[0]
# Extract the tile features
features = vtpk.tile_features(one_tile)
# Look at the keys in the data
print(f"{features.keys()})

More detailed example using dodge_city.vtpk

This file is can be found at by searching for "vtpk" and "dodge" on www.arcgis.com. Based on the name and the description, it probably does not contain content not available elsewhere, but being small it is a useful test file.

from vtpk_reader import Vtpk
import geopandas as gpd
import matplotlib.pyplot as plt
import contextily as cx

# Load the vtpk
vtpk = Vtpk("dodge_city.vtpk")
# Create a matplotlib plot
fig, ax = plt.subplots(figsize=(10, 10))
# Get all the tiles at the maximum Level Of Detail (LOD)
# ... not normally recommended, but in case of small VTPKs it should be OK?
tiles = vtpk.get_tiles([vtpk.max_lod], None)
# Get a color palette from matplotlib
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']

for idx_tile, tile in enumerate(tiles):
  features = vtpk.tile_features(tile)

  # Plot every kind of feature there is
  for feature_key_idx, feature_key in enumerate(features.keys()):
    gdf = gpd.GeoDataFrame(
      [prop["geometry"] for prop in features[feature_key]["features"]], 
      columns=["geometry"],
      crs=vtpk.crs, 
      geometry="geometry",
    )
    gdf.plot(ax=ax, alpha=0.25, color=colors[idx_tile])

# Add a basemap
cx.add_basemap(ax, source=cx.providers.CartoDB.DarkMatter)
# Expand the plot limits by a factor
increase_factor = 0.125
xlim = ax.get_xlim() 
xextent = xlim[1] - xlim[0]
ylim = ax.get_ylim() 
yextent = ylim[1] - ylim[0]
ax.set_xlim(xlim[0] - xextent*increase_factor, xlim[1] + xextent*increase_factor/2)
ax.set_ylim(ylim[0] - yextent*increase_factor, ylim[1] + yextent*increase_factor/2)
ax.set_axis_off()

You should get something like this: logo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vtpk_reader-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vtpk_reader-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file vtpk_reader-0.1.0.tar.gz.

File metadata

  • Download URL: vtpk_reader-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for vtpk_reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e919dd0795923de1b4963f66e101605229aea48931b869444d34d27e70b2292c
MD5 bf1d6ed83a1d6d40b5d97235c2603000
BLAKE2b-256 ac06a2c0f9d72b281f7bef83f56894def91d237b72351ae1a18e888b97081005

See more details on using hashes here.

File details

Details for the file vtpk_reader-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vtpk_reader-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for vtpk_reader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06362847da268799b185f94e0d11b651de2a9032445ef4f6740058e0db0bb059
MD5 c64dc68e4557d8f9012ec9cfb2be0d49
BLAKE2b-256 75388cd9b67801458ff8a872463e0a48cb1f9060c65f85b09bb280840b7267d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page