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
User friendly Rasterio plugin to read raster datasets.

rio-tiler User friendly Rasterio plugin to read raster datasets. Documentation: https://cogeotiff.github.io/rio-tiler/ Source Code: https://github.com

372 Dec 23, 2022
Python 台灣行政區地圖 (2021)

Python 台灣行政區地圖 (2021) 以 python 讀取政府開放平台的 ShapeFile 地圖資訊。歡迎引用或是協作 另有縣市資訊、村里資訊與各種行政地圖資訊 例如: 直轄市、縣市界線(TWD97經緯度) 鄉鎮市區界線(TWD97經緯度) | 政府資料開放平臺: https://data

WeselyOng 12 Sep 27, 2022
iNaturalist observations along hiking trails

This tool reads the route of a hike and generates a table of iNaturalist observations along the trails. It also shows the observations and the route of the hike on a map. Moreover, it saves waypoints

7 Nov 11, 2022
Satellite imagery for dummies.

felicette Satellite imagery for dummies. What can you do with this tool? TL;DR: Generate JPEG earth imagery from coordinates/location name with public

Shivashis Padhi 1.8k Jan 03, 2023
Tool to suck data from ArcGIS Server and spit it into PostgreSQL

chupaESRI About ChupaESRI is a Python module/command line tool to extract features from ArcGIS Server map services. Name? Think "chupacabra" or "Chupa

John Reiser 34 Dec 04, 2022
This is a simple python code to get IP address and its location using python

IP address & Location finder @DEV/ED : Pavan Ananth Sharma Dependencies: ip2geotools Note: use pip install ip2geotools to install this in your termin

Pavan Ananth Sharma 2 Jul 05, 2022
3D extension built off of shapely to make working with geospatial/trajectory data easier in python.

PyGeoShape 3D extension to shapely and pyproj to make working with geospatial/trajectory data easier in python. Getting Started Installation pip The e

Marc Brittain 5 Dec 27, 2022
gpdvega is a bridge between GeoPandas and Altair that allows to seamlessly chart geospatial data

gpdvega gpdvega is a bridge between GeoPandas a geospatial extension of Pandas and the declarative statistical visualization library Altair, which all

Ilia Timofeev 49 Jul 25, 2022
Stitch image tiles into larger composite TIFs

untiler Utility to take a directory of {z}/{x}/{y}.(jpg|png) tiles, and stitch into a scenetiff (tif w/ exact merc tile bounds). Future versions will

Mapbox 38 Dec 16, 2022
Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Wei Ji 20 Nov 24, 2022
Geospatial web application developed uisng earthengine, geemap, and streamlit.

geospatial-streamlit Geospatial web applications developed uisng earthengine, geemap, and streamlit. App 1 - Land Surface Temperature A simple, code-f

13 Nov 27, 2022
Summary statistics of geospatial raster datasets based on vector geometries.

rasterstats rasterstats is a Python module for summarizing geospatial raster datasets based on vector geometries. It includes functions for zonal stat

Matthew Perry 437 Dec 23, 2022
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

13 Jan 06, 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
Tile Map Service and OGC Tiles API for QGIS Server

Tiles API Add tiles API to QGIS Server Tiles Map Service API OGC Tiles API Tile Map Service API - TMS The TMS API provides these URLs: /tms/? to get i

3Liz 6 Dec 01, 2021
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
Record railway train route profile with GNSS tools

Train route profile recording with GNSS technology based on ARDUINO platform Project target Develop GNSS recording tools based on the ARDUINO platform

tomcom 1 Jan 01, 2022
Deal with Bing Maps Tiles and Pixels / WGS 84 coordinates conversions, and generate grid Shapefiles

PyBingTiles This is a small toolkit in order to deal with Bing Tiles, used i.e. by Facebook for their Data for Good datasets. Install Clone this repos

Shoichi 1 Dec 08, 2021
Water Detect Algorithm

WaterDetect Synopsis WaterDetect is an end-to-end algorithm to generate open water cover mask, specially conceived for L2A Sentinel 2 imagery from MAJ

142 Dec 30, 2022
EOReader is a multi-satellite reader allowing you to open optical and SAR data.

Remote-sensing opensource python library reading optical and SAR sensors, loading and stacking bands, clouds, DEM and index.

ICube-SERTIT 152 Dec 30, 2022