ogr

How can I get the installed GDAL/OGR version from python?

纵然是瞬间 提交于 2019-12-06 18:58:45
问题 How can I get the installed GDAL/OGR version from python? I aware of the gdal-config program and are currently using the following: In [3]: import commands In [4]: commands.getoutput('gdal-config --version') Out[4]: '1.7.2' However, I suspect there is a way to do this using the python API itself. Any dice? 回答1: gdal.VersionInfo() does what I want: >>> osgeo.gdal.VersionInfo() '1604' This works on both my Windows box and Ubuntu install. gdal.__version__ gives an error on my Windows

Extract Point From Raster in GDAL

左心房为你撑大大i 提交于 2019-12-06 14:00:42
问题 I have a raster file and a WGS84 lat/lon point. I would like to know what value in the raster corresponds with the point. My feeling is that I should use GetSpatialRef() on the raster object or one of its bands and then apply a ogr.osr.CoordinateTransformation() to the point to map it to the raster's space. My hope would then be that I could simply ask the rasters' bands what is at that point. However, the raster object doesn't seem to have a GetSpatialRef() or a way to access a geo-located

Parsing osm.pbf data using GDAL/OGR python module

青春壹個敷衍的年華 提交于 2019-12-05 23:46:00
I'm trying to extract data from an OSM.PBF file using the python GDAL/OGR module. Currently my code looks like this: import gdal, ogr osm = ogr.Open('file.osm.pbf') ## Select multipolygon from the layer layer = osm.GetLayer(3) # Create list to store pubs pubs = [] for feat in layer: if feat.GetField('amenity') == 'pub': pubs.append(feat) While this little bit of code works fine with small.pbf files (15mb). However, when parsing files larger than 50mb I get the following error: ERROR 1: Too many features have accumulated in points layer. Use OGR_INTERLEAVED_READING=YES MODE When I turn this

gdal/ogr: How to really crop a shapefile?

心已入冬 提交于 2019-12-05 22:54:18
问题 Given a SHP file corresponding to European countries , and... Given defined area corresponting to France such : West : 005° 48' W East : 010° E North : 051° 30' N South : 041° N How to get only the dots/geometries which intersects my defined area with gdal ? so my crop indeed is a real crop, which just keep the necessary geometries. Strong preference to gdal , ogr or console solutions. 回答1: Use GDAL's ogr2ogr command-line utility. If you have a file Europe.shp which has a spatial reference

How can I get the installed GDAL/OGR version from python?

做~自己de王妃 提交于 2019-12-05 01:37:25
How can I get the installed GDAL/OGR version from python? I aware of the gdal-config program and are currently using the following: In [3]: import commands In [4]: commands.getoutput('gdal-config --version') Out[4]: '1.7.2' However, I suspect there is a way to do this using the python API itself. Any dice? gdal.VersionInfo() does what I want: >>> osgeo.gdal.VersionInfo() '1604' This works on both my Windows box and Ubuntu install. gdal.__version__ gives an error on my Windows installation, although it works on my Ubuntu installation: >>> import osgeo.gdal >>> print osgeo.gdal.__version__

Extract Point From Raster in GDAL

柔情痞子 提交于 2019-12-04 21:49:20
I have a raster file and a WGS84 lat/lon point. I would like to know what value in the raster corresponds with the point. My feeling is that I should use GetSpatialRef() on the raster object or one of its bands and then apply a ogr.osr.CoordinateTransformation() to the point to map it to the raster's space. My hope would then be that I could simply ask the rasters' bands what is at that point. However, the raster object doesn't seem to have a GetSpatialRef() or a way to access a geo-located point, so I'm somewhat at a loss for how to do this. Any thoughts? Say i have a geotiff file test.tif.

Adding custom Feature attributes to ESRI Shapefile with Python

这一生的挚爱 提交于 2019-12-03 14:48:53
I am seeking a way to take an existing ESRI Shapefile that has a Feature set of 200 countries. Each country Feature has an attribute of "NAME." My objective is to create a Python script that adds an arbitrary (for now) additional attribute, say, "POPULATION". Of course I have the OSGeo and GeoDjango modules installed. I'm as far as: from osgeo import ogr infile = ogr.Open('sample.shp', 1) #'sample.shp' is a pre-existing ESRI shapefile described above inlyr = infile.GetLayerByIndex(0) Am I missing an OGR function that will allow me to insert Feature attribute fields into an existing Shapefile?

GTiff mask with shapefile in python with gdal, ogr, etc

僤鯓⒐⒋嵵緔 提交于 2019-12-03 13:40:36
问题 OK, After a bit of fiddling, I've tweaked a script from the site hyperlink in the second comment line. The purpose of the script is to clip/mask a LARGE raster (i.e. that cannot fit into a 32-bit Python 2.7.5 application) in GTiff format with a shapefile with multiple polygons (each with a "Name" record) and save the clipped rasters into a "clip" sub-directory, where each masked grid is named after each polygon's "Name". Like the original script, it assumes that the GTiff and shapefile are in

GTiff mask with shapefile in python with gdal, ogr, etc

久未见 提交于 2019-12-03 03:40:36
OK, After a bit of fiddling, I've tweaked a script from the site hyperlink in the second comment line. The purpose of the script is to clip/mask a LARGE raster (i.e. that cannot fit into a 32-bit Python 2.7.5 application) in GTiff format with a shapefile with multiple polygons (each with a "Name" record) and save the clipped rasters into a "clip" sub-directory, where each masked grid is named after each polygon's "Name". Like the original script, it assumes that the GTiff and shapefile are in the same projection and overlap correctly, and it processes ~100 masks/sec. However, I have modified

Python GDAL课程笔记

元气小坏坏 提交于 2019-12-02 02:33:02
说明: 这是一份来自网上的学习笔记,教程来自于犹他州立大学,课程名称为:Geoprocessing with Python using Open Source GIS 。 这份教程在网上有几个网站进行过发布,也无从判断哪份才是原创。作为一份学习笔记,里面很多技术细节都语焉不详,但是不管怎样,这份资料都是很难得的。 开放地理空间实验室进行了整理,修改了一些细节,并进行重新发布。感谢原作者的工作。 地理数据处理软件包GDAL简介 GDAL OGR GDAL python教程(1)——用OGR读写矢量数据 为什么用open source? Open source RS/GIS模块 相关模块 导入库: 读取数据层 释放内存 读完了再说怎么写 GDAL python教程(2)——几何形状geometry与投影projection 建立新的几何形状 创建复合几何形状multi geometry GDAL python教程(3)——过滤器,简单的空间分析,函数和模块 属性过滤器Attribute filters 空间过滤器Spatial filters 统计每种cover类型各有多少个Feature 空间操作 下面看看简单的地理数据处理geoprocessing GDAL python教程(4)——用GDAL读取栅格数据 导入GDAL支持库 GDAL python教程(5)—