- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 185字
- 2021-07-02 22:52:21
Extracting spatial information from flat data
As we have some flat data already in our database, it's time to extract the spatial information. So far all the datasets, used Cartesian coordinate systems so our job is really straightforward:
drop table if exists data_import.earthquakes_subset_with_geom;
select
id,
"time",
depth,
mag,
magtype,
place,Points of Interest in TXT format
ST_SetSRID(ST_Point(longitude, latitude), 4326) as geom
into data_import.earthquakes_subset_with_geom
from data_import.earthquakes_csv;
This example extracts a subset of data and puts data into a new table with coordinates being expressed as a geometry type, rather than two columns with numeric data appropriate for Lon and Lat.
In order to quickly preview the data, we dump the table's content to KML using ogr2ogr (this is a little spoiler on the next chapter on exporting the data from PostGIS indeed):
ogr2ogr -f "KML" earthquakes_from_postgis.kml PG:"host=localhost port=5434 user=postgres dbname=mastering_postgis" data_import.earthquakes_subset_with_geom -t_srs EPSG:4326
Such KML can be viewed for example in Google Earth (you can use the original KML downloaded from USGS just as a cross check for the output data):

More examples of extracting the spatial data from different formats are addressed in the ETL chapter.
推薦閱讀
- 大數據戰爭:人工智能時代不能不說的事
- Linux Mint System Administrator’s Beginner's Guide
- 網頁編程技術
- 反饋系統:多學科視角(原書第2版)
- 教父母學會上網
- 模型制作
- 傳感器與新聞
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- C++程序設計基礎(上)
- 在實戰中成長:C++開發之路
- 智能鼠原理與制作(進階篇)
- ZigBee無線通信技術應用開發
- 漢字錄入技能訓練
- ROS Robotics By Example(Second Edition)
- Oracle Blockchain Quick Start Guide