Package: xyzspaces
XYZ Spaces for PythonManage yourXYZ HuborHERE Data Hubspaces  andInteractive Map Layerfrom Python.FEATURED IN:Online Python Machine Learning Conference & GeoPython 2020, Sept 21, 2020, seeconference schedule.MotivationXYZ 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 anexample notebook,
demonstrating how to use a spatial search on a big public dataset, loaded from the HEREData Hub.PrerequisitesBefore 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 thepipcommand available to install dependenciesA HERE developer account, free and available underHERE Developer PortalAn XYZ API access token from your XYZ Hub server or theXYZ portal(see also itsGetting
Startedsection) in an environment variable namedXYZ_TOKENwhich you can
set like this (with a valid value, of course):exportXYZ_TOKEN="MY-FANCY-XYZ-TOKEN"If you prefer, you can alternatively provide this token as a parameter in your code.InstallationThis package can be installed withpiporcondafrom various sources:Install with conda from the Anacondaconda-forge channel:condainstall-cconda-forgexyzspacesInstall from thePython Package Index:pipinstallxyzspacesInstall from thePython Package Indexwith optional dependencies:pipinstall"xyzspaces[geo]"Install from its source repository on GitHub:pipinstall-egit+https://github.com/heremaps/xyz-spaces-python#egg=xyzspacesIf 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:gitclonehttps://github.com/heremaps/xyz-spaces-python.gitChange into the repo root directory:cdxyzspacesInteractive Map LayersThexyzspacespackage supports Interactive Map Layers which is Data Hub onHERE Platform.
Usingxyzspacesyou 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.CredentialsTo 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 documentationGet a HERE account.
Once you have the account follow the below steps to get credentials:Go toHERE Platform Applications and Keysand register a new app.Create a key for the app and download the generatedcredentials.propertiesfile.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 credentialsEnvironment variablesCredentials fileDefault credentialsPlace the credentials file intoFor Linux/MacOS:$HOME/.here/credentials.propertiesFor Windows:%USERPROFILE%\.here\credentials.propertiesEnvironment VariablesYou 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_URLCredentials FileYou 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.DocumentationDocumentation is hostedhere.To build the docs locally run:bashscripts/build_docs.shHello World ExampleThe following are tiny "Hello World"-like examples that you can run to have a successful first XYZ experience right after installation!Data Hubimportgeojsonimportosimportxyzspacesos.environ["XYZ_TOKEN"]="MY_XYZ_TOKEN"xyz=xyzspaces.XYZ()# Create a New Spacetitle="My Demo Space"description="My Description"space=xyz.spaces.new(title=title,description=description)# Define a New Featurefeature={"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 IDfeature_id=space.add_features(features=geojson.FeatureCollection([feature]))["features"][0]["id"]# Read a Feature from a Spacefeature=space.get_feature(feature_id=feature_id)print(geojson.dumps(feature,indent=4,sort_keys=True))Interactive Map LayerimportgeojsonfromxyzspacesimportIMLfromxyzspaces.iml.credentialsimportCredentialscredentials=Credentials.from_default()# credentials are in either credentials file at default location or in environment variableslayer_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 Featurefeature={"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 layeriml.layer.write_feature(feature_id="demo_feature",data=feature)# Read feature from nteractive map layerresp=iml.layer.get_feature(feature_id="demo_feature")print(geojson.dumps(resp.to_geojson(),indent=4,sort_keys=True))LicenseCopyright (C) 2019-2021 HERE Europe B.V.Unless otherwise noted inLICENSEfiles for specific directories, theLICENSEin the root applies to all content in this repository.