- 浏览: 580372 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
JamAndVariousAbalone:
存储方式的不同吧。gb_tree是平衡树,list是线性结构。 ...
gb_trees和lists的访问效率相差很大 -
genesislive:
eporf:analyse()写错了,应该改成eprof:an ...
Erlang程序的性能测试工具(1) -
vampirezh:
高手啊 求带 ! 请列出带徒标准
Erlang的未来(2008) -
aiquantong:
great!
rebar工具使用备忘录 (1) -
wccxiaoan:
basho的资源 都没办法打开,不过还是有帮助,谢谢。
关于webmachine
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
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
发表评论
-
静态链接与动态链接
2014-09-06 03:24 1552基于gmp开发第三方库,后者以动态链接库(静态库?)对方式发布 ... -
在macbook上安装linux
2014-06-12 10:29 22821. 安装最新的rEFInd > 0.8.2 http: ... -
关于nif
2013-08-19 10:28 5106一、NIF的误用问题 使用NIF是很危险的,一不小心它就会搞 ... -
遇到的riak性能问题
2013-07-23 10:59 24201。 遇到一个奇怪的性能问题,多个进程中用riakc_pb_ ... -
dialyzer使用备忘
2013-07-04 12:36 1639一、构建PLT文件: 新构建 dialyzer --build ... -
手工从源码制作一个riak安装包
2013-06-22 18:47 1659riak的Makefile文件提供了各个平台上的安装包的生成脚 ... -
folsom_metrics使用备忘
2013-06-07 15:41 1478folsom是一个通用的统计度量工具。使用很简单,关键是搞清它 ... -
git 库永久删除大文件
2013-01-08 11:49 4694无意中把一个装有很多大文件数据的文件夹(./my1202260 ... -
Riak Core与folsom
2012-09-01 11:54 1499folsom是Riak从1.2开始引入。 -
关于Erlang/OTP的application参数配置
2012-08-26 23:27 9133Erlang/OTP中将完成特定功能的一组模块组织起来,称之 ... -
rebar工具使用备忘录 (5)
2012-08-23 18:17 1502haogongju、人人IT网、59n南龙、360doc、as ... -
lager的使用
2012-08-23 15:06 10552haogongju、人人IT网、59n南龙、360doc不要抄 ... -
rebar工具使用备忘录 (4)
2012-08-22 19:20 5618haogongju、人人IT网、59n南龙、360doc、as ... -
rebar工具使用备忘录 (3)
2012-08-22 19:18 1309haogongju、人人IT网、59n南龙、360doc不要抄 ... -
对Riak Core的探索 (9) cheatsheet
2012-08-12 12:58 1679haogongju、人人IT网、59n南龙、360doc不要抄 ... -
对Riak Core的探索 (8)
2012-08-11 18:52 1256haogongju、人人IT网、59n南龙、360doc不要抄 ... -
对Riak Core的探索 (7)
2012-08-10 18:15 1353haogongju、人人IT网、59n南龙、360doc不要抄 ... -
对Riak Core的探索 (6) HTTP接口
2012-08-09 16:16 1542haogongju,人人IT网,360do ... -
对Riak Core的探索 (5) 业务逻辑的实现:数据如何处理
2012-08-07 18:18 1654业务逻辑的实现:数据 ... -
对riak_core的探索 (5) webmachine
2012-08-07 17:49 0人人IT网不要抄我的烂博客了,私人备忘用的。
相关推荐
ogr2ogr是GDAL(Geospatial Data Abstraction Library)的一部分,它是一个强大的开源库,用于处理多种地理空间数据格式。这个工具的主要功能是进行数据转换,它支持大量的GIS(地理信息系统)数据格式,包括矢量和...
在IT行业中,尤其是在地理信息系统(GIS)开发领域,GDAL(Geospatial Data Abstraction Library)和OGR是两个非常重要的开源库。GDAL是一个强大的库,用于处理各种地理空间数据,包括栅格和矢量数据,而OGR是GDAL的...
标题中的“ogr2ogrGUI版本”指的是一个图形用户界面(GUI)版本的ogr2ogr工具,它是GDAL(Geospatial Data Abstraction Library)库的一部分。GDAL是一个强大的开源地理空间数据处理库,广泛用于处理各种地理矢量和...
ogr2ogr 是GDAL(Geospatial Data Abstraction Library)工具集的一部分,用于在各种地理空间数据格式之间进行转换。本篇文章将详细介绍如何使用ogr2ogr将Shapefile(.shp文件)数据导入到MySQL数据库,并解决可能...
**OGR**,全称是**OpenGIS Simple Features Reference Implementation**,是GDAL(Geospatial Data Abstraction Library)的一部分,是一个开源的C++库,用于处理地理空间的矢量数据。它支持多种矢量数据格式,包括...
OGR(Open Geospatial Resource)作为 GDAL(Geospatial Data Abstraction Library)项目的一部分,专门用于读取和处理矢量数据。OGR 支持多种矢量数据格式,包括但不限于 ESRI Shapefile、S-57、SDTS、PostGIS、...
GDAL代表Geospatial Data Abstraction Library,主要处理栅格数据,而OGR(原名:Simple Features for GDAL)则用于矢量数据。这两者经常被一起使用,因此通常简称为GDAL/OGR。 本教程将涉及到以下几个核心模块的...
ogr2ogr.py 是一个Python脚本,它是GDAL/OGR库的一部分,GDAL(Geospatial Data Abstraction Library)是一个开源的地理空间数据处理库,OGR是GDAL的一个子项目,专门用于处理矢量数据。 ogr2ogr工具能够方便地在...
Reading and writing vector data with OGR
OGR,全称OpenGIS Simple Features Reference Implementation,是GDAL(Geospatial Data Abstraction Library)项目的一部分,是一个开源的、跨平台的C++库,用于处理地理空间矢量数据。GDAL是广泛使用的地理空间...
它可以读取和处理多种流行的矢量数据(如ESRI的Shapefile、S-57、SDTS、PostGIS、Oracle Spatial、以及Mapinfo的mid/mif和TAB格式),本文将讲解OGR库的安装、OGR的数据模型以及主要类的函数功能,最后将通过几个...
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...
OGR,全称是Open Geospatial Consortium (OGC) Geometry API,是GDAL(Geospatial Data Abstraction Library)项目的一部分。GDAL是一个强大的开源库,用于处理地理空间数据,如栅格和矢量数据。OGR专注于矢量数据...
在Python环境中,OGR库,全称为OpenGIS Simple Features Implementation for C++,是GDAL(Geospatial Data Abstraction Library)的一部分,用于处理多种矢量数据格式,包括GML。 OGR库提供了丰富的API接口,用于...
OGR,全称为OpenGIS Simple Features Reference Implementation,是GDAL(Geospatial Data Abstraction Library)的一部分,是一个开源库,用于处理多种矢量数据格式。在C#环境中,我们可以利用OGR的.NET绑定来操作...
地图数据格式转换,可以转换文件,也可以转换数据库。
GDAL (Geospatial Data Abstraction Library) 和 OGR (Open Geospatial Library) 是两个密切相关且在地理信息系统(GIS)领域广泛应用的开源库。GDAL 主要处理栅格数据,如遥感图像和数字高程模型,而 OGR 则专注于...
GDAL(Geospatial Data Abstraction Library)与OGR(Open Geospatial Library)是两个在地理信息系统(GIS)领域中广泛使用的开源库。GDAL主要用于处理地理空间数据,如栅格数据(如卫星图像、遥感数据),而OGR则...
2. **OGR**:OGR是GDAL(Geospatial Data Abstraction Library)的一部分,GDAL是一个强大的开源库,用于处理地理空间数据。OGR专注于矢量数据,支持多种矢量数据格式的读写,例如ESRI Shapefile、GeoJSON、KML等。...