geodisasters

FREEMIUM
By Jan Tschada | Updated a month ago | Mapping
Health Check

N/A

README

Ready to use

The geodisasters API offer ready-to-use geospatial features representing broadcasted news related to natural disasters. You can use these geospatial features to build various mapping and geospatial applications. The underlying serverless cloud-backend analyses raw geospatial locations of news articles provided by the Global Database of Events, Language and Tone (GDELT) Project (https://www.gdeltproject.org/).

Broadcasted news serves as a valuable source of information for identifying natural disasters globally. Geospatial features represent extracted locations from broadcasted news to identify the locations of these events. Natural disasters such as hurricanes, floods, wildfires, and others are captured and represented as geospatial features.

In your dedicated spatial data science environment, you just need the ArcGIS API for Python. We need some utility functions querying the broadcasted news related to natural disasters into a Esri FeatureSet.

# author: Jan Tschada
# SPDX-License-Identifer: Apache-2.0

from arcgis.gis import GIS
from arcgis.features import FeatureLayer, FeatureSet
from datetime import datetime, timedelta
import os
import pandas as pd
import requests

def hotspots_disasters(seen_date, api_key):
    """
    Queries the news related to natural disasters and returns the hotspots as a feature set.
    You need to specify the date of interest.
    The underlying knowledge graph collects locations since 2023-05-24 and yesterday should be the latest available date.
    
    :param datetime seen_date: The date of interest.
    :param api_key str: Your RapidAPI API key.
    """
    host = 'geodisasters.p.rapidapi.com'
    url = f'https://{host}/hotspots'
    headers =  {
        'x-rapidapi-host': host,
        'x-rapidapi-key': api_key
    }
    params = {
        'date': seen_date.strftime('%Y-%m-%d'),
        'format': 'esri'
    }
    featureset_result = requests.get(url, headers=headers, params=params)
    featureset_result.raise_for_status()
    featureset = FeatureSet.from_dict(featureset_result.json())
    return featureset

def hotspots_disasters_since(start_date, api_key):
    """
    Queries the news related to natural disasters and returns the hotspots as a feature set.
    You need to specify the start date, the end date equals yesterday.
    Be aware if you specify a date range greater than 10 days you exceed the free tier!
    
    :param datetime start_date: The first date of interest.
    :param str api_key: Your RapidAPI API key.
    """
    end_date = datetime.utcnow() - timedelta(days=1)
    datespan = end_date - start_date
    featureset_combined = None
    for days in range(0, datespan.days + 1):
        seen_date = start_date + timedelta(days=days)
        featureset = hotspots_disasters(seen_date, api_key)
        if None is featureset_combined:
            featureset_combined = featureset
        elif not None is featureset:
            featureset_combined.features.extend(featureset.features)
    return featureset_combined

The following snippet queries the mentioned hotspots related to natural disasters of 24th May 2023.

seen_date = datetime(2023, 5, 24)
api_key = 'RapidAPI API key'
hotspots_featureset = hotspots_disasters(seen_date, api_key)
hotspots_featureset.sdf

We want to use the mapping capabilities and manage the geospatial features using ArcGIS Online. Therefore, we create a simple geospatial intelligence portal wrapping the mapping and spatial capabilities.

# author: Jan Tschada
# SPDX-License-Identifer: Apache-2.0

class GeospatialIntelligencePortal(object):

    def login(self, username):
        """
        Login into ArcGIS Online using a password input.
        
        :param str username: Your ArcGIS Online username.
        """
        self._gis = GIS(username=username)
    
    def plot_features(self, featureset):
        """
        Creates and returns a simple map view with the plotted geospatial features.
        
        :param FeatureSet featureset:
        """
        map_view = self._gis.map('Europe')
        featureset.sdf.spatial.plot(map_view,
                                    renderer_type='c', 
                                    method='esriClassifyNaturalBreaks',
                                    class_count=5, 
                                    col='count', 
                                    cmap='YlOrRd',
                                    alpha=0.35)
        return map_view

Let us visualize the hotspots using the map view. Please, check out the Sign up for a free ArcGIS Developer account for more details.

geoint_portal = GeospatialIntelligencePortal()
arcgis_user = 'ArcGIS username'
geoint_portal.login(arcgis_user)
...
geoint_portal.plot_features(hotspots_featureset)

Publishing the web map into your dedicated ArcGIS Online organization and designing a simple dashboard works like a charm.

Dashboard of mentioned locations related to natural disasters

Followers: 0
Resources:
Product Website Terms of use
API Creator:
Rapid account: Jan Tschada
Jan Tschada
gisfromscratch
Log In to Rate API
Rating: 5 - Votes: 1