Small script for UrbanAtlas data

I made a small (python) script to convert some fields from UrbanAtlas ( https://land.copernicus.eu/local/urban-atlas ) into OSM-type of format, that can be opened in JOSM.

If anyone has use for it, please go ahead. Now it is adapted for UrbanAtlas 2012, but should be easy to adapt to the 2018 dataset.

(Also, if this type of topic should be in some other part of the forum, please let me know.)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

import geopandas as gpd

infilename = sys.argv[1]
outfilename = sys.argv[2]

gdf = gpd.read_file(infilename, encoding="utf-8")

attrs = ["landuse", "harbour", "aeroway", "natural", "leisure"]
attrs_to_delete = [
    #    "fid",
    "country",
    "fua_name",
    "fua_code",
    "code_2012",
    "class_2012",
    "prod_date",
    "identifier",
    "perimeter",
    "area",
    "comment",
    "Pop2012",
]

map_attr = "code_2012"
# code; desc; osm-tag
mapper = {
    "11100": {"landuse": "residential"},  # Continuous Urban Fabric (S.L. > 80%)
    "11210": {
        "landuse": "residential"
    },  # Discontinuous Dense Urban Fabric (S.L. : 50% - 80%)
    "11220": {
        "landuse": "residential"
    },  # Discontinuous Medium Density Urban Fabric (S.L. : 30% - 50%)
    "11230": {
        "landuse": "residential"
    },  # Discontinuous Low Density Urban Fabric (S.L. : 10% - 30%)
    "11240": {
        "landuse": "residential"
    },  # Discontinuous Very Low Density Urban Fabric (S.L. < 10%)
    "11300": None,  # Isolated Structures
    "12100": {
        "landuse": "industrial"
    },  # Industrial, commercial, public, military and private units
    "12210": None,  # "Fast transit roads and associated land
    "12220": None,  # "Other roads and associated land
    "12230": {"landuse": "railway"},  # Railways and associated land
    "12300": {"harbour": "yes"},  # Port areas
    "12400": {"aeroway": "aerodrome"},  # Airports
    "13100": {"landuse": "quarry"},  # Mineral extraction and dump sites
    "13300": {"landuse": "construction"},  # Construction sites
    "13400": {"landuse": "brownfield"},  # Land without current use
    "14100": {"landuse": "park"},  # Green urban areas
    "14200": {"leisure": "sports_centre"},  # Sports and leisure facilities
    "21000": {"landuse": "farmland"},  # Arable land (annual crops)
    "22000": {
        "landuse": "orchard"
    },  # Permanent crops (vineyards, fruit trees, olive groves)
    "23000": {"landuse": "meadow"},  # Pastures
    "24000": {"landuse": "farmland"},  # Complex and mixed cultivation patterns
    "25000": {"landuse": "orchard"},  # Orchards at the fringe of urban classes
    "31000": {"landuse": "forest"},  # Forests
    "32000": {
        "natural": "grassland"
    },  # Herbaceous vegetation associations (natural grassland, moors...)
    "33000": None,  # "Open spaces with little or no vegetations (beaches, dunes, bare rocks, glaciers)
    "40000": {"natural": "wetland"},  # Wetland
    "50000": {"natural": "water"},  # Water bodies
}

# JOSM loads polygons faster if they are in wgs84
gdf = gdf.to_crs("EPSG:4326")

# set def attrs to None
for attr in attrs:
    gdf[attr] = None

for attr in attrs:
    temp_map = {}
    for key, valdict in mapper.items():
        if valdict is not None:
            try:
                temp_map[key] = valdict[attr]
            except KeyError:
                pass
    gdf[attr] = gdf[map_attr].map(temp_map)
    gdf[~gdf[attr].isna()].drop(columns=attrs_to_delete).to_file(
        f"{outfilename}_{attr}.shp", driver="ESRI Shapefile"
    )

gdf = gdf.drop(columns=attrs_to_delete)



gdf.to_file(f"{outfilename}_ALL.shp", driver="ESRI Shapefile")

6 posts - 2 participants

Read full topic


Ce sujet de discussion accompagne la publication sur https://community.openstreetmap.org/t/small-script-for-urbanatlas-data/9449