You are not logged in.

#1 2021-05-04 05:51:43

alnyme
Member
Registered: 2021-05-01
Posts: 10

New API for OSM

Hi,

New API has been developed that provides easy access to Open Street Map geodatabase.
The API does not only provide you with the features but also gives you the ability to filter these features using buffer filtration technique.
Provide the API with the center point and radius, and all the requested POI’s within that buffer will be provided in JSON format.
I have created a demo on how to download restaurants, cafes and pubs that are within a 3000 meter radius from Stockholm central station.
Currently the API provides information within Sweden and Germany for the following categories (keys): Amenity, highway, historic, leisure, office, public transport, shop, sport and tourism. Node subcategories (values) for all the mentioned categories are available.
The development of API will be continued, and it will include buildings, lands, railways, roads, transport, waterway, population, regions, municipality borders, and much more.
The buffer radius is limited to max 3000 meter, if you need higher radius like 50 000 meter, then I need to give you a special API key. smile

https://www.youtube.com/watch?v=1mPTEvnDgYE

Regards,
Omar

Offline

#2 2021-05-04 06:25:02

Wulf4096
Member
From: Hamburg
Registered: 2018-10-23
Posts: 1,037

Re: New API for OSM

Hello! Sounds great. Could you please share a link to the API documentation?

Offline

#3 2021-05-04 07:59:14

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

Hi,

Its new API, the document is not completed yet.

You can use the following information for now, and I will come back to you on the final document.


CeTLeR API URL: "https://gisdataapi.cetler.se/"

API variables are:
•    dataBaseName: CeTLeR contains several different geodata databases, in our assignment we will be working with the database named CeTLeR.
•    bufferType: several filtration buffer types are available; we will use radius type only.
•    data: type of data you want to retrieve. We will use “poi” data type.
•    key & value: We will use keys (amenity, highway) and all its values. Please visit https://wiki.openstreetmap.org/wiki/Map_features for more information.
Variable value can accept multi selection separated by “;”. Example: (restaurant;cafe)
•    centerpoint: latitude and longitude that represents the buffer center point.
•    radius: in meter; represents the buffer radius.
•    apiKey: authentication code. Each student will be given one unique code to be used for this assignment.

The idea of the API is to provide all the requested features for the selected category within the given buffer.

Example of a call to OSM API in R:

url <-"https://gisdataapi.cetler.se/"

apiData = GET(url, 
           query = list(dataBaseName='OSM', ApiKey="omar-public", bufferType="radius", data="poi",
                        centerPoint ="52.497424, 13.372886", radius=3000,  
                        key='amenity',value='restaurant;cafe;pub'))

To plot the downloaded feature on a map use the following R code:

apiData = rawToChar(apiData$content)
jsonData = fromJSON(apiData)
sfData <- st_as_sf(jsonData, coords = c("longitude", "latitude"), crs = 4326)
tm_basemap(leaflet::providers$OpenStreetMap) +
  tm_shape(sfData) +   tm_dots(col = "value", palette=c(restaurant='green', cafe='red', pub='black'),
                           stretch.palette = FALSE, size=.1, shape =21)

Retrieve data structure:

The response will be in JSON format. The format is shown below:


[
  {
    "poiName": "Tullinge Gymnasium",
    "key": "amenity",
    "value": "school",
    "latitude": 59.2141762,
    "longitude": 17.9181938
  },
  {
    "poiName": "Hörningsnässkolan",
    "key": "amenity",
    "value": "school",
    "latitude": 59.2360153,
    "longitude": 17.9942684
  },
.
.
.
]

The retrieved data will contain the following fields:
•    Point of interested name.
•    Key.
•    Value.
•    Latitude.
•    Longitude.

Regards,
Omar

Offline

#4 2021-05-04 08:56:09

Wulf4096
Member
From: Hamburg
Registered: 2018-10-23
Posts: 1,037

Re: New API for OSM

alnyme wrote:

Example of a call to OSM API in R:

An example HTTP request (head + body) would be helpful to translate your R example to other programming languages

Offline

#5 2021-05-04 10:16:25

Hartmut Holzgraefe
Member
Registered: 2015-04-13
Posts: 199

Re: New API for OSM

So this is not meant to be a full replacement of the v0.7 API, allowing for both downloading data and submitting changesets, but rather an alternative query API, somewhere in between the old XAPI and the much more powerful, but also way more complex OverPass API, filling a gap between these two ends of the spectrum?

Offline

#6 2021-05-04 12:12:21

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

Hi Wulf4096,

The following code used .Net console application to retrieve data from OSM.


static void Main(string[] args)
        {
            string jsonString = "";
           string URL = "https://gisdataapi.cetler.se/?dataBaseName=OSM&ApiKey=omar-public&bufferType=radius&centerPoint=52.497424,13.372886&radius=3000&key=amenity&value=restaurant;cafe;pub&data=poi";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.ContentType = "application/json; charset=utf-8";
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                jsonString = reader.ReadToEnd();
            }
            Console.WriteLine(jsonString);
            Console.ReadLine();
        }

Offline

#7 2021-05-04 12:13:28

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

Hartmut Holzgraefe wrote:

So this is not meant to be a full replacement of the v0.7 API, allowing for both downloading data and submitting changesets, but rather an alternative query API, somewhere in between the old XAPI and the much more powerful, but also way more complex OverPass API, filling a gap between these two ends of the spectrum?

No its not replacement, but its faster. And this is just the beginning, we are still developing the API.

Last edited by alnyme (2021-05-04 12:13:48)

Offline

#8 2021-05-04 12:44:00

Wulf4096
Member
From: Hamburg
Registered: 2018-10-23
Posts: 1,037

Re: New API for OSM

Nice! Same in code in python:

#!/usr/bin/python3

import requests
from dataclasses import dataclass

@dataclass
class POI:
    poiName: str
    key: str
    value: str
    latitude: float
    longitude: float


resp = requests.get("https://gisdataapi.cetler.se/", params={
    "dataBaseName": "OSM",
    "ApiKey": "omar-public",
    "bufferType": "radius",
    "centerPoint": "53.57003,9.95758",
    "radius": "3000",
    "key": "amenity",
    "value": "restaurant;cafe;pub",
    "data": "poi",
}).json()

for poi in resp:
    print(POI(**poi))

Would it be possible to add the OSM object id, e.g. "n6924790948" for a node?

Offline

#9 2021-05-04 13:59:03

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

Will add it now. give me 15 minutes. smile

Offline

#10 2021-05-04 14:12:47

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

I have added new field called osm_id, which contains the object ID.
Enjoy

Offline

#11 2021-05-04 14:12:59

wambacher
Member
From: Schlangenbad/Wambach, Germany
Registered: 2009-12-16
Posts: 16,621
Website

Re: New API for OSM

@alnyme what is your database and how do you get the data from the central osm database?

regards
walter

Offline

#12 2021-05-04 14:17:49

alnyme
Member
Registered: 2021-05-01
Posts: 10

Re: New API for OSM

--------------------------------------------------------------------

Last edited by alnyme (2021-05-04 15:43:12)

Offline

Board footer

Powered by FluxBB