~tfardet/gistools

f672efab6be30b9e3f153a599028563381ad5a91 — Tanguy Fardet 28 days ago cd74522
Fix issue with Paris + IGN support
4 files changed, 18 insertions(+), 16 deletions(-)

M __init__.py
M countries/FRA/__init__.py
M countries/FRA/fra_admin.py
M utils/__init__.py
M __init__.py => __init__.py +1 -1
@@ 19,7 19,7 @@ from .utils import _init_logger
from .utils.config import _default_config, _init_config, get_config, set_config


__version__ = "0.2.0-dev"
__version__ = "0.2.1-dev"

# initialize logger and progress bar


M countries/FRA/__init__.py => countries/FRA/__init__.py +0 -5
@@ 24,11 24,6 @@ logger = logging.getLogger(__name__)
# format: geoname, gadm_name, code, admin_level

exceptions = {
    ("75", 2): ("Paris", "Paris", "75", 2),
    ("75", 4): ("Paris", "Paris", "75", 2),
    ("75", 5): ("Paris", "Paris", "75", 2),
    ("75", 3): ("Paris", "Paris", "75", 2),
    "Paris": ("Paris", "Paris", "75056", 4),
    "75000": ("Paris", "Paris", "75056", 4),
    "75056": ("Paris", "Paris", "75056", 4),
    "Arrondissement de Paris": ("Paris", "Paris", "751", 3),

M countries/FRA/fra_admin.py => countries/FRA/fra_admin.py +13 -9
@@ 6,7 6,7 @@ import logging
import os

from os.path import isdir, isfile, join
from shutil import move
from shutil import move, rmtree

import pandas as pd
import numpy as np


@@ 223,19 223,23 @@ def _from_ign() -> tuple[str, str]:

        try:
            os.remove(zipfile)
            os.removedirs(folder)
        except Exception:
            pass

    # check arrondissements
    gdf: GeoDataFrame = _read_file(tmpfile4)
        rmtree(folder, ignore_errors=True)

    if (gdf.INSEE_ARR.str.len() < 3).any():
        gdf.loc[:, "INSEE_ARR"] = gdf["INSEE_DEP"] + gdf["INSEE_ARR"]
        # check arrondissements
        gdf: GeoDataFrame = _read_file(tmpfile4)

        # special case for mayotte
        gdf.loc[gdf.INSEE_DEP == "976", "INSEE_ARR"] = ""
        if (gdf.INSEE_ARR.str.len() < 3).any():
            gdf.loc[:, "INSEE_ARR"] = gdf["INSEE_DEP"] + gdf["INSEE_ARR"]

        gdf.to_file(tmpfile4)
            # special case for mayotte
            gdf.loc[gdf.INSEE_DEP == "976", "INSEE_ARR"] = ""

            gdf.to_file(tmpfile4)

    assert isfile(tmpfile4)
    assert isfile(tmpfile5)

    return tmpfile4, tmpfile5

M utils/__init__.py => utils/__init__.py +4 -1
@@ 27,7 27,10 @@ def is_number(x: _Any) -> bool:
    return False


def _get_admin_level(admin_level, folder) -> list[int]:
def _get_admin_level(
    admin_level: int | _np.integer | None,
    folder: str
) -> list[int]:
    '''
    Return list of admin_level(s) in decreasing order.
    '''