kleshnin a. postgis-open solution for spatial data-database
DESCRIPTION
PostGIS - open solution for storing and processing of spatial data in the databaseAlexander Kleshnin, Kharkiv, Intetics CoTRANSCRIPT
![Page 1: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/1.jpg)
PostGIS - открытое решение для хранения и обработки пространственных данных в базе данных
Александр Клешнин Харьков, Intetics Co
![Page 2: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/2.jpg)
Содержание
Теоретический обзорЧто такое PostGIS?Стоимость/функциональность пространственных баз данныхФункции/возможности PostGIS
Практическая демонстрацияУстановка PostgreSQL/PostGISИмпорт данных в пространственную базу данныхВыполнение запросов расчета длины/площадиПространственные индексыСоздание функции PostGISВыполнение запросов обновления атрибутивных данных в слоеСоздание объектов через SQL запросЭкспорт данных из пространственной базы данных
![Page 3: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/3.jpg)
Open Geospatial Consortium (OGC)
http://www.opengeospatial.org/
![Page 4: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/4.jpg)
СУБД для пространственных данных
Проприетарные решения:Oracle SpatialMS SQL Server 2008Informix Spatial BladeDB2 Spatial ExtenderArcSDE (SDE – Spatial Database Engine)
Свободные решения:PostgreSQL/PostGISSQLite/SpatiaLiteMySQL/Spatial
![Page 5: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/5.jpg)
Стоимость & функциональность
Сто
им
ость
Функциональность
![Page 6: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/6.jpg)
Что такое PostGIS?
PostGIS – расширение СУБД PostgreSQL для хранения в базе данных географических данных
экономически эффективная альтернатива Oracle Spatial & Locator, IBM DB2 Spatial, Informix Spatial DataBlade, Microsoft SQL Server
PostGIS – GPL Open Source Project
![Page 7: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/7.jpg)
PostGIS объекты
OpenGIS Simple Features for SQL Objects
POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION
OpenGIS Simple Features for SQL Representations
AsText( ) Well-Known Text• POINT(2 4)• MULTILINESTRING((-128 45,-128 46),(-130 50,-131 55))
AsBinary( ) Well-Known Binary • 000000000140000000000000004010000000000000
![Page 8: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/8.jpg)
Геопроцессинг с PostGIS
Функции управления
Функции геометрической связи
Функции обработки геометрии
Функции измерения
• ST_Distance• ST_DWithin• ST_Intersects
• ST_Area• ST_Length• ST_Distance_Spheroi
d
• ST_Buffer• ST_Intersection• ST_Union
• ST_Touches• ST_Crosses• ST_Within
• AddGeometryColumn• DropGeometryColumn• ST_SetSRID
PostGIS функции (~800) доступны посредством SQL
• ST_Centroid• ST_ConvexHull• ST_Difference
![Page 9: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/9.jpg)
PostgreSQL/PostGIS и другое ПО
![Page 10: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/10.jpg)
Практическая работа: структура системы/ПО
Сервер БД
Пользователи
![Page 11: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/11.jpg)
Установка PostgreSQL / PostGIS
http://www.postgresql.org/ http://postgis.refractions.net/
PostgreSQL PostGIS
![Page 12: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/12.jpg)
Установка PostgreSQL
![Page 13: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/13.jpg)
Установка PostgreSQL
![Page 14: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/14.jpg)
Установка PostgreSQL
![Page 15: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/15.jpg)
Установка PostgreSQL
![Page 16: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/16.jpg)
Установка PostgreSQL
![Page 17: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/17.jpg)
Установка PostGIS
![Page 18: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/18.jpg)
Установка PostGIS
![Page 19: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/19.jpg)
Установка PostGIS
![Page 20: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/20.jpg)
Установка PostGIS
![Page 21: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/21.jpg)
Установка PostGIS
![Page 22: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/22.jpg)
Установка PostGIS
![Page 23: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/23.jpg)
Установка PostGIS
![Page 24: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/24.jpg)
Установка PostGIS
![Page 25: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/25.jpg)
Установка PostGIS
![Page 26: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/26.jpg)
pgAdmin – инструмент управления БД PostgreSQL/PostGIS
SELECT version() || ' ' || postgis_full_version();
![Page 27: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/27.jpg)
Создание пользователей
-- Role: admin-- DROP ROLE admin;
CREATE ROLE admin LOGIN ENCRYPTED PASSWORD 'md5f6fdffe48c908deb0f4c3bd36c032e72' SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION CONNECTION LIMIT 5;
-- Role: gis-- DROP ROLE gis;
CREATE ROLE gis LOGIN ENCRYPTED PASSWORD 'md5d1eac6a9b9835a37d71bac718a80a7ac' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION CONNECTION LIMIT 100;
Administrator - admin User - gis
![Page 28: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/28.jpg)
Создание пространственной базы данных
-- Database: template_postgis_20-- DROP DATABASE template_postgis_20;CREATE DATABASE template_postgis_20 WITH OWNER = postgres
ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'Russian_Russia.1251'
LC_CTYPE = 'Russian_Russia.1251'CONNECTION LIMIT = -1;
ALTER DATABASE template_postgis_20 SET search_path = "$user", public, topology;
База данных - database
![Page 29: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/29.jpg)
Структура пространственной базы данных
![Page 30: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/30.jpg)
Импорт shp-файлов в базу данных PostGIS
SQL команды shp2pgsql // PostGIS 2.0 Shapefile and DBF Loader Exporter (GUI)
ogr2ogr (OGR – свободная библиотека для работы с векторными данными)
SPIT (Quantum GIS Tool)
ESRI’s Data Interoperability extension ($)
ogr2ogr -f PostgreSQL PG:"host=localhost user=admin dbname=database password=admin" streets.shp;
shp2pgsql -s 2964 lakes.shp lakes_new | psql gis_data
![Page 31: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/31.jpg)
Исходные данные
http://gis-lab.info/qa/geosample.html
![Page 32: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/32.jpg)
Исходные данные
admin
oopt
poi-osm
road-l-osm
settlements
![Page 33: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/33.jpg)
Импорт shape-файлов в базу данных - SPIT
![Page 34: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/34.jpg)
pgAdmin – выделение прав
![Page 35: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/35.jpg)
pgAdmin – выделение прав
admin
![Page 36: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/36.jpg)
SQL-window для пользовательских запросов
![Page 37: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/37.jpg)
Вычисление длины линейных объектов
--length in kilometersSELECT "NAME" AS name, ST_Length_Spheroid("road-l-osm".the_geom,'SPHEROID["WGS 84",6378137,298.257223563]')/1000 AS length FROM "road-l-osm";--sum length in kilometersSELECT Sum(ST_Length_Spheroid("road-l-osm".the_geom,'SPHEROID["WGS 84",6378137,298.257223563]')/1000) AS sum_length FROM "road-l-osm";
![Page 38: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/38.jpg)
Вычисление длины линейных объектов по АТД
SELECTm."NAME",sum(ST_Length_Spheroid(r.the_geom,'SPHEROID["WGS 84",6378137,298.257223563]'))/1000 AS roads_kmFROM"road-l-osm" AS r,"admin" AS mWHERE ST_Intersects(m.the_geom, r.the_geom)GROUP BYm."NAME"ORDER BYm."NAME"
![Page 39: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/39.jpg)
Пространственные индексы
• B-Tree• R-Tree • GiST
CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] );
![Page 40: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/40.jpg)
Вычисление длины линейных объектов по АТД + GiST
-- Index: "sidx_road-l-osm_the_geom«-- DROP INDEX "sidx_road-l-osm_the_geom";CREATE INDEX "sidx_road-l-osm_the_geom" ON "road-l-osm" USING gist (the_geom);
![Page 41: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/41.jpg)
Вычисление площади
![Page 42: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/42.jpg)
Перепроецирование данных
![Page 43: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/43.jpg)
Перепроецирование данных
![Page 44: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/44.jpg)
Создание функции выбора зоны СК
![Page 45: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/45.jpg)
Создание колонки и запись значений площади
![Page 46: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/46.jpg)
Таблица атрибутов слоя с площадями для объектов
![Page 47: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/47.jpg)
Создание пространственной таблицы “poi”
-- Table: poiCREATE TABLE "poi"( gid serial NOT NULL, "NAME" character varying(64), the_geom geometry(Point,4326), CONSTRAINT "poi_pkey" PRIMARY KEY (gid))WITH ( OIDS=FALSE);ALTER TABLE "poi" OWNER TO admin;GRANT ALL ON TABLE "poi" TO admin;GRANT ALL ON TABLE "poi" TO public;
-- Sequence: poi_gid_seqALTER TABLE "poi_gid_seq" OWNER TO admin;GRANT ALL ON TABLE "poi_gid_seq" TO admin;GRANT ALL ON TABLE "poi_gid_seq" TO public;
![Page 48: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/48.jpg)
Загрузка пространственной таблицы “poi” в QGIS
![Page 49: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/49.jpg)
Создание объектов в слое “poi”, которые находятся в “oopt”
![Page 50: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/50.jpg)
Обновление количества объектов “poi” в слое “oopt”
--ALTER TABLE "oopt" ADD COLUMN count INTEGER;
UPDATE "oopt" tSETcount = calc.objectscountFROM (SELECTm."NAME_PRT_R",count(*) AS objectscountFROM"poi" AS r,"oopt" AS m WHERE ST_Intersects(m.the_geom, r.the_geom)GROUP BYm."NAME_PRT_R") calc WHERE t."NAME_PRT_R" = calc."NAME_PRT_R";
![Page 51: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/51.jpg)
Количество объектов “poi” в слое “oopt”
![Page 52: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/52.jpg)
Запуск SQL запроса через консоль
![Page 53: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/53.jpg)
Экспорт данных из базы данных в шейп-файл
![Page 54: Kleshnin A. PostGIS-open solution for spatial data-database](https://reader038.vdocuments.mx/reader038/viewer/2022102815/557f8063d8b42a55278b4c2f/html5/thumbnails/54.jpg)
Спасибо!Вопросы?