This document provides an introduction to PostGIS and spatial databases. It discusses what a spatial database is, an overview of PostGIS, supported GIS programs, and the open source geostack. It also covers spatial data types, indexing, functions, installation of PostGIS, creation of spatial databases, importing GIS data, coordinate system settings and transformations.
- The document discusses PostGIS education provided by the Spatial Information Research Institute.
- It introduces PostGIS, an open source spatial database extender for PostgreSQL object-relational database. PostGIS adds support for geographic objects allowing location queries and geospatial processing.
- The document provides an overview of installing and setting up PostGIS, managing spatial databases, using spatial functions and applications like QGIS with PostGIS.
2021년 6월 15일에 LX국토정보공사 본사에서 강의한 자료입니다. 디지털 트윈 플랫폼과 관련한 국내외 동향을 살펴보고, 오픈소스와 개방형 표준 기반의 디지털 트윈 플랫폼에 대해 이야기했습니다. 이후 가이아쓰리디의 디지털 트윈 플랫폼인 mago3D와 그 활용처를 소개했습니다.
PyQGIS 개발자 쿡북(PyQGIS Developer Cookbook) 한국어 판 SANGHEE SHIN
PyQGIS Developer Cookbook의 한국어판입니다.
한국오픈소스GIS포럼의 지원으로 번역되었으며, 원본은 http://docs.qgis.org/2.8/en/docs/pyqgis_developer_cookbook/index.html 에서 확인할 수 있습니다. 한국어 웹 버젼은 http://docs.qgis.org/2.8/ko/docs/pyqgis_developer_cookbook/index.html 에서 보실 수 있습니다.
지은이: QGIS 프로젝트팀
번역: 권용찬
펴낸이: 한국오픈소스GIS포럼
문서라이선스: Creative Commons Attribution-ShareAlike 3.0 licence (CC BY-SA)
1. 속성 편집
2. XYZ 타일 추가
3. 벡터데이터 구축
4. 벡터 조인
5. 지오패키지 구축
12주간 원주시에서 진행 중인 'QGIS 공간정보 스터디' 2주차 학습자료입니다. 매주 월요일 저녁 7시 30분, 국립공원연구원 4층 대회의실에서, 스터디 불참자를 위한 녹화 영상은 '공간정보 스터디' 유튜브 채널(https://www.youtube.com/channel/UClhOyfz6d4EgQmUmQ_UeeHw)'을 통해 해당 주 중에 게시됩니다.
QGIS Training Manual이 번역, 인쇄되어 나왔습니다. QGIS Training Manual의 번역과 감수 등에 고생하신 권용찬, 장병진, 김서인 님 등의 노고에 깊은 감사 드립니다.
책과 편집이 동일한 인쇄본 PDF는 다음 링크에서도 다운 받으실 수 있습니다.
http://open.gaia3d.com/doc/QGIS/manual/QgisTrainingManual_KR_4print.pdf
위의 출력본은 최상의 인쇄를 위해 링크 등이 제거되어 있습니다. 때문에 전자책으로 보실 분은 다음에서 받으시면 됩니다.
http://docs.qgis.org/2.2/pdf/ko/QGIS-2.2-QGISTrainingManual-ko.pdf
웹에서 보시기를 원하시면 다음의 링크를 이용하시면 됩니다.
http://docs.qgis.org/2.2/ko/docs/training_manual/
본 QGIS Training Manual의 번역, 출판은 한국오픈소스GIS포럼의 지원으로 이뤄졌으며, 이에 대해 깊은 감사 드립니다.
This document provides an agenda and background information for a presentation on PostgreSQL. The agenda includes topics such as practical use of PostgreSQL, features, replication, and how to get started. The background section discusses the history and development of PostgreSQL, including its origins from INGRES and POSTGRES projects. It also introduces the PostgreSQL Global Development Team.
The document provides details on installing and configuring PostGIS on Windows. It describes downloading and installing PostgreSQL, PostGIS, and pgAdmin. The OpenGeo Suite is introduced as an alternative to installing components individually. Steps are outlined to add a PostgreSQL server in pgAdmin and begin using the query tool and other pgAdmin features to manage and interact with spatial databases.
- KOPSS Open API was first designed in 2009 to allow various GIS engines to access KOPSS and provide a common foundation.
- The API consists of around 120 processes organized into geometry, vector, raster, statistics, and custom model analysis categories.
- The API supports OGC standards including WMS, WFS, WCS, and WPS, and uses formats like GML, GeoTIFF, and KML. Processes include spatial analysis, geoprocessing, statistics, and model-specific functions.
- The API has some limitations such as supporting only parts of the OGC filter standard and requiring SRS information in geometries.
2021년 6월 15일에 LX국토정보공사 본사에서 강의한 자료입니다. 디지털 트윈 플랫폼과 관련한 국내외 동향을 살펴보고, 오픈소스와 개방형 표준 기반의 디지털 트윈 플랫폼에 대해 이야기했습니다. 이후 가이아쓰리디의 디지털 트윈 플랫폼인 mago3D와 그 활용처를 소개했습니다.
PyQGIS 개발자 쿡북(PyQGIS Developer Cookbook) 한국어 판 SANGHEE SHIN
PyQGIS Developer Cookbook의 한국어판입니다.
한국오픈소스GIS포럼의 지원으로 번역되었으며, 원본은 http://docs.qgis.org/2.8/en/docs/pyqgis_developer_cookbook/index.html 에서 확인할 수 있습니다. 한국어 웹 버젼은 http://docs.qgis.org/2.8/ko/docs/pyqgis_developer_cookbook/index.html 에서 보실 수 있습니다.
지은이: QGIS 프로젝트팀
번역: 권용찬
펴낸이: 한국오픈소스GIS포럼
문서라이선스: Creative Commons Attribution-ShareAlike 3.0 licence (CC BY-SA)
1. 속성 편집
2. XYZ 타일 추가
3. 벡터데이터 구축
4. 벡터 조인
5. 지오패키지 구축
12주간 원주시에서 진행 중인 'QGIS 공간정보 스터디' 2주차 학습자료입니다. 매주 월요일 저녁 7시 30분, 국립공원연구원 4층 대회의실에서, 스터디 불참자를 위한 녹화 영상은 '공간정보 스터디' 유튜브 채널(https://www.youtube.com/channel/UClhOyfz6d4EgQmUmQ_UeeHw)'을 통해 해당 주 중에 게시됩니다.
QGIS Training Manual이 번역, 인쇄되어 나왔습니다. QGIS Training Manual의 번역과 감수 등에 고생하신 권용찬, 장병진, 김서인 님 등의 노고에 깊은 감사 드립니다.
책과 편집이 동일한 인쇄본 PDF는 다음 링크에서도 다운 받으실 수 있습니다.
http://open.gaia3d.com/doc/QGIS/manual/QgisTrainingManual_KR_4print.pdf
위의 출력본은 최상의 인쇄를 위해 링크 등이 제거되어 있습니다. 때문에 전자책으로 보실 분은 다음에서 받으시면 됩니다.
http://docs.qgis.org/2.2/pdf/ko/QGIS-2.2-QGISTrainingManual-ko.pdf
웹에서 보시기를 원하시면 다음의 링크를 이용하시면 됩니다.
http://docs.qgis.org/2.2/ko/docs/training_manual/
본 QGIS Training Manual의 번역, 출판은 한국오픈소스GIS포럼의 지원으로 이뤄졌으며, 이에 대해 깊은 감사 드립니다.
This document provides an agenda and background information for a presentation on PostgreSQL. The agenda includes topics such as practical use of PostgreSQL, features, replication, and how to get started. The background section discusses the history and development of PostgreSQL, including its origins from INGRES and POSTGRES projects. It also introduces the PostgreSQL Global Development Team.
The document provides details on installing and configuring PostGIS on Windows. It describes downloading and installing PostgreSQL, PostGIS, and pgAdmin. The OpenGeo Suite is introduced as an alternative to installing components individually. Steps are outlined to add a PostgreSQL server in pgAdmin and begin using the query tool and other pgAdmin features to manage and interact with spatial databases.
- KOPSS Open API was first designed in 2009 to allow various GIS engines to access KOPSS and provide a common foundation.
- The API consists of around 120 processes organized into geometry, vector, raster, statistics, and custom model analysis categories.
- The API supports OGC standards including WMS, WFS, WCS, and WPS, and uses formats like GML, GeoTIFF, and KML. Processes include spatial analysis, geoprocessing, statistics, and model-specific functions.
- The API has some limitations such as supporting only parts of the OGC filter standard and requiring SRS information in geometries.
The document discusses spatial analysis and visualization using open source GIS and OGC standards. It provides examples of 1) a national land environment assessment map service, 2) an integrated epidemiological investigation analysis system, and 3) a Web Processing Service demo. It also discusses descriptive statistics, spatial pattern analysis, spatial interpolation, vector and raster geoprocessing tools, and setting up a GeoServer and PostGIS system to support WMS, WFS, and WPS services.
1. Geoscript allows the addition of spatial capabilities to scripting languages like Groovy and Python through the Geotools library, making GIS development simpler through batching and fast prototyping.
2. uDig is an open source desktop GIS application that supports geoscripting and spatial processing through tools like JGrasstools, and provides a scripting editor to write and run geoscripts.
3. Geoscripts in uDig can access vector and raster data, perform spatial operations, and use tools like JGrasstools for hydrological modeling tasks through a simple template-based process.
Java 기반의 오픈 소스 GIS 맵서버인 GeoServer 2.4 버젼 한국어 사용자 지침서입니다.
본 사용자 지침서는 한국정보통신산업진흥원(NIPA)이 시행한 공개SW커뮤니티 출판·번역지원 사업을 통해 번역, 출판되었습니다.
본 문서의 라이선스는 Creative-Commons-Attribution 3.0 Unported를 따릅니다.
초대용량의 3차원 BIM/AEC/GIS 자료를 웹에서 시각화하고 관리할 수 있는 오픈소스 프로젝트 mago3D(http://www.mago3d.com) 기술 워크샵 자료(한국어)입니다.
mago3D에 대한 개요, 설치, 파일 변환, 활용 방법 등에 대해 설명하고 있습니다. 스스로 따라해 보면서 실습할 수 있도록 구성했습니다. mago3D에 관심 있는 분들은 참고하시기 바랍니다.
감사합니다.
The document provides information about a lecture on using QGIS and the ISCGM Global Map 2013. It contains the following information:
- The lecturer's name is Minpa Lee from Mango System inc. and their contact information is provided.
- An overview of QGIS and the ISCGM Global Map is given. Details on installing QGIS and Google Earth are also outlined.
- Instructions are provided on using QGIS including exploring the GUI, working with vector and raster data, and extending QGIS using plugins.
- The document describes how to edit and work with the Global Map data in QGIS including setting the environment, using the digitizing toolbar, and importing/exporting data.
2. 목차
1. PostGIS 개요
2. PostGIS 설치 및 환경 설정
3. 공간 데이터베이스의 생성
4. GIS 자료의 Import
5. 좌표계 설정 및 변경
6. PostGIS Objects & Function
7. PostGIS 함수 활용
8. Backup & Restore
9. pgRouting 소개
2
3. 1.1 What is a Spatial Database?
1.2 PostGIS
1.3 PostGIS를 지원하는 GIS 프로그램들
3
4. Spatial databases store/manipulate
spatial objects
– data types, indexes, and functions
Spatial data types
shapes - point, line, polygon
Spatial indexing
efficient processing of spatial operations
Spatial functions,
querying of spatial properties and relationships.
4
8. 2.1 PostGIS 설치
2.2 Dashboard
2.3 Starting and Stopping
2.4 환경 설정
2.5 PostGIS Web Administration
8
9. 1. PostgreSQL 단독 설치
Application Stack Builder
Binaries 수동 설치
http://postgis.refractions.net/download
pgRouting을 사용하는 경우 8.4.x 버전 설치할 것
http://www.pgrouting.org/download.html
2. OpenGeoSuite 통합 설치
PostGIS와 함께 설치
OpenGeoSuite 2.5 = PostgreSQL 8.4.9 + PostGIS
1.5.4 + GeoServer + GeoWebCache + GeoExplorer +
Client SDK
http://opengeo.org/technology/suite/download/
9
11. PostgreSQL + PostGIS Binaries
아래 예는 postgreSQL 9.0 버전에 PostGIS 1.5.4.2 버전을
설치하는 과정
http://postgis.refractions.net/download/windows/ 이동
설치된 PostgreSQL 버전과 호환하는 PostGIS 1.5.x 바이
너리 버전 다운로드, ex) postgis-pg90-binaries-1.5.4-
2.zip
압축 해제 후 postgis-pg90-binaries-1.5.4-2 폴더로 이동
makepostgisdb.bat 파일의 연결정보 및 경로를 수정
makepostgisdb.bat 파일 실행하여 PostGIS 설치
11
12. makepostgisdb.bat 파일
set PGPORT=5432
set PGHOST=localhost
set PGUSER=postgres
set PGPASSWORD=postgis
set THEDB=template_postgis
set PGBIN=C:Program FilesPostgreSQL9.0bin
set PGLIB=C:Program FilesPostgreSQL9.0lib
set POSTGISVER=1.5
xcopy bin*.* "%PGBIN%"
xcopy /I /S binpostgisgui* "%PGBIN%postgisgui"
xcopy lib*.* "%PGLIB%"
"%PGBIN%psql" -c "CREATE DATABASE %THEDB%"
"%PGBIN%psql" -d "%THEDB%" -c "CREATE LANGUAGE plpgsql"
"%PGBIN%psql" -d "%THEDB%" -f "sharecontribpostgis-%POSTGISVER%postgis.sql"
"%PGBIN%psql" -d "%THEDB%" -f "sharecontribpostgis-%POSTGISVER%spatial_ref_sys.sql"
"%PGBIN%psql" -d "%THEDB%" -f "sharecontribpostgis-%POSTGISVER%postgis_comments.sql"
REM Uncomment the below line if this is a template database
REM "%PGBIN%psql" -d "%THEDB%" -c "UPDATE pg_database SET datistemplate = true WHERE datname =
'%THEDB%';GRANT ALL ON geometry_columns TO PUBLIC; GRANT ALL ON spatial_ref_sys TO PUBLIC―
pause
12
26. 도구 설명
pgAdmin 도구에 새로운 서버를 추가합니다.
객체의 정보를 생성, 수정, 갱신, 삭제 후 새로고침 합니다.
테이블 등의 객체의 등록정보를 확인하거나 수정합니다.
선택된 객체와 같은 형태의 새로운 객체를 생성합니다.
선택된 객체를 삭제합니다.
SQL을 실행할 수 있는 Query 도구를 불러옵니다.
선택된 테이블을 편집할 수 있는 테이블 편집기를 불러옵니다.
필터를 적용해서 테이블을 편집할 수 있는 테이블 편집기를 불러옵니다.
Vacuum, Analyze 등 테이블 유지에 필요한 도구를 불러옵니다.
26
28. 이름: seoul
오너: postgres
인코딩: UTF8
Template: template_postgis
CREATE DATABASE seoul
WITH ENCODING='UTF8'
TEMPLATE=template_postgis
CONNECTION LIMIT=-1;
28
31. spatial_ref_sys table
Table "public.spatial_ref_sys"
Column | Type | Modifiers
-----------+-------------------------+-----------
srid | integer | not null
auth_name | character varying(256) |
auth_srid | integer |
srtext | character varying(2048) |
proj4text | character varying(2048) |
Indexes:
"spatial_ref_sys_pkey" PRIMARY KEY, btree (srid)
31
32. geometry_columns table
Table "public.geometry_columns"
Column | Type | Modifiers
-------------------+------------------------+-----------
f_table_catalog | character varying(256) | not null
f_table_schema | character varying(256) | not null
f_table_name | character varying(256) | not null
f_geometry_column | character varying(256) | not null
coord_dimension | integer | not null
srid | integer | not null
type | character varying(30) | not null
Indexes:
"geometry_columns_pk" PRIMARY KEY, btree
(f_table_catalog, f_table_schema, f
_table_name, f_geometry_column)
32
56. 4.1.1. OpenGIS WKB and WKT
4.1.2. PostGIS EWKB, EWKT and Canonical Forms
4.1.3. SQL-MM Part 3
The GIS objects supported by PostGIS are a superset of the "Simple
Features" defined by the OpenGIS Consortium (OGC). As of version 0.9,
PostGIS supports all the objects and functions specified in the OGC
"Simple Features for SQL" specification.
PostGIS extends the standard with support for 3DZ,3DM and 4D
coordinates.
56
72. 공간테이블 생성하기
공간인덱싱 생성하기
공간테이블 삭제하기
공간 뷰(View) 생성 후 등록하기
SQL을 이용하여 공간테이블 생성 후 등록하기
72
73. cityhall 이라는 공간 테이블을 생성하고 다음의 정보를 입력
X=197977.3885 , Y=451601.1444, city_name =서울
Function
AddGeometryColumn( <schema_name>, <table_name>, <column_name>, <srid>, <type>,
<dimension> )
AddGeometryColumn( <table_name>, <column_name>, <srid>, <type>, <dimension> )
CREATE TABLE cityhall (city_name VARCHAR);
SELECT AddGeometryColumn('cityhall', 'the_geom', 2097, 'POINT', 2 );
INSERT INTO cityhall (the_geom, city_name) VALUES
(ST_GeomFromText('POINT(197977.3885 451601.1444)', 2097), '서
울');
http://postgis.org/docs/ch04.html#OpenGISWKBWKT
73
74. 위에서 생성한 cityhall 테이블에 공간인덱싱을 생성
SQL
CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] );
CREATE INDEX spatial_cityhall_the_geom ON public.cityhall USING
GIST(the_geom);
http://postgis.org/docs/ch04.html#id2628148
74
75. 위에서 생성한 cityhall 테이블을 삭제
일반적인 과정
Remove refs from geometry_columns table
Remove table
Function
DropGeometryTable(varchar table_name);
DropGeometryTable(varchar schema_name, varchar table_name);
DropGeometryTable(varchar catalog_name, varchar schema_name,
varchar table_name);
SELECT DropGeometryTable('public', 'cityhall');
75
76. 읍면동 행정경계(admin_emd)를 이용하여 종로구에 해당하는 읍면동의 중
심점을 admin_emd_point View로 등록
Function
CREATE OR REPLACE VIEW, DROP VIEW
ST_Centroid(geometry g1)
Populate_Geometry_Columns()
CREATE OR REPLACE VIEW admin_emd_point AS
SELECT
gid, ST_Centroid(the_geom) as the_geom, sgg_nm,
emd_cd, emd_nm, pop2008, pop_den
FROM admin_emd
WHERE sgg_nm = '종로구';
SELECT Populate_Geometry_Columns();
76
77. 시군구 행정경계(admin_sgg)를 이용하여 종로구에 해당하는 시군구 폴리
곤과 Intersects되는 도로(road_link2)를 Clip하여 새로운 테이블로 생성
CREATE TABLE clip_road_link AS
SELECT
ST_Intersection(r.the_geom, a.the_geom) as the_geom,
ST_Length(r.the_geom) as new_length,
a.sgg_cd as sgg_cd, a.sgg_nm as sgg_nm, r.road_name as
road_name, r.link_id as link_id
FROM
road_link2 as r,
admin_sgg as a
WHERE a.sgg_nm = '종로구' AND ST_Intersects(r.the_geom,
a.the_geom);
SELECT Populate_Geometry_Columns();; 77
80. 1. 서울특별시 중구의 행정경계(admin_sgg) 면
적은 얼마인가? 단위는 ㎢로 표현하시오.
SELECT ST_Area(the_geom) / 1000000 AS area
FROM admin_sgg
WHERE sgg_nm = '중구'
80
81. 2. 도로 레이어(road_link2) 중 6차선(lanes) 이
상의 도로의 길이는 얼마인가? 단. ㎞로 표현하
시오.
SELECT SUM(ST_Length(the_geom)) / 1000 AS
km_roads
FROM road_link2
WHERE lanes >= 6
81
82. 3. 서울시의 읍면동(admin_emd) 중 면적이 가
장 큰 상위 10개를 선택하여 읍면동이름 및 면
적값을 조회하시오.
SELECT emd_nm, ST_Area(the_geom) as area
FROM admin_emd
ORDER BY area DESC
LIMIT 10
82
83. 4. 강(river) 레이어 중 hole을 가진 강은?
SELECT *
FROM river
WHERE ST_NumInteriorRings(the_geom) > 0
83
84. 1. 좌표 X = 197215 Y = 447711 지점에서 1KM
반경 내에 있는 대형매장(stores)은 무엇인가?
ST_Distance, ST_Dwithin
SELECT *
FROM stores
WHERE
ST_Distance(the_geom, ST_GeomFromTex
t('POINT(197215 447711)', 2097)) < 1000
84
85. 2. 좌표 X = 197215 Y = 447711 지점에서 1KM
반경 내에 있는 대형매장(stores)은 무엇인가?
SELECT *
FROM stores
WHERE ST_DWithin(the_geom,
ST_GeomFromText('POINT(197215 447711)',
2097), 1000)
85
86. 2. 좌표 X = 197215 Y = 447711 지점에서 1KM 반
경 내에 있는 대형매장(stores)은 무엇인가?
단. ST_Buffer, ST_Intersects 함수를 사용해서 구하
시오.
SELECT *
FROM stores
WHERE ST_Intersects(the_geom,
ST_Buffer(ST_GeomFromText('POINT(197215
447711)', 2097), 1000))
86
87. 1. 한강(river, river_cd = '1')과 인접한 서울시의
구(admin_sgg)는?
SELECT a.sgg_nm
FROM admin_sgg As a, river r
WHERE r.river_cd = '1' AND
ST_Intersects(a.the_geom, r.the_geom)
GROUP BY a.sgg_nm
87
88. 2. 영등포구(admin_sgg)에 속한 대형매장
(stores)은 무엇인가?
SELECT *
FROM stores s, admin_sgg a
WHERE a.sgg_nm = '영등포구' AND
ST_Within(s.the_geom, a.the_geom)
88
89. 3. 소방서(firestation)에서 500미터 반경 내의 도로
중 가장 가까운 도로(road_link2)와 거리를 계산하
시오.
SELECT DISTINCT ON(f.nam) f.nam, r.roadname_a,
r.lanes, ST_Distance(r.the_geom, f.the_geom)
As dist
FROM firestation AS f LEFT JOIN road_link2 As r ON
ST_DWithin(r.the_geom, f.the_geom, 500)
ORDER BY f.nam, ST_Distance(r.the_geom,
f.the_geom)
89
90. 1. 서울시 구별(admin_sgg) 6차선 이상 도로(road_link2, lanes)의 길
이를 구하시오.
SELECT
a.sgg_nm as sgg_nm,
SUM(ST_Length(ST_Intersection(r.the_geom,
a.the_geom))) / 1000 as road_length
FROM
road_link2 as r,
admin_sgg as a
WHERE r.lanes >= 6 AND ST_Intersects(r.the_geom,
a.the_geom)
GROUP BY sgg_nm
ORDER BY road_length DESC
90
91. 1. 서울특별시 중구의 중심점은 어디인가?
단, 경위도로 표시하라
SELECT
ST_AsText(ST_Transform(ST_Centroid(the_
geom), 4326))
FROM admin_sgg
WHERE sgg_nm = '중구'
91
97. pgRouting 은 PostGIS/PostgreSQL에 라우팅 기능을 추한 PostGIS의
Extension
Camptocamp SA 에 의해 시작된 pgDijkstra의 확장판이며 Orkney 에
의해 확장
현재 Georepublic 에 의해 개발 및 유지 관리되고 있음
pgRouting는 GPLv2 라이선스 하에 사용 가능하며 개인, 기업 및 조직
의 커뮤니티에 의해 지원
데이터베이스 기반 라우팅 접근 방법의 장점
데이터와 속성은 Quantum GIS, uDig 그리고 JDBC, ODBC 또는
Pl/pgSQL 등 다양한 클라이언트에 의해 직접 갱신 가능하며, 클라이언트
는 PC나 모바일 기기가 될 수 있음
데이터 변경 내용은 라우팅 엔진을 통해 즉시 반영되며, 재계산이 필요
없음
―cost‖ 파라미터는 SQL을 통해 동적으로 계산되고 그 값은 다중 필드 및
테이블의 다양한 값을 사용할 수 있음
97
98. Shortest Path Dijkstra
휴리스틱 기법(heuristic method)을 사용하지 않는 최단거리 알고리즘, 알고리즘을 개
발한 Dr. Edsger Wybe Dijkstra 교수의 이름을 사용.
Shortest Path A-Star(A*)
휴리스틱 기법을 사용하며 대용량 데이터셋에 적합한 최단거리 알고리즘
Shortest Path Shooting-Star(Shooting*)
휴리스틱 기법을 사용하며 turn restrictions(U-turn, P-turn, left-turn 등), 신호등, 편도
차선 등의 시제 도로 네트워크를 위한 최단거리 알고리즘
Traveling Salesperson Problem (TSP)
최대 40개의 포인트를 지원하는 Traveling Salesman Problem(TSP, 외판원 문제) 알고리
즘
Driving Distance calculation (Isolines)
도로네트워크에 기반을 둔 특정지점에서 특정 시간내에 도달 할 수 있는 영역. Service
area
98
99. 도로 네트워크 데이터셋은 최소한 다음의 정보를
포함
Road link ID (gid)
Road class (class_id): primary roads, secondary roads,
and local roads 등 Hierarchies
Road link length (length): Cost - Length, Travel Time
등
Road name (name)
Road geometry (the_geom)
Road restrictions & rule (optional): Lanes, Speed Limit,
traffic light, one-way streets 등
99
100. 공공기관에서 생산하는 도로네트워크로 활용 가능한
데이터는 다음의 4가지가 가능
1. ITS 전국표준노드링크: http://nodelink.its.go.kr/
2. UTIS 통합노드링크: http://www.utis.go.kr/
3. 국가교통DB센터 노드링크: http://www.ktdb.go.kr/
4. 새주소 도로구간
1. 2. 3. 데이터는 1:5000 축척을 기반으로 제작되었으
며 주요 도로(고속국도/일반국도/지방도 수준) 중심으
로 상세한 지역에서의 활용은 어려움
4. 새주소 도로구간은 도로중심선으로 구축되어 있으
나 네트워크 분석자료로 활용하기 위해서는 위상구조
편집이 필요하며 도로에 대한 상세정보(Restrictions &
rules)는 없음
100
102. PostgreSQL 8.4 버전을 대상으로 하며 2012년 8월 현재 Windows에서
PostgreSQL 9.0 이상은 지원하지 않음
설치에 대한 더 자세한 내용은 다음을 참고
PgRouting 1.02 on Win32
Installing PostgreSQL 8.4, PostGIS 1.4.1, and pgRouting 1.0.3 on Ubuntu 9.10
다운로드
http://www.pgrouting.org/download.html 이동
Source Packages에서 pgrouting-1.05.tar.gz 다운로드
Windows Binaries에서 pgRouting-1.03_pg-8.4.2.zip 다운로드
특정폴더(C:OpenGeoSuitepgrouting)에 pgRouting-1.03_pg-8.4.2.zip 파일 압축 해제
doc : 설치 도움말 포함
lib : pgRouting 라이브러리
share : 설치 sql
share 폴더에는 Shortest Path(Dijkstra, A-Star, Shooting-Star) 알고리즘만 포함
위 3 폴더를 C:Program FilesOpenGeoOpenGeo Suitepgsql8.4 폴더에 복사
pgrouting-1.05.tar.gz 파일 열어 core/sql/matching.sql 압축풀기
matching.sql은 Utility 함수를 포함하고 있음
102
103. template_routing 이라는 라우팅 템플릿 데이터베이스를
생성
Query 윈도우에서 다음을 실행
CREATE DATABASE template_routing
WITH ENCODING='UTF8'
TEMPLATE=template_postgis
CONNECTION LIMIT=-1;
103
105. 다음은 라우팅 데이터베이스 생성 후 도로 shapefile을 이용해 네트워크
데이터를 생성하는 과정
Routing 데이터베이스 생성
CREATE DATABASE routing
WITH ENCODING='UTF8'
TEMPLATE=template_routing
CONNECTION LIMIT=-1;
샘플 데이터 변환
샘플 데이터셋의 road_link2.shp를 road_link로 변환
토폴로지 생성
ALTER TABLE road_link ADD COLUMN source integer;
ALTER TABLE road_link ADD COLUMN target integer;
SELECT assign_vertex_id('road_link', 0.1, 'the_geom', 'gid');
CREATE INDEX road_link_source_idx ON road_link("source");
CREATE INDEX road_link_target_idx ON road_link("target");
105
106. Dijkstra 알고리즘은 pgRouting에 구현된 최초의 알
고리즘
source 와 target ID, id 속성과 cost 이외의 속성을
필요로 하지 않음
directed와 undirected 그래프를 구분할 수 있으며,
네트워크의 역방향 cost(reverse cost) 유무를 설정
할 수 있음
Cost를 도로의 길이로 사용하는 경우
ALTER TABLE road_link ADD COLUMN length double precision;
UPDATE road_link SET length = ST_Length(the_geom);
ALTER TABLE road_link ADD COLUMN reverse_cost double precision;
UPDATE road_link SET reverse_cost = length;
106
107. Dijkstra shortest_path 함수 선언
CREATE OR REPLACE FUNCTION shortest_path(
sql text,
source_id integer,
target_id integer,
directed boolean,
has_reverse_cost boolean)
RETURNS SETOF path_result
sql: 다음의 컬럼을 포함한 결과를 생성하는 SQL query
SELECT id, source, target, cost FROM edge_table
* id: integer, edge 테이블의 identifier, 일반적으로 gid
* source: integer, source vertex의 identifier
* target: integer, target vertex의 identifier
* cost: float8 value, 경로 탐색 비용(cost)에 사용되는 edge의 속성(-값의 cost를 가지는 edge는 그
래프 탐색에서 제외).
* reverse_cost (옵션): 역방향 탐색(reverse traversal)에 사용되는 edge의 속성, 방향성이 true이고
has_reverse_cost가 true일 경우에만 사용
source_id: integer 경로탐색 시점의 노드 id
target_id: integer 경로탐색 종점의 노드 id
directed: 그래프의 방향성이 정해진 경우 true
has_reverse_cost: true이면 역방향 탐색에 SQL의 reverse_cost 컬럼을 사용
107
108. 다음은 네트워크의 길이(length)를 cost로 사용하며, 방향성을 무시하여 노드 id
3에서 7까지의 경로를 탐색하는 예
SELECT *
FROM shortest_path('
SELECT
gid AS id,
source::integer,
target::integer,
length::double precision AS cost
FROM road_link',
3,
7,
false,
false);
Wrapper WITHOUT bounding box
SELECT gid AS edge_id, ST_Length(the_geom) AS cost FROM dijkstra_sp('road_link', 3, 7);
Wrapper WITH bounding box
SELECT gid AS edge_id, ST_Length(the_geom) AS cost FROM dijkstra_sp_delta('road_link', 3, 7, 500);
108
109. QIS에서 확인하기
QGIS를 실행합니다.
Add PostGIS Layer -> PosotGIS 연결정보 생성 후 road_link 및
vertices_tmp 레이어를 배경 레이어로 추가합니다.
Add PostGIS Layer -> road_link 레이어를 선택한 후 Build query
버튼을 눌러 다음을 SQL where clause에 추가합니다.
―gid‖ IN (SELECT gid FROM dijkstra_sp('road_link', 3, 7))
109
110. 유용한 함수 – matching.sql
POINT(211894.692 447070.0273)에서 50미터 반경 내 가장 가까운 링
크의 soruce, target 노드 정보를 검색
SELECT gid, source, target
FROM road_link
WHERE gid IN (SELECT
find_nearest_link_within_distance(ST_AsText(ST_GeomFromText('P
OINT(211894.692 447070.0273)', 2097)), 300, 'road_link'));
POINT(211894.692 447070.0273)에서 50미터 반경 내 가장 가까운 노
드의 ID와 좌표를 검색
SELECT id, ST_AsText(the_geom) AS wkt
FROM vertices_tmp
WHERE id IN (SELECT
find_nearest_node_within_distance(ST_AsText(ST_GeomFromText('
POINT(211894.692 447070.0273)', 2097)), 50, 'road_link'))
110
111. 탐색 경로의 도로 정보 확인
SELECT edge_id, vertex_id, cost, roadname_a, ST_AsText(the_geom) as
wkt
FROM road_link
JOIN
(SELECT vertex_id, edge_id, cost FROM shortest_path('
SELECT gid AS id,
source::integer AS source,
target::integer AS target,
length::double precision AS cost
FROM road_link',
1385,
2059,
false,
false)) AS route
ON
road_link.gid = route.edge_id;
111
112. 탐색 경로 주변 100미터 이내의 stores 찾기
SELECT *
FROM stores
WHERE ST_Intersects(stores.the_geom,
(SELECT ST_Buffer(ST_Union(road_link.the_geom), 2000)
FROM shortest_path('SELECT gid as id,
source::integer,
target::integer,
length::double precision as cost
FROM road_link', 3, 7, false, false) AS sp
INNER JOIN road_link ON road_link.gid = sp.edge_id));
112