README

Geospatial Land Cover API Service

Classify locations into well-known land cover categories.

Classify locations using Python

We have some named locations with coordinates and want to classify them using the service.

import requests
import os
import pandas as pd

api_key = os.environ.get('x_rapidapi_key')

You need some helper functions accessing the API using the requests module.

def classify_landcover(latitudes, longitudes):
    url = "https://geolandcover.p.rapidapi.com/classify"
    payload = {
        'lat': latitudes,
        'lon': longitudes
    }
    headers = {
        'content-type': 'application/json',
        'X-RapidAPI-Key': api_key,
        'X-RapidAPI-Host': 'geolandcover.p.rapidapi.com'
    }
    result = requests.post(url, json=payload, headers=headers)
    result.raise_for_status()
    return result.json()

You define two named locations.

named_locations = [
    {
        'name': 'Kernkraftwerk Brokdorf',
        'lat': 53.850833,
        'lon': 9.344722
    },
    {
        'name': 'Kernkraftwerk Stendal',
        'lat': 52.723774,
        'lon': 12.017516
    }
]

You create a pandas dataframe using the dictionary and enrich this dataframe using the API.

named_locations_df = pd.DataFrame.from_dict(named_locations)
latitudes = named_locations_df['lat'].values.tolist()
longitudes = named_locations_df['lon'].values.tolist()
classifications = classify_landcover(latitudes, longitudes)
named_locations_df['category'] = classifications[1]
name lat lon category
Kernkraftwerk Brokdorf 53.850833 9.344722 Industrial or commercial units
Kernkraftwerk Stendal 52.723774 12.017516 Industrial or commercial units
Відстежувачі: 1
Ресурси:
Веб-сайт продукту Умови використання
Створювач API:
Rapid account: Jan Tschada
Jan Tschada
gisfromscratch
Увійти в «Ставки по API»
Рейтинг: 4 - Голосів: 1