- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 360字
- 2021-07-02 22:52:22
Importing KML
As usual, we'll start with the dataset's metadata checkup:
ogrinfo 2.5_day_age.kml
The output shows that there is more than one layer:
INFO: Open of `2.5_day_age.kml'
using driver `LIBKML' successful.
1: Magnitude 5
2: Magnitude 4
3: Magnitude 3
4: Magnitude 2
Therefore, in order to review metadata for each layer at once, the following command should be used:
ogrinfo 2.5_day_age.kml -al -so
The output of the previous command is rather longish, so we'll truncate it a bit and only show the info for the first layer:
INFO: Open of `2.5_day_age.kml'
using driver `LIBKML' successful.
Layer name: Magnitude 5
Geometry: Unknown (any)
Feature Count: 2
Extent: (-101.000100, -36.056300) - (120.706400, 13.588200)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9108"]],
AUTHORITY["EPSG","4326"]]
Name: String (0.0)
description: String (0.0)
timestamp: DateTime (0.0)
begin: DateTime (0.0)
end: DateTime (0.0)
altitudeMode: String (0.0)
tessellate: Integer (0.0)
extrude: Integer (0.0)
visibility: Integer (0.0)
drawOrder: Integer (0.0)
icon: String (0.0)
snippet: String (0.0)
This time, EPSG information is available, so we do not have to worry; ogr2ogr will create extra SRID definition in the database.
Once we've confirmed that this is the exact dataset we'd like to import, we can continue with the following command:
ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5434 user=postgres dbname=mastering_postgis" 2.5_day_age.kml -nln data_import.usgs_earthquakes_kml -lco GEOMETRY_NAME=geom -append
Note the append param in the command earlier. This is required because our KML has more than one layer and ogr2ogr is importing them one by one. Without the append param, only the first layer would be imported and then ogr2ogr would fail with a similar output:
FAILED: Layer data_import.usgs_earthquakes_kml already exists, and -append not specified.
Consider using -append, or -overwrite.
ERROR 1: Terminating translation prematurely after failed
translation of layer Magnitude 4 (use -skipfailures to skip errors)
FAILED: Layer data_import.usgs_earthquakes_kml already exists, and -append not specified.
Consider using -append, or -overwrite.
ERROR 1: Terminating translation prematurely after failed
translation of layer Magnitude 4 (use -skipfailures to skip errors)
The cmd output should be similar to:
WARNING: Layer creation options ignored since an existing layer is
being appended to.
WARNING: Layer creation options ignored since an existing layer is
being appended to.
WARNING: Layer creation options ignored since an existing layer is
being appended to.
At this stage, the KML dataset should have made it to our PostGIS database.
推薦閱讀
- Microsoft Power BI Quick Start Guide
- 高性能混合信號(hào)ARM:ADuC7xxx原理與應(yīng)用開發(fā)
- 一本書玩轉(zhuǎn)數(shù)據(jù)分析(雙色圖解版)
- MCSA Windows Server 2016 Certification Guide:Exam 70-741
- JMAG電機(jī)電磁仿真分析與實(shí)例解析
- Spark大數(shù)據(jù)技術(shù)與應(yīng)用
- 四向穿梭式自動(dòng)化密集倉儲(chǔ)系統(tǒng)的設(shè)計(jì)與控制
- 愛犯錯(cuò)的智能體
- 單片機(jī)技術(shù)一學(xué)就會(huì)
- 基于RPA技術(shù)財(cái)務(wù)機(jī)器人的應(yīng)用與研究
- 基于人工免疫原理的檢測(cè)系統(tǒng)模型及其應(yīng)用
- 案例解說Delphi典型控制應(yīng)用
- Advanced Deep Learning with Keras
- PyTorch深度學(xué)習(xí)
- 網(wǎng)頁設(shè)計(jì)與制作