Manage your XYZ Hub or HERE Data Hub spaces from Python.

Overview

XYZ Spaces for Python

Documentation Status Tests PyPI - Status PyPI - Python Version PyPI - Implementation Downloads Conda (channel only) Conda Downloads PyPI - License LGTM alerts LGTM context Swagger Validator GitHub contributors Codecov Slack Code style: black commits since Anaconda-Server Badge Binder

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.

Example from xyzspaces building_numbers.ipynb notebook

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 the Python Package Index with optional dependencies:

    pip install "xyzspaces[geo]"
  • 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:

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.

Comments
  • Outdated package on conda-forge?

    Outdated package on conda-forge?

    Hi guys, I wanted to let you know that I recently installed xyzspace package from conda-forge (version '0.4.0') and it looks that some functionalities are missing there. E.g. according to the documentation one of the parameters of space.spatial_search() is 'force_2d' (to skip Z coordinate in the response). When I wanted to use it I got: TypeError: spatial_search() got an unexpected keyword argument 'force_2d'

    Thanks, Piotr

    no-issue-activity 
    opened by pioboch 4
  • Feature request: 'params' query for feature filtering

    Feature request: 'params' query for feature filtering

    Please implement the functionality to filter feature based in the Python client. A feature filter contains 3 components: property name, value and operator. The current implementation is not sufficient when one want to filter feature using an operator other than equal '='

    Feature filtering is realized in XYZ API via 'params' query for several endpoint, for example for tile request https://xyz.api.here.com/hub/static/swagger/#/Read%20Features/getFeaturesByTile

    Query Syntax ?p.property_name_1=value_1,value_2

    Supported operators

    "=" - equals
    "!=" - not equals
    ">=" or "=gte=" - greater than or equals
    "<=" or "=lte=" - less than or equals
    ">" or "=gt=" - greater than
    "<" or "=lt=" - less than
    "@>" or "=cs=" - contains
    

    Thank you

    enhancement 
    opened by minff 4
  • Exclude tests submodules from package

    Exclude tests submodules from package

    With current setup.py, pip install would still install "tests" package at the same level as xyzspaces package. Added wildcard pattern to exclude it

    opened by minff 3
  • Add initial ADRs

    Add initial ADRs

    Initial stab at adding ADRs, as described by Michael Nygard. This is in MD, but later down the line we might explore way to include this into the main documentation which is formatted in ReST...

    opened by deeplook 3
  • Added changes for custom url for self hosted data hub instances

    Added changes for custom url for self hosted data hub instances

    Signed-off-by: Kharude, Sachin [email protected]

    This PR includes changes for private instances of DataHub APIs. With this change, the user can provide a different base URL for self-hosted Data Hub APIs.

    opened by sackh 2
  • Consider suppressing returning resources for PUT/POST requests

    Consider suppressing returning resources for PUT/POST requests

    Using Accept: application/x-empty in PUT/POST feature requests would prevent the resource to be returned again in the HTTP response which would save some bandwidth and might even reduce server load a bit. If the user really wants the resource it can be obtained with a follow-up GET request.

    enhancement no-issue-activity 
    opened by deeplook 2
  • Resolution param for hexbin clusters has no effect

    Resolution param for hexbin clusters has no effect

    Sample snippet:

    from ipyleaflet import GeoJSON, Map
    from turfpy.measurement import center
    from xyzspaces import XYZ
    from xyzspaces.datasets import get_countries_data
    
    xyz_pro_token = "******"
    xyz = XYZ(credentials=xyz_pro_token)
    space = xyz.spaces.new(title="Hexbin Cluster Demo", description="Hexbin Cluster Demo")
    afg = get_countries_data()["features"][0]
    space.add_features(features=geojson.FeatureCollection([afg]))
    try:
        fc = None
        # Allowed params: [resolution, relativeResolution, absoluteResolution,
        #                  property, pointmode, countmode, noBuffer]
        fc = space.cluster("hexbin", clustering_params={"absoluteResolution": 5})
    finally:
        space.delete()
    
    c = list(reversed(center(afg)["geometry"]["coordinates"]))
    m = Map(center=c, zoom=5)
    if fc:
        m += GeoJSON(data=fc)
    m
    
    opened by deeplook 2
  • Added clientId in query params for Hub API requests

    Added clientId in query params for Hub API requests

    Signed-off-by: Kharude, Sachin [email protected]

    • Added clientId in query params as suggested by DataHub developers this helps in identifying requests sent from xyzspaces library.
    • Minor variable name changes as per pep8 guidelines.
    • Improved clean up for activity log test.
    opened by sackh 2
  • Fix: added mode and viz_sampling params in space class method features_in_tile

    Fix: added mode and viz_sampling params in space class method features_in_tile

    This PR fixes two missing parameters in the Space class's method features_in_tile, mode and viz_sampling which were present in the Api class's method get_space_tile. Also added missing proclamation changes.

    opened by sackh 1
Releases(v0.7.2)
  • v0.7.2(Aug 18, 2021)

  • v0.7.1(Aug 10, 2021)

  • v0.7.0(Aug 10, 2021)

  • v0.6.0(Jun 17, 2021)

  • 0.5.0(Feb 1, 2021)

    Features

    • Added functionality to clone Space. (#93)
    • Added support for the new force2D parameter for all the APIs used to read features. (#96)
    • Added support for new mode and vizSampling params in HubApi.get_space_tile. (#101)
    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Sep 18, 2020)

    Features

    • Upload data from kml and geobuff files to space.
    • Upload Geopandas Dataframe to space and read space data as Geopandas Dataframe.
    • Enabled property search while searching features in the bounding box.
    • Enabled property search while searching features in tile.
    • Improved performance of CSV and GeoJSON files upload.
    • Enabled conversion of original projection of shapefile to EPSG:4326.
    • New notebook illustrating spatial search on Microsoft US building footprints dataset.

    Fixes:

    • Fixed encoding and projections issue for shapefile upload.
    • Fixed duplicate features for spatial_search_geometry with the division.
    • Fixed upload of duplicate features while uploading to space using add_features.
    • Madedescription param optional when creating the space.
    • Added limit param to method iter_feature of Space class to control the number of features to iterate in a single call.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Aug 19, 2020)

    Features

    Upload Enhancements:

    • Supporting upload via shapefile to space. (#40)
    • Supporting upload via WKT file to space. (#41)
    • Supporting upload via gpx file to space. (#42)

    Optimized the spatial search to search features from large geometries. (#44)

    Misc

    • Added Binder support to the repository. (#28)
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Jul 24, 2020)

  • 0.3(Jul 24, 2020)

Owner
HERE Technologies
HERE Technologies, the leading location cloud.
HERE Technologies
Tool to display your current position and angle above your radar

?? Tool to display your current position and angle above your radar. As a response to the CS:GO Update on 1.2.2022, which makes cl_showpos a cheat-pro

Miko 6 Jan 4, 2023
Open Data Cube analyses continental scale Earth Observation data through time

Open Data Cube Core Overview The Open Data Cube Core provides an integrated gridded data analysis environment for decades of analysis ready earth obse

Open Data Cube 410 Dec 13, 2022
A public data repository for datasets created from TransLink GTFS data.

TransLink Spatial Data What: TransLink is the statutory public transit authority for the Metro Vancouver region. This GitHub repository is a collectio

Henry Tang 3 Jan 14, 2022
Using Global fishing watch's data to build a machine learning model that can identify illegal fishing and poaching activities through satellite and geo-location data.

Using Global fishing watch's data to build a machine learning model that can identify illegal fishing and poaching activities through satellite and geo-location data.

Ayush Mishra 3 May 6, 2022
geobeam - adds GIS capabilities to your Apache Beam and Dataflow pipelines.

geobeam adds GIS capabilities to your Apache Beam pipelines. What does geobeam do? geobeam enables you to ingest and analyze massive amounts of geospa

Google Cloud Platform 61 Nov 8, 2022
Python Data. Leaflet.js Maps.

folium Python Data, Leaflet.js Maps folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js

null 6k Jan 2, 2023
Python tools for geographic data

GeoPandas Python tools for geographic data Introduction GeoPandas is a project to add support for geographic data to pandas objects. It currently impl

GeoPandas 3.5k Jan 3, 2023
A package built to support working with spatial data using open source python

EarthPy EarthPy makes it easier to plot and manipulate spatial data in Python. Why EarthPy? Python is a generic programming language designed to suppo

Earth Lab 414 Dec 23, 2022
Python package for earth-observing satellite data processing

Satpy The Satpy package is a python library for reading and manipulating meteorological remote sensing data and writing it to various image and data f

PyTroll 882 Dec 27, 2022
Use Mapbox GL JS to visualize data in a Python Jupyter notebook

Location Data Visualization library for Jupyter Notebooks Library documentation at https://mapbox-mapboxgl-jupyter.readthedocs-hosted.com/en/latest/.

Mapbox 620 Dec 15, 2022
python toolbox for visualizing geographical data and making maps

geoplotlib is a python toolbox for visualizing geographical data and making maps data = read_csv('data/bus.csv') geoplotlib.dot(data) geoplotlib.show(

Andrea Cuttone 976 Dec 11, 2022
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.

OSMnx OSMnx is a Python package that lets you download geospatial data from OpenStreetMap and model, project, visualize, and analyze real-world street

Geoff Boeing 4k Jan 8, 2023
A toolbox for processing earth observation data with Python.

eo-box eobox is a Python package with a small collection of tools for working with Remote Sensing / Earth Observation data. Package Overview So far, t

null 13 Jan 6, 2022
A Python package for delineating nested surface depressions from digital elevation data.

Welcome to the lidar package lidar is Python package for delineating the nested hierarchy of surface depressions in digital elevation models (DEMs). I

Qiusheng Wu 166 Jan 3, 2023
prettymaps - A minimal Python library to draw customized maps from OpenStreetMap data.

A small set of Python functions to draw pretty maps from OpenStreetMap data. Based on osmnx, matplotlib and shapely libraries.

Marcelo de Oliveira Rosa Prates 9k Jan 8, 2023
Spatial Interpolation Toolbox is a Python-based GUI that is able to interpolate spatial data in vector format.

Spatial Interpolation Toolbox This is the home to Spatial Interpolation Toolbox, a graphical user interface (GUI) for interpolating geographic vector

Michael Ward 2 Nov 1, 2021
GebPy is a Python-based, open source tool for the generation of geological data of minerals, rocks and complete lithological sequences.

GebPy is a Python-based, open source tool for the generation of geological data of minerals, rocks and complete lithological sequences. The data can be generated randomly or with respect to user-defined constraints, for example a specific element concentration within minerals and rocks or the order of units within a complete lithological profile.

Maximilian Beeskow 16 Nov 29, 2022
Get-countries-info - A python code that fetches data of any country

Country-info A python code getting countries information including country's map

CODE 2 Feb 21, 2022
Fiona reads and writes geographic data files

Fiona Fiona reads and writes geographic data files and thereby helps Python programmers integrate geographic information systems with other computer s

null 987 Jan 4, 2023