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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3

File details

Details for the file py-stadfangaskra-1.0.0.tar.gz.

File metadata

  • Download URL: py-stadfangaskra-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for py-stadfangaskra-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e2f25c157488654a01bdc2401c0559b8689399a24ed02c6b93d37928e1fa1cf9
MD5 928fc223761e466214ddc68d5d46af08
BLAKE2b-256 32daa80359f3ade9680016c9bdacb1e8e1f964e84a1c05139f08ec6ae2d01a59

See more details on using hashes here.

File details

Details for the file py_stadfangaskra-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: py_stadfangaskra-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for py_stadfangaskra-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 90b134d10454cca1580ffcbfa2bb1478adc773800aab38d39b7b9c604647507e
MD5 37c9c2666055f54004269418a5f3133d
BLAKE2b-256 1737f395dcc575f60a34306ad3ca656e915490ce26e805c9b298f1ccb18797fc

See more details on using hashes here.

Supported by

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