main.py downloads and imports Latvian addresses into PostgreSQL database. Data contains parishes,
counties, cities, towns, and streets.
downloads and imports parcels shapefiles (cadastral groups, buildings, engineering structures, parcels, parcel borders,
parcel errors, parcel parts, surveying statuses, and way restrictions)..
- PostgreSQL with PostGIS extension
- Python3 with httpx and psycopg2 modules
- shp2pgsql (shipped with PostGIS), curl, and jq command-line JSON processor for
parcel import script.
Possible future work
- Add import of addresses related shapefiles (same dataset, different archive file; contributors welcome, I have no
use case for it just now)
- Add a utility script to download and import
of parcels data (there’s
a lot of shapefiles)
These are welcome (use issues to report or discuss, pull requests to implement).
To fetch and import addresses, create schema (
psql schema <schema.sql) and then
VZD_DBNAME=schema python3 main.py --verbose.
To download and import all parcel shapefiles, run
VZD_DBNAME=schema ./import-kadastrs.sh. This will take a while.
Python script checks
against Latvian address register open data
, using If-Modified-Since header, which it saves to a file for future reference, so data is being downloaded only if it
has been updated. This means that it can be dropped into cron job to download data when it is updated.
If data has been downloaded, it’s unzipped into
data/csv and then imported into PostgreSQL. Schema has to be created
(it can be found in schema.sql)
If data has invalid coordinates (latitude or longitude is not a number), it’s skipped.
aw_eka table column
geom is created, and an spatial index is added. SRID 4326 is used, so some offsets may
Shell script does nothing fancy. It just fetches JSON metadata, extracts list of all shapefile zip’s, downloads them,
then imports into database (via dropping, creating and populating tables). Spatial index on
geom is also created.
Data has been released by the State Land Service of the Republic of Latvia under goverment’s OpenData initiative, and is
at this data.gov.lv page
. It’s released under CC BY 4.0 license.
CC BY 4.0, which means that it can be used for free, however attribution is required, and no additional restrictions on
this data can be imposed. This script follows suit.