- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 327字
- 2021-07-02 22:52:21
Importing vector data using ogr2ogr
ogr2ogr is the GDAL's vector transform utility. It is - not without reason - considered a Swiss Army knife for vector transformations. Despite its size, ogr2ogr can handle a wide range of formats and this makes it a really worthy tool.
We'll use ogr2ogr to import a few data formats other than SHP, although ogr2ogr can obviously import SHP too. For this scenario, we'll use some data downloaded earlier:
- OS GB address base in GML format
- OS GB code point polygons in MapInof MIF & TAB formats
- USGS earthquakes in KML format
Some of the most common ogr2ogr params are:
- -f: The format of the output (when importing to PostGIS it will be PostgreSQL).
- -nln: Assigns a name to the layer. In the case of importing the data to PostGIS this will be the table name.
- -select: Lets you specify a comma separated list of columns to pick.
- -where: Lets you specify a sql like query to filter out the data.
- append: Appends data to the output dataset.
- overwrite: Overwrites the output datasource - in case of PostgreSQL it will drop and re-create a table.
- s_srs: Specifies the input SRID.
- t_srs: Transforms coordinates to the specified SRID.
- a_srs: Specifies the output SRID.
- lco NAME=VALUE: Layer creation options - these are driver specific; for pgsql options, see http://www.gdal.org/drv_pg.html. The most commonly used layer creation options are:
- LAUNDER: This defaults to YES. It is responsible for converting column names into pgsql compatible ones (lower case, underscores).
- PRECISION: This defaults to YES. It is responsible for using numeric and char types over float and varchar.
- GEOMETRY_NAME: Defaults to wkb_geometry.
For a full list of ogr2ogr params, just type ogr2ogr.
Ogr2ogr has an accompanying utility called ogrinfo. This tool lets one inspect the metadata of a dataset. Verifying the metadata of any dataset prior to working with it is considered good practice and one should get into the habit of always using it before importing or exporting the data.
Ogr2ogr has an accompanying utility called ogrinfo. This tool lets one inspect the metadata of a dataset. Verifying the metadata of any dataset prior to working with it is considered good practice and one should get into the habit of always using it before importing or exporting the data.
推薦閱讀
- 32位嵌入式系統與SoC設計導論
- 工業機器人虛擬仿真實例教程:KUKA.Sim Pro(全彩版)
- 大數據時代的數據挖掘
- PyTorch深度學習實戰
- 自動生產線的拆裝與調試
- Visual C++編程全能詞典
- 網絡綜合布線設計與施工技術
- 控制系統計算機仿真
- 中國戰略性新興產業研究與發展·工業機器人
- 分數階系統分析與控制研究
- Word 2007,Excel 2007辦公應用融會貫通
- Salesforce Advanced Administrator Certification Guide
- Linux Shell Scripting Cookbook(Third Edition)
- Creating ELearning Games with Unity
- Instant Slic3r