RESTful web service for geospatial data
Tags: geospatial, restful, webservice, opensource
Published: 2020-02-16 09:08:06

If you want to play with Geospatial data, probably you need some tools that allow you to:
- store/import/export geo data;
- search data by proximity or that are included in a specific area;
- obtain statistics;
- aggregate/cluster data;
- connect with multiple sources;
- realtime notification on data changes.

## XYZ Hub

In these days I was playing with XYZ Hub.
**XYZ Hub** is a RESTful web service for geospatial data.
It is opensource and you can obtain sources here: https://github.com/heremaps/xyz-hub

In this post I'm going to list all step needed to install XYZ Hub on your Macbok.

XYZ Hub needs some 3rd party tools like Postgresql for storing data and Redis to manage queues and some other things.

In order to simplify the local setup, and start to play quickly, I suggest you to user Docker.
XYZ Hub uses 3 containers managed by Docker Compose. The file that orchestrates the setup is https://github.com/heremaps/xyz-hub/blob/master/docker-compose.yml .

## Setup

You need to: obtain sources, install dependencies, run containers.

You are going to use:
- *git clone* to obtain sources
- *mvn* to install all dependencies
- *docker-compose up* to run all services needed

```sh
git clone https://github.com/heremaps/xyz-hub.git
cd xyz-hub
mvn clean install
docker-compose up -d
```

If you don't have maven (mvn command) on your local machine, you could install it via Homebrew:

```sh
brew install maven
```


## Consuming APIs

Once you have your services up and running you can start to play with APIs exposed by XYZ Hub.
With the default configuration you can access to APIs with http://localhost:8080

The documentation of APIs: https://xyz.api.here.com/hub/static/swagger/#/

To obtain all spaces:
```sh
curl -H "content-type:application/json" http://localhost:8080/hub/spaces
```
Probably the response is empty, so let's create a new space
```sh
curl -H "content-type:application/json" -d '{"title": "my first space", "description": "my first geodata repo"}' http://localhost:8080/hub/spaces
```

You will see a json response. The most important attribute is "id". This is the identifier of your space.

For example in my case, the response was:
```json
{"id":"hsL2VQik","title":"my first space","description":"my first geodata repo","storage":{"id":"psql","params":null},"owner":"ANONYMOUS","createdAt":1581839550657,"updatedAt":1581839550657,"contentUpdatedAt":1581839550657,"volatility":0.010202997130407065,"autoCacheProfile":{"browserTTL":0,"cdnTTL":0,"serviceTTL":0}}
```
so *hsL2VQik* is my space id.

## Space, Features, Data, Tags

If you are not familiar with these terms, I suggest you to read quickly https://www.here.xyz/api/ . It refers to XYZ Hub Cloud, but you can find useful informations also for your local installation.



## Unofficial PHP SDK

In my spare time I started to implement an open source PHP SDK for consuming these APIs. So it means that for creating space, adding data to space you could use a fluent PHP Library instead of use directly HTTPS APIs.
If you want to contribute, or simply use, or provide feedback or suggestions: https://github.com/hi-folks/milk-sdk-php


## Any feedback is welcome

I'm here to learn and improve every day.
So if you have some suggestion or feedback, this is appreciated!