geoconflicts

FREEMIUM
By Jan Tschada | Updated 24 days ago | Mapping
Health Check

N/A

Back to All Tutorials (1)

Mapping Russian invasion of Ukraine

This sample notebook visualizes the armed conflict events of a specific day. You need a RapidAPI account and a valid API key.
We are ging to use the ArcGIS API for Python which enables access to ready-to-use maps and curated geographic data from Esri and other authoritative sources, and works with your own data as well. It integrates well with the scientific Python ecosystem and includes rich support for Pandas and Jupyter notebook. For more details take a closer look at Install and Setup.

Install and Setup your Python environment

Choose your favourite enironment e.g. conda or pip, create a dedicated environment, and enter the following at the prompt:

conda install -c esri arcgis
pip install arcgis

pip install georapid

Start a new Juypter notebook instance:

jupyter notebook

Import the Python modules

from arcgis.gis import GIS
from arcgis.features import FeatureLayer, FeatureSet
from arcgis.mapping import WebMap
from arcgis.mapping.renderer import generate_simple, generate_classbreaks
from datetime import datetime
from georapid.client import GeoRapidClient
from georapid.factory import EnvironmentClientFactory
from georapid.conflicts import aggregate, query
from georapid.formats import OutFormat

Define the date of interest

We are interested in every armed conflict event from th 24th February 2022.

date_of_interest = datetime(2022, 2, 24)

Utility functions for mapping capabilities

We define some utility functions offering ready-to-use mapping capabilities.

def create_osm_webmap():
    """Creates a simple web map using the OSM basemap."""
    webmap = WebMap()
    webmap.basemap = 'osm'
    return webmap

def create_events_renderer():
    """Creates a simple renderer representing events as areas of interests."""
    renderer = generate_simple(geometry_type='Polygon', colors=[171, 31, 42, 191])
    renderer_outline = {
        'type': 'esriSLS',
        'color': [0, 0, 0, 191],
        'width': 0.75,
        'style': 'esriSLSSolid'
    }
    renderer['symbol']['outline'] = renderer_outline
    return renderer

def create_aggregated_renderer(spatial_df, field = 'count'):
    """Create a class-breaks renderer representing aggregated events as hexagonal spatial bins."""
    renderer = generate_classbreaks(sdf_or_series=spatial_df, geometry='Polygon', colors='OrRd', field=field)
    return renderer

Connect to RapidAPI

The factory implementation expects a system environment variable named โ€˜x_rapid_apiโ€™ containing your API key.

host = 'geoconflicts.p.rapidapi.com'
conflicts_client = EnvironmentClientFactory.create_client_with_host(host)

aggregated_features_dict = aggregate(conflicts_client, date=date_of_interest, format=OutFormat.ESRI)
aggregated_events_featureset = FeatureSet.from_dict(aggregated_features_dict)

Mapping the armed conflict events

The first web map shows the aggregated armed conflict events of 24th February 2022.

# Mapping the aggregated armed conflict events
focus_map = create_osm_webmap()
aggregated_events_renderer = create_aggregated_renderer(aggregated_events_featureset.sdf)
focus_map.add_layer(aggregated_events_featureset, {'renderer': aggregated_events_renderer, 'opacity': 0.7})
focus_map

Russian Invasion Map