Manage your XYZ Hub server or HERE Data Hub from Python
Project description
XYZ Spaces for Python
Manage your XYZ Hub or HERE Data Hub spaces and Interactive Map Layer from Python.
FEATURED IN: Online Python Machine Learning Conference & GeoPython 2020, Sept 21, 2020, see conference schedule.
Motivation
XYZ is an Open Source, real-time, cloud database system providing access to large geospatial data at scale. An XYZ "Hub" manages "spaces" that contain "features" (geodata "records") with tags and properties, with spaces and features having unique IDs. A RESTful API exists to provide low-level access to interact with a XYZ Hub.
This Python package allows to interact with your XYZ spaces and features on a given Hub using a higher level programmatic interface that wraps the RESTful API. Using this package you can:
- Create, read, list, update, share, delete spaces (also: get space info and stats).
- Add, read, update, iterate, search, cluster (hex/quad bins), delete features.
- Search features by ID, tag, property, bbox, tile, radius, geometry.
Based on the XYZ Hub the HERE Data Hub is a commercial service (with a free plan), that offers some additional features (in a pro plan), like clustering, virtual spaces, activity logs, and likely more to come.
The GIF below shows an interaction with an example notebook, demonstrating how to use a spatial search on a big public dataset, loaded from the HERE Data Hub.
Prerequisites
Before you can install this package, run its test-suite or use the example notebooks to make sure your system meets the following prerequisities:
-
A Python installation, 3.7+ recommended, with the
pip
command available to install dependencies -
A HERE developer account, free and available under HERE Developer Portal
-
An XYZ API access token from your XYZ Hub server or the XYZ portal (see also its Getting Started section) in an environment variable named
XYZ_TOKEN
which you can set like this (with a valid value, of course):export XYZ_TOKEN="MY-FANCY-XYZ-TOKEN"
If you prefer, you can alternatively provide this token as a parameter in your code.
Installation
This package can be installed with pip
or conda
from various sources:
-
Install with conda from the Anaconda conda-forge channel:
conda install -c conda-forge xyzspaces
-
Install from the Python Package Index:
pip install xyzspaces
-
Install from its source repository on GitHub:
pip install -e git+https://github.com/heremaps/xyz-spaces-python#egg=xyzspaces
If you want to run the test suite or experiment with the example notebooks bundled, you need to clone the whole repository:
-
Make a local clone of the repository hosting this package. The following command should do:
git clone https://github.com/heremaps/xyz-spaces-python.git
-
Change into the repo root directory:
cd xyzspaces
Interactive Map Layers
The xyzspaces
package supports Interactive Map Layers which is Data Hub on HERE Platform.
Using xyzspaces
you can interact with your Interactive Map Layers using higher level pythonic interface that wraps the RESTful API.
With Interactive Map Layers, data is stored in GeoJSON and can be retrieved dynamically at any zoom level.
Interactive map layer is optimized for the visualization, analysis, and modification of data on a map (i.e., GIS functions).
Key features of Interactive Map Layers include:
- Creating and modifying maps manually or programmatically; edits are published real-time and require no additional interaction.
- Modifying data a granular feature and feature property level.
- Adding and removing points, lines, and polygons directly on a map.
- Ability to retrieve data in different tiling schemes.
- Exploring and retrieving data by feature ID, bounding box, spatial search, property search, and features contained within a tile.
- Searching for data by values of feature properties (e.g., speed limits, type of place, address, name, etc.).
- Data sampling, making it possible to efficiently render an excerpt of a very large data set for visual reference and analysis.
- Clustering using hexbins or quadbins to produce rich, visual data representations.
Credentials
To interact with Interactive Map Layer you will need an account on the HERE Platform. To get more details on the HERE Platform account please check our documentation Get a HERE account. Once you have the account follow the below steps to get credentials:
- Go to HERE Platform Applications and Keys and register a new app.
- Create a key for the app and download the generated
credentials.properties
file.
The HERE platform generated app credentials should look similar to the example below:
here.user.id = <example_here>
here.client.id = <example_here>
here.access.key.id = <example_here>
here.access.key.secret = <example_here>
here.token.endpoint.url = <example_here>
You can provide your credentials using any of the following methods:
- Default credentials
- Environment variables
- Credentials file
Default credentials
Place the credentials file into
For Linux/MacOS: $HOME/.here/credentials.properties
For Windows: %USERPROFILE%\.here\credentials.properties
Environment Variables
You can override default credentials by assigning values to the following environment variables:
HERE_USER_ID
HERE_CLIENT_ID
HERE_ACCESS_KEY_ID
HERE_ACCESS_KEY_SECRET
HERE_TOKEN_ENDPOINT_URL
Credentials File
You can specify any credentials file as an alternative to that found in ~/.here/credentials.properties
. An error is generated if there is no file present at the path, or if the file is not properly formatted.
Documentation
Documentation is hosted here.
To build the docs locally run:
bash scripts/build_docs.sh
Hello World Example
The following are tiny "Hello World"-like examples that you can run to have a successful first XYZ experience right after installation!
Data Hub
import geojson
import os
import xyzspaces
os.environ["XYZ_TOKEN"] = "MY_XYZ_TOKEN"
xyz = xyzspaces.XYZ()
# Create a New Space
title = "My Demo Space"
description = "My Description"
space = xyz.spaces.new(title=title, description=description)
# Define a New Feature
feature = {
"type": "Feature",
"properties": {"party": "Republican"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}
# Save it to a Space and get its ID
feature_id = space.add_features(features=geojson.FeatureCollection([feature]))["features"][0]["id"]
# Read a Feature from a Space
feature = space.get_feature(feature_id=feature_id)
print(geojson.dumps(feature, indent=4, sort_keys=True))
Interactive Map Layer
import geojson
from xyzspaces import IML
from xyzspaces.iml.credentials import Credentials
credentials = Credentials.from_default() # credentials are in either credentials file at default location or in environment variables
layer_details = {
"id": "demo-interactive-layer",
"name": "Demo Interactive Layer",
"summary": "Demo Interactive Layer",
"description": "Demo Interactive Layer",
"layerType": "interactivemap",
"interactiveMapProperties": {},
}
iml = IML.new(
catalog_id="demo-catalog1",
catalog_name="demo-catalog",
catalog_summary="Demo catalog",
catalog_description="Demo catalog",
layer_details=layer_details,
credentials=credentials,
)
# Define a New Feature
feature = {
"type": "Feature",
"properties": {"party": "Republican"},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99],
]
],
},
}
# Save feature to interactive map layer
iml.layer.write_feature(feature_id="demo_feature", data=feature)
# Read feature from nteractive map layer
resp = iml.layer.get_feature(feature_id="demo_feature")
print(geojson.dumps(resp.to_geojson(), indent=4, sort_keys=True))
License
Copyright (C) 2019-2021 HERE Europe B.V.
Unless otherwise noted in LICENSE
files for specific directories, the LICENSE in the root applies to all content in this repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xyzspaces-0.7.1.tar.gz
.
File metadata
- Download URL: xyzspaces-0.7.1.tar.gz
- Upload date:
- Size: 7.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7514ecb69389ffe2aca5acc59c63bf8a93b6ee222626eb9175f0de2a6583629 |
|
MD5 | 014bf74a3535a349355568c7c21a7d44 |
|
BLAKE2b-256 | 19021138ed8d869d8a08e64935262b31505b7576d259d8891b867f9460ff545f |
File details
Details for the file xyzspaces-0.7.1-py2.py3-none-any.whl
.
File metadata
- Download URL: xyzspaces-0.7.1-py2.py3-none-any.whl
- Upload date:
- Size: 217.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37cf0b2704934ebe6033f486378e04f12d21b2ea140bc045b754cf9308c82054 |
|
MD5 | 1fed52870d2c2d87f912216c73a5864b |
|
BLAKE2b-256 | 047a2bf7126f9fbe087633f8055c0637c565f35bbfa628af14e61fbf1688e821 |