Platform Operations

Accessing the HERE Platform

The HERE Data SDK for Python provides interaction with HERE platform through the Platform object. There are two standard platform environments supported by the SDK:

Each of these platform environments has its own set of credentials. If you are accessing the default environment and using default credentials, create a Platform object as shown below:

from here.platform import Platform
platform = Platform()

To interact with a different environment and/or provide alternate credentials, pass either or both of the corresponding optional parameters in the Platform constructor:

from here.platform import Platform
platform = Platform(credentials=platform_cred, environment=Environment.CHINA)

See the Credentials section of this document for details of the different ways to provide credentials.

Create the Platform Object With Proxies

If you need to use a proxy, you can create and retrieve the Platform object by passing a proxy configuration. For more details, see Proxies.

from here.platform import Platform
proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}
platform = Platform(proxies=proxies)

Create the Platform Object With Adapter

If you plan to use pandas/GeoPandas in your code, you should create the Platform object passing a GeoPandasAdapter. This will adapt all of the standard platform operations to work seamlessly with the data structures provided by pandas/GeoPandas. See the Using GeoPandas section of this document for information on working with the GeoPandasAdapter.

from here.geopandas_adapter import GeoPandasAdapter
from here.platform import Platform
platform = Platform(adapter=GeoPandasAdapter())

Platform Operations

When you have created a Platform object, you can:

Below you will find a list of common operations at the platform level. Refer to later sections of this document to learn about the catalog and project operations available to you for catalog and project objects. For details on optional arguments and return types of methods presented, refer to the API documentation.

Get the Platform Environment

from here.platform import Platform
platform = Platform()
env = platform.environment

Set the Platform Environment

from here.platform import Platform
from here.platform import Environment
platform = Platform()

env = Environment.DEFAULT
platform.environment = env
env
<Environment.DEFAULT: 1>

Get the Platform Config

from here.platform import Platform
platform = Platform()
config = platform.platform_config
config.config_properties
ConfigTree([('api', 'api.platform.here.com'),
            ('portal_url', 'https://platform.here.com'),
            ('status_url', 'https://status.here.com/status'),
            ('platform_status_url',
             'https://status.here.com/api/here/v1/status'),
            ('account_url', 'https://account.api.here.com')])

Get the Platform Status

from here.platform import Platform
platform = Platform()
status = platform.get_status()
status
{'result': {'status': 'ok', 'description': 'all systems operational'}}

Get Catalog Object

Get the catalog object of the given hrn. An error is generated if the catalog does not exist or if your credentials are not valid.

from here.platform import Platform
platform = Platform()
hrn = "hrn:here:data::olp-here:oma-3"
catalog = platform.get_catalog(hrn=hrn)

Check if Catalog Exists

Check if a catalog exists for a given hrn. Returns True or False depending on whether the catalog exists.

from here.platform import Platform
platform = Platform()
hrn = "hrn:here:data::olp-here:rib-2"
result = platform.catalog_exists(hrn=hrn)
result
True

Create Catalog

Create a catalog and get the generated catalog object.

from here.platform import Platform
platform = Platform()
catalog = platform.create_catalog(id="catalog-id", name="name-of-the-catalog",
             summary="summary of the catalog", description="description of the catalog",
             tags=["tag1", "tag2"])

Create Catalog with Layers

You can define and create one or more layers at the time of catalog creation.

layer1 = {
    "id": "temp-layer",
    "name": "temp-layer-name",
    "summary": "temp-layer-summary",
    "description": "temp-layer-description",
    "contentType": "application/json",
    "layerType": "volatile",
    "partitioning": {
        "scheme": "generic"
    }
}

catalog = platform.create_catalog(id=catalog_id, name='name-of-the-catalog',
                             summary='summary-of-the-catalog', description='description-of-the-catalog', layers=[layer1],
                             tags=["test", "analytics"])

List Catalogs

List all the catalogs accessible on the HERE platform. Optionally, search and return only catalogs specified by filter criteria. A list of Catalog objects is returned.

from here.platform import Platform
platform = Platform()
list_of_catalogs = platform.list_catalogs()

List Layers

List all layers of all catalogs accessible on the HERE platform. Optionally, search and return only layers specified by filter criteria. A list of Layer objects is returned.

from here.platform import Platform
platform = Platform()
list_of_layers = platform.list_layers(coverage='CN')

Modify Catalog

Modify the catalog details, including name, summary, and description. This replaces the complete details of the catalog. After this call succeedes, obtain a new catalog via get_catalog to have access to the modified details, including affected layers. This is used to modify catalog fields.

from here.platform import Platform
platform = Platform()
platform.modify_catalog(hrn="hrn:here:data::olp-here:update", name='updated-name',
                        description='updated-description')

Update Catalog

Update any descriptive and structural information in the catalog. To update a catalog, send a new version of your catalog configuration with the updated data and any required fields.

from here.platform import Platform
platform = Platform()
platform.update_catalog(hrn='hrn:here:data::olp-here:update', id='update', name='update-name',
                        summary='update-summary', description='update-description')

Update Catalog - Add layers

The update_catalog method allows you to add one or more new layers to an existing catalog.

from here.platform import Platform
platform = Platform()
layer1 = {
    "id": "temp-layer",
    "name": "temp-layer-update-name",
    "summary": "temp-layer-summary",
    "description": "temp-layer-description",
    "contentType": "application/json",
    "layerType": "volatile",
    "partitioning": {"scheme": "generic"},
}

platform.update_catalog(catalog.hrn, id=catalog_id, name="updated-name2", summary="updated-summary2", description="updated-description2", layers=[layer1])

# Refresh the updated catalog
catalog = platform.get_catalog(catalog.hrn)

Delete Catalog

Delete a catalog together with the layers it contains.

from here.platform import Platform
platform = Platform()
platform.delete_catalog(hrn='hrn:here:data::olp-here:sample-catalog')

Get Project

Get a project object for the given hrn.

from here.platform import Platform
platform = Platform()
project_object = platform.get_project("hrn:here:authorization::olp-here:project/test")

Create Project

from here.platform import Platform
platform = Platform()
created_project_object = platform.create_project("hrn:here:authorization::olp-here:sample-test-project")

List Projects

Get the list of projects where you are a project admin or a member based on the can_manage and is_member.

from here.platform import Platform
platform = Platform()
project_list = platform.list_projects()

Update Project

Update the project metadata.

from here.platform import Platform
platform = Platform()
project_list = platform.update_project(hrn ="hrn:here:authorization::olp-here:sample-test-project" ,
                                       project_name="sample-project-name", project_desc="sample project desc")

Delete Project

Delete a project together with the catalogs it contains.

from here.platform import Platform
platform = Platform()
project_list = platform.delete_project("hrn:here:authorization::olp-here:sample-test-project")

Leave Project

Leave the specified project.

from here.platform import Platform
platform = Platform()
project_list = platform.leave_project("hrn:here:authorization::olp-here:sample-test-project")

Platform Service Operations

The HERE Data SDK for Python also provides generic access to all Platform Services, including the ability to perform GET and POST requests. For details on all available methods see the API documentation. Below are examples. To execute these examples first perform the following:

from here.platform.platform import Platform
from here.platform.service import Service
platform = Platform()

Get a list of all services

services = platform.list_services()

Get a single service

routing_service_hrn = "hrn:here:service::olp-here:routing-8"
routing_service = platform.get_service(hrn=routing_service_hrn)

Read basic fields of the service

print('\n',
   'HRN:           ', routing_service.hrn, '\n',
   'Version:       ', routing_service.version, '\n',
   'Name:          ', routing_service.name, '\n',
   'Base URL:      ', routing_service.base_url, '\n',
   'Summary:       ', routing_service.summary, '\n',
   'Tags:          ', routing_service.tags, '\n'
)
HRN:            hrn:here:service::olp-here:routing-8
Version:        8.25.0
Name:           HERE Routing
Base URL:       https://router.hereapi.com/v8
Summary:        The Routing service end point calculates routes between two or more locations using various transport modes and provides additional route-related information. The Routing API is customizable so that the route calculation and additional information can be adapted to both consumer and enterprise applications.
Tags:           ['Waypoints', 'Navigation', 'Directions', 'Traffic', 'Pedestrian', 'Routing', 'Vehicle', 'HERE', 'ETA', 'Short route', 'Route shape', 'Car', 'Fast route', 'Alternative routes', 'Route']

Perform REST calls on the service

# GET Request example on service "Transit Next Departures"

transit_dep_service_hrn = "hrn:here:service::olp-here:transit-next-departures-8"
transit_dep_service = platform.get_service(hrn=transit_dep_service_hrn)
departures = transit_dep_service.get("/departures", params={
    'in': '19.152351636582207,72.85587912861622,r=50',
    'maxPlaces': 20
})

departures
{'boards': [{'place': {'name': 'Mahananda Dairy',
    'type': 'station',
    'location': {'lat': 19.150885, 'lng': 72.85633},
    'id': '408202729'},
   'departures': [{'time': '2021-06-16T20:49:00+05:30',
     'transport': {'mode': 'bus',
      'name': '498LTD',
      'category': 'Bus',
      'headsign': 'Borivali Station East'},
     'agency': {'id': 'bhB00000',
      'name': 'BEST (The Brihanmumbai Electric Supply & Transport)',
      'website': 'https://www.bestundertaking.com/in/'}},
    {'time': '2021-06-16T20:50:00+05:30',
     'transport': {'mode': 'bus',
      'name': '225',
      'category': 'Bus',
      'headsign': 'Dahisar Bus Station'},
     'agency': {'id': 'bhB00000',
      'name': 'BEST (The Brihanmumbai Electric Supply & Transport)',
      'website': 'https://www.bestundertaking.com/in/'}},

      --- etc. ---
}
# POST Request example on service "HERE Network Positioning"
nw_positioning_service_hrn = "hrn:here:service::olp-here:positioning-2"
nw_positioning_service = platform.get_service(hrn=nw_positioning_service_hrn)

location_info = nw_positioning_service.post("/locate", data={
  "client": {
    "manufacturer": "Lemon",
    "model": "Flagship X1",
    "name": "FinderApp",
    "version": "2.0.31"
  },
  "lte": [
    {
      "mcc": 262,
      "mnc": 2,
      "cid": 2898945
    }
  ]
})

location_info
{'location': {'lat': 52.51812458, 'lng': 13.37465286, 'accuracy': 2139}}

results matching ""

    No results matching ""