`
cryolite
  • 浏览: 580372 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

OGR vector data tips and tricks

阅读更多
OGR vector data tips and tricks
by markusN

Get vector map extent
You can easily grep the map extent of a vector map (bounding box):
ogrinfo /cdrom/ITALY_GC.SHP ITALY_GC | grep Extent
Extent: (9.299460, 43.787362) - (13.911350, 47.070188)

Merge of two SHAPE files
Merge of two SHAPE files 'file1.shp' and 'file2.shp' into a new file 'file_merged.shp' is performed like this:
ogr2ogr file_merged.shp file1.shp
ogr2ogr -update -append file_merged.shp file2.shp -nln file_merged file2

The second command is opening file_merged.shp in update mode, and trying to find existing layers and append the features being copied. The -nln option sets the name of the layer to be copied to.

Vector map reprojection
We reproject from the source projection (as defined in .prj file) to WGS84/LL:
ogr2ogr vmap0rd_ll.shp -t_srs "EPSG:4326" vmap0rd.shp

If the .prj file is missing, you can use the 'epsg_tr.py' utility to create it if you know the EPSG code:
epsg_tr.py -wkt 4326 > cities.prj

Reproject to current GRASS location projection:
ogr2ogr -t_srs "`g.proj -wf`" polbnda_italy_GB_ovest.shp polbnda_italy_LL.shp

Cut out a piece of a vector map
Use spatial query extents: -spat xmin ymin xmax ymax (W S E N)
ogr2ogr ARC_BZ.shp -spat 10 45 13 47 ARC.shp

Get VMAP0 metadata info
ogrinfo -ro gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr
ogrinfo -ro gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr | grep bnd
ogrinfo -ro gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr 'polbnda@bnd(*)_area'
ogrinfo -ro gltp:/vrf/grass0/warmerdam/v0eur/vmaplv0/eurnasia 'roadl@trans(*)_line'

MAP0: Extract spatial subregion, reproject from NAD83 to WGS84
# coordinate order: W S E N
ogr2ogr -spat 19.95035 -26.94755 29.42989 -17.72624 -t_srs 'EPSG:4326' \
polbnda_botswana.shp gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr \
'polbnda@bnd(*)_area'

OGR and SQL
Sample 'where' statements (use -sql for PostgreSQL driver):
# -where 'fac_id in (195,196)'
# -where 'fac_id = 195'
ogrinfo -ro -where 'fac_id in (195,196)' \
gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr 'polbnda@bnd(*)_area'

Find out the Countries VMAP0 coding
ogdi_info -u gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr \
-l 'polbnda@bnd(*)_area' -f area | grep Botswana
or read the VMAP0 Military specs, page 75pp

Extract Botswana, reproject on the fly from NAD83 to WGS84, store as SHAPE:
ogr2ogr -t_srs "EPSG:4326" -where "na2 = 'BC'" polbnda_botswana.shp \
gltp:/vrf/grass0/warmerdam/v0soa/vmaplv0/soamafr 'polbnda@bnd(*)_area'

Extract Germany, reproject on the fly from NAD83 to WGS84, store as SHAPE:
ogr2ogr -t_srs "EPSG:4326" -where "na2 = 'GM'" polbnda_germany.shp
gltp:/vrf/grass0/warmerdam/v0eur/vmaplv0/eurnasia 'polbnda@bnd(*)_area'
ogrinfo -summary polbnda_germany.shp polbnda_germany | grep Extent
# Extent: (5.865639, 47.275776) - (15.039889, 55.055637)
# W S E N

VMAP0 Contour lines for Germany:
ogr2ogr -t_srs "EPSG:4326" -spat 5.865639 47.275776 15.039889 55.055637 \
contour_lines.shp \
gltp:/vrf/grass0/warmerdam/v0eur/vmaplv0/eurnasia 'contourl@elev(*)_line'

VMAP0 elevation spots (points) for Germany:
ogr2ogr -t_srs "EPSG:4326" -spat 5.865639 47.275776 15.039889 55.055637 \
elevation_spots.shp \
gltp:/vrf/grass0/warmerdam/v0eur/vmaplv0/eurnasia 'elevp@elev(*)_point'

VMAP0 lakes of Trentino province in Italy
ogr2ogr -t_srs "EPSG:4326" -where "na2 = 'IT'" \
-spat 10.340029 45.261888 10.98727 45.98993 \
lakes_italy.shp \
gltp:/vrf/grass0/warmerdam/v0eur/vmaplv0/eurnasia 'inwatera@hydro(*)_area'

Connect OGR and PostgreSQL/PostGIS
ogrinfo PG:'host=grass.itc.it user=postgres dbname=ogc_simple'
ogr2ogr out.shape PG:'host=grass.itc.it user=postgres dbname=ogc_simple' lake_geom

GRASS 6 and OGR
Convert GRASS 6 vector map to SHAPE (needs GDAL-OGR-GRASS plugin):
# -nln is "new layer name" for the result:
ogr2ogr archsites.shp grassdata/spearfish60/PERMANENT/vector/archsites/head 1 \
-nln archsites

Using WKT files with ogr2ogr
The definition is in ESRI WKT format. If you save it to a text file called out.wkt you can do the following in a translation to reproject input latlong points to this coordinate system:
ogr2ogr -s_srs WGS84 -t_srs ESRI::out.wkt out_dir indatasource

Most comand line options for GDAL/OGR tools that accept a coordinate system will allow you to give the name of a file containing WKT. And if you prefix the filename with ESRI:: the library will interprete the WKT as being ESRI WKT and convert to "standard" format accordingly. The -s_srsswitch is assigning a source coordinate system to your input data (in case it didn't have this properly defined already), and the -t_srs is defining a target coordinate system to reproject to.

TIGER files in OGR
# linear features:
ogr2ogr tiger_lines.shp tgr46081.rt1 CompleteChain

# area features:
export PYTHONPATH=/usr/local/lib/python2.5/site-packages
tigerpoly.py tgr46081.rt1 tiger_area.shp

OGR CSV driver: easily indicate column types
You can now write a little csv help file to indicate the columns types to OGR. It works as follow :
Suppose you have a foobar.csv file that looks like this:
"ID","X","Y","AREA","NAME"
"1","1023.5","243.56","675","FOOBAR"
...

Now write a foobar.csvt file like this one:
"Integer","Real","Real","Integer","String"
The driver will then use the types you specified for the csv columns. The types recognized are Integer, Real and String, DateTime, and Date.

Convert KML to CSV (WKT)
First find layers:
ogrinfo -so myfile.kml

Then convert KML to CSV:
ogr2ogr -f CSV out.csv myfile.kml -sql "select *,OGR_GEOM_WKT from myfilelayer"
cat out.csv


Or use the cool online converter: http://geoconverter.hsr.ch
分享到:
评论

相关推荐

    ogr2ogr — GDAL文档_格式转换_gis_pdf_Linuxogr2ogr安装_

    ogr2ogr是GDAL(Geospatial Data Abstraction Library)的一部分,它是一个强大的开源库,用于处理多种地理空间数据格式。这个工具的主要功能是进行数据转换,它支持大量的GIS(地理信息系统)数据格式,包括矢量和...

    OGR.rar_ OGR _GetEnvelope org gdal_gdal 矢量_geotiff_矢量

    在IT行业中,尤其是在地理信息系统(GIS)开发领域,GDAL(Geospatial Data Abstraction Library)和OGR是两个非常重要的开源库。GDAL是一个强大的库,用于处理各种地理空间数据,包括栅格和矢量数据,而OGR是GDAL的...

    ogr2ogrGUI版本

    标题中的“ogr2ogrGUI版本”指的是一个图形用户界面(GUI)版本的ogr2ogr工具,它是GDAL(Geospatial Data Abstraction Library)库的一部分。GDAL是一个强大的开源地理空间数据处理库,广泛用于处理各种地理矢量和...

    ogr2ogr将shp文件导入到Mysql.zip

    ogr2ogr 是GDAL(Geospatial Data Abstraction Library)工具集的一部分,用于在各种地理空间数据格式之间进行转换。本篇文章将详细介绍如何使用ogr2ogr将Shapefile(.shp文件)数据导入到MySQL数据库,并解决可能...

    OGR使用参考文档

    **OGR**,全称是**OpenGIS Simple Features Reference Implementation**,是GDAL(Geospatial Data Abstraction Library)的一部分,是一个开源的C++库,用于处理地理空间的矢量数据。它支持多种矢量数据格式,包括...

    初学者OGR入门经典

    OGR(Open Geospatial Resource)作为 GDAL(Geospatial Data Abstraction Library)项目的一部分,专门用于读取和处理矢量数据。OGR 支持多种矢量数据格式,包括但不限于 ESRI Shapefile、S-57、SDTS、PostGIS、...

    基于Python的GDAL/OGR教程:Python GDAL/OGR Cookbook

    GDAL代表Geospatial Data Abstraction Library,主要处理栅格数据,而OGR(原名:Simple Features for GDAL)则用于矢量数据。这两者经常被一起使用,因此通常简称为GDAL/OGR。 本教程将涉及到以下几个核心模块的...

    shpfile批量转换成mapinfo支持的tab使用ogr2ogr.py

    ogr2ogr.py 是一个Python脚本,它是GDAL/OGR库的一部分,GDAL(Geospatial Data Abstraction Library)是一个开源的地理空间数据处理库,OGR是GDAL的一个子项目,专门用于处理矢量数据。 ogr2ogr工具能够方便地在...

    python 读取shp文件

    Reading and writing vector data with OGR

    OGR帮助文档(html)

    OGR,全称OpenGIS Simple Features Reference Implementation,是GDAL(Geospatial Data Abstraction Library)项目的一部分,是一个开源的、跨平台的C++库,用于处理地理空间矢量数据。GDAL是广泛使用的地理空间...

    GDAL和OGR资料

    它可以读取和处理多种流行的矢量数据(如ESRI的Shapefile、S-57、SDTS、PostGIS、Oracle Spatial、以及Mapinfo的mid/mif和TAB格式),本文将讲解OGR库的安装、OGR的数据模型以及主要类的函数功能,最后将通过几个...

    Mastering.Geospatial.Analysis.with.Python

    Chapter 5, Vector Data Analysis, covers Python libraries such as Shapely, OGR, and GeoPandas. which are used for analyzing and processing vector data. Chapter 6, Raster Data Processing, explores using...

    Python库 | ogr-0.0.3-py2.py3-none-any.whl

    OGR,全称是Open Geospatial Consortium (OGC) Geometry API,是GDAL(Geospatial Data Abstraction Library)项目的一部分。GDAL是一个强大的开源库,用于处理地理空间数据,如栅格和矢量数据。OGR专注于矢量数据...

    OGR 读取GML格式文件

    在Python环境中,OGR库,全称为OpenGIS Simple Features Implementation for C++,是GDAL(Geospatial Data Abstraction Library)的一部分,用于处理多种矢量数据格式,包括GML。 OGR库提供了丰富的API接口,用于...

    ogr.rar_OGR

    OGR,全称为OpenGIS Simple Features Reference Implementation,是GDAL(Geospatial Data Abstraction Library)的一部分,是一个开源库,用于处理多种矢量数据格式。在C#环境中,我们可以利用OGR的.NET绑定来操作...

    ogr2ogr转换工具

    地图数据格式转换,可以转换文件,也可以转换数据库。

    GDAL\OGR_2.3.1_x64 源码,gdal/ogr C源码

    GDAL (Geospatial Data Abstraction Library) 和 OGR (Open Geospatial Library) 是两个密切相关且在地理信息系统(GIS)领域广泛应用的开源库。GDAL 主要处理栅格数据,如遥感图像和数字高程模型,而 OGR 则专注于...

    GDAL&OGR;官方文档离线html

    GDAL(Geospatial Data Abstraction Library)与OGR(Open Geospatial Library)是两个在地理信息系统(GIS)领域中广泛使用的开源库。GDAL主要用于处理地理空间数据,如栅格数据(如卫星图像、遥感数据),而OGR则...

    OGR+C#+OpenGL

    2. **OGR**:OGR是GDAL(Geospatial Data Abstraction Library)的一部分,GDAL是一个强大的开源库,用于处理地理空间数据。OGR专注于矢量数据,支持多种矢量数据格式的读写,例如ESRI Shapefile、GeoJSON、KML等。...

Global site tag (gtag.js) - Google Analytics