官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 托克逊县| 神农架林区| 广平县| 讷河市| 衢州市| 清水河县| 翼城县| 民勤县| 道孚县| 米易县| 随州市| 旅游| 商丘市| 怀远县| 乡城县| 巩留县| 兖州市| 阿拉善左旗| 兰坪| 句容市| 斗六市| 平舆县| 新河县| 义乌市| 双辽市| 北碚区| 襄垣县| 东辽县| 云霄县| 美姑县| 仁布县| 沁水县| 庐江县| 建瓯市| 安达市| 潍坊市| 上杭县| 青浦区| 繁峙县| 商洛市| 五峰|