Icelandic Location Registry utils
Project description
py-stadfangaskra
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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for py_stadfangaskra-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b134d10454cca1580ffcbfa2bb1478adc773800aab38d39b7b9c604647507e |
|
MD5 | 37c9c2666055f54004269418a5f3133d |
|
BLAKE2b-256 | 1737f395dcc575f60a34306ad3ca656e915490ce26e805c9b298f1ccb18797fc |