Skip to main content

Icelandic Location Registry utils

Project description

py-stadfangaskra

Python package

Utility library for working with the Icelandic address registry, pandas & geopandas.

Installation

pip install py-stadfangaskra

Development

Clone the repository and install dev extras.

$ git clone git@github.com:StefanKjartansson/py-stadfangaskra.git
$ cd py-stadfangaskra
# python3.6 & python3.8 are supported as well
$ python3.7 -m venv venv
$ . venv/bin/activate
$ pip install .[dev]
$ py.test

Usage

import stadfangaskra

# Load a dataframe directly from hardcoded ftp path, same as df = stadfangaskra.parse('ftp://ftp.skra.is/skra/STADFANG.dsv.zip'),
# fetches the database from ftp, fairly slow
df = stadfangaskra.parse()
# or use cached local copy, much faster
df = stadfangaskra.parse('STADFANG.dsv.zip')

# Lookup is a utility class for hydrating data using the dataframe.
lookup = stadfangaskra.Lookup.from_dataframe(df)

# Example semi-structured dataframe
some_df = pd.DataFrame({"address": [
    'Laugavegur 22, 101 Reykjavík',
    'Þórsgata 1, 101 Reykjavík',
]})
# hydrate the dataframe, adding columns for postcode, street, house number, latitude, longitude & municipality.
some_df[["postcode", "street", "house_nr", "lat", "lon", "municipality"]] = pd.DataFrame(
    lookup.hydrate_text_array(some_df.address.values), index=some_df.index
)

# Or used to fill latitude & longitude columns in structured datasets
other_df = pd.DataFrame({
    "postcode": [101, 201],
    "street": ["Laugavegur", "Hagasmári"],
    "house_nr": [22, 1],
})

other_df["lat"], other_df["lon"] = (
    lookup.coordinates_from_array(
        df.postcode.values,
        df.street.values,
        df.house_nr.values
    )
)

# Or be used to iterate address matches in text.
my_text = """
Nóatún Austurveri er að Háaleitisbraut 68, 103 Reykjavík en ég bý á Laugavegi 11, 101 Reykjavík
"""

for m in lookup.lookup_text(my_text):
    print(m)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-stadfangaskra-1.0.0.tar.gz (17.1 kB view hashes)

Uploaded Source

Built Distribution

py_stadfangaskra-1.0.0-py2.py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page