Coder Social home page Coder Social logo

ruian-adresy-db's Introduction

RUIAN do databáze

Sada skriptů pro import adresních bodů RUIAN a územních jednotek z veřejného dálkového přístupu (Kraje, Obce, ...) do databáze PostgreSQL/PostGIS a SQLite/Spatialite.

Instalace a závislosti

Skripty využívají SQLalchemy a GeoAlchemy2, gdaltools, PyProj a Shapely. Skript je napsán pro Python3.

pip install requirements.txt

Použití - Import adres

ruian-addresses2db.py [-h] [-v] --connection CONNECTION [--schema SCHEMA]

PostgreSQL

Vytvoření databáze

$ createdb adresy
$ psql adresy

adresy=> CREATE EXTENSION postgis;
adresy=> CREATE SCHEMA adresy;
adresy=> \q

Nastavení souř. systému

Pro správné fungování je potřeba nastavit souř. systém S-JTSK s transformačními parametry towgs84:

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext)
values ( 5514, 'EPSG', 5514,
'+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +units=m +no_defs ',
'PROJCS["S-JTSK / Krovak East North",GEOGCS["S-JTSK",DATUM["System_Jednotne_Trigonometricke_Site_Katastralni",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[570.8,85.7,462.8,4.998,1.587,5.261,3.56],AUTHORITY["EPSG","6156"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4156"]],PROJECTION["Krovak"],PARAMETER["latitude_of_center",49.5],PARAMETER["longitude_of_center",24.83333333333333],PARAMETER["azimuth",30.28813972222222],PARAMETER["pseudo_standard_parallel_1",78.5],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","5514"]]');

nebo

UPDATE spatial_ref_sys set proj4text='+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +units=m +no_defs '
srtext='PROJCS["S-JTSK / Krovak East North",GEOGCS["S-JTSK",DATUM["System_Jednotne_Trigonometricke_Site_Katastralni",SPHEROID["Bessel
1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[570.8,85.7,462.8,4.998,1.587,5.261,3.56],AUTHORITY["EPSG","6156"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4156"]],PROJECTION["Krovak"],PARAMETER["latitude_of_center",49.5],PARAMETER["longitude_of_center",24.83333333333333],PARAMETER["azimuth",30.28813972222222],PARAMETER["pseudo_standard_parallel_1",78.5],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","5514"]]'
where srid = 5514;

Import adres

ruian-adressses2db.py --connection "postgresql://uzivatel:heselo@localhost:5432/adresy" \
                      --schema adresy

SQLite

Je potřeba mít nainstalovanou nadstavbu Spatialite a natvrdo je předpokládáno, že existuje soubor /usr/lib/x86_64-linux-gnu/mod_spatialite.so

ruian-adressses2db.py --connection "sqlite:///adresy.sqlite"

Database schema

                                       Table "addresses"
┌───────────────────────┬──────────────────────┬───────────┬──────────┬──────────────────────────────┐
│        Column         │         Type         │ Collation │ Nullable │           Default            │
├───────────────────────┼──────────────────────┼───────────┼──────────┼──────────────────────────────┤
│ kod_adm               │ integer              │           │ not null │ nextval('addresses_kod_adm_s…│
│                       │                      │           │          │…eq'::regclass)               │
│ obec_kod              │ integer              │           │          │                              │
│ obec_nazev            │ character varying    │           │          │                              │
│ momc_kod              │ integer              │           │          │                              │
│ momc_nazev            │ character varying    │           │          │                              │
│ mop_kod               │ integer              │           │          │                              │
│ mop_nazev             │ character varying    │           │          │                              │
│ cast_obce_kod         │ integer              │           │          │                              │
│ cast_obce_nazev       │ character varying    │           │          │                              │
│ ulice_kod             │ integer              │           │          │                              │
│ ulice_nazev           │ character varying    │           │          │                              │
│ typ_so                │ character varying    │           │          │                              │
│ cislo_domovni         │ integer              │           │          │                              │
│ cislo_orientacni      │ integer              │           │          │                              │
│ cislo_orientacni_znak │ character varying    │           │          │                              │
│ psc                   │ integer              │           │          │                              │
│ plati_od              │ date                 │           │          │                              │
│ geometry              │ geometry(Point,4326) │           │          │                              │
│ geometry_jtsk         │ geometry(Point,5514) │           │          │                              │
└───────────────────────┴──────────────────────┴───────────┴──────────┴──────────────────────────────┘
Indexes:
    "addresses_pkey" PRIMARY KEY, btree (kod_adm)
    "idx_addresses_geometry" gist (geometry)
    "idx_addresses_geometry_jtsk" gist (geometry_jtsk)

Viz dokumentace k adresním bodům RUIAN

Použití - Import Krajů, Okresů, ORP, POÚ a Obcí

Poznámka: Funguje pouze nad PostgreSQL/PostGIS

Data jsou importována do tabulek kraje, orp, okresy, pou a obce. Při každém importu jsou stažena čerstvá data z databáze RUIAN a původní data jsou přemazána (čistý import). Výsledná data obsahují hranice územních jednotek pouze v souř. systému S-JTSK.

python3 ruian-adm2db.py --connection "host=localhost user=user dbname=ruian port=5432 password=XXXXXX"

Parametr connection odpovídá textovému řetězci pro použití v knihovně GDAL.

Po importu

Je dobré vytvořit prostorové indexy a provézt příkaz VACUUM ANALYZE pro lepší uspořádání dat.

CREATE INDEX kraje_geom_idx ON kraje USING GIST (originalnihranice);
CREATE INDEX okresy_geom_idx ON okresy USING GIST (originalnihranice);
CREATE INDEX orp_geom_idx ON orp USING GIST (originalnihranice);
CREATE INDEX pou_geom_idx ON pou USING GIST (originalnihranice);
CREATE INDEX obce_geom_idx ON obce USING GIST (originalnihranice);
VACUUM ANALYZE;

Licence

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Autoři

Jáchym Čepicky jachym.cepicky opengeolabs.cz

OpenGeoLabs s.r.o.

ruian-adresy-db's People

Contributors

dependabot[bot] avatar jachym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.