The OGR Simple Features Library is a C++ open source library (and command line tools) providing access to vector file formats.

learn more… | top users | synonyms

14
votes
4answers
7k views

How to add an attribute field to an existing Shapefile via Python

I have a Python script that adds an attribute field to a Shapefile if doesn't exist. This is easy to do with ArcGIS (graphically or via Python), but I'm looking for something that doesn't depend on ...
8
votes
7answers
9k views

Fixing corrupt shapefile?

I have a shapefile that I was working on in ArcGIS Desktop 9.3 get corrupted somehow and it gives me the error "Number of shapes does not match the number of table records.". What I would want is to ...
9
votes
5answers
1k views

How to build a geographic database of GPS logs?

On our aerial wildlife surveys we typically generate dozens of GPX files, and usually convert most of them into shapefiles for display in a GIS application. GPX files are a terrific way of keeping all ...
0
votes
1answer
340 views

How to conditionnally assign a new value to pixels of a raster image?

Given a topographic GIS raster of one country crop.tif: Given a know pixel value such as elevation (z) is +73 : $ gdallocationinfo crop.tif 1 1 -valonly > 73 Given an elevation threshold n = 50 ...
21
votes
1answer
2k views

Can ESRI's File Geodatabase API be Redistributed?

ESRI's file geodatabase API can now be used with GDAL/OGR - http://www.gdal.org/ogr/drv_filegdb.html however each individual seems to have to login to ESRI and download the API files individually. For ...
14
votes
6answers
5k views

Generate points that lie inside polygon

I have polygon feature and want to be able to generate points inside it. I need this for one classification task. Generating random points until one is inside the polygon wouldn't work because it's ...
6
votes
4answers
2k views

Is it possible to create 3D dxf with OGR?

Does anyone know if it's possible to create a 3D dxf with OGR. I would like to assign our contour lines a z value and export them to dxf for some cad work. PS I know FME can do this, however I would ...
7
votes
2answers
3k views

Generating GeoJSON with Python

Hi I want to programatically create a GeoJSON file using polygons from a shapefile but adding attributes from my own application. This is easily done for a shapefile: def ...
5
votes
2answers
3k views

How can I convert a csv file of WKT data to a shape file using ogr2ogr?

This question is related to Shapefiles to Text. I have a csv file, with one column, where all the rows correspond to WKT POLYGON()'s: WKT POLYGON(...) POLYGON(...) ... I'm familiar with how to ...
5
votes
1answer
3k views

How to resample a batch of rasters using OGR/GDAL?

I'm looking for a function similar to GRASS r.resample. I have a folder full of TIF files and want to reduce their resolution ("scale them down") to reduce file size.
2
votes
1answer
295 views

How to run OGR in ArcGIS Scripts?

When I run my script outside ArcGIS it works because during execution script uses a GDAL and OGR modules from osgeo. When I use script as a tool in ArcGIS it does not work. In PySripter I can import ...
4
votes
1answer
1k views

better way to duplicate a layer using ogr in python?

I'm splitting a large shapefile into many smaller ones using ogr. I'd like to just copy all of the field and layer config information from the original. Here's how I'm doing it now: src = ...
2
votes
2answers
2k views

How do you open shapefiles with ogr2ogr

I'm following along the D3 tutorial, and on this line: ogr2ogr \ -f GeoJSON \ -where "adm0_a3 IN ('GBR', 'IRL')" \ subunits.json \ ne_10m_admin_0_map_subunits.shp run into the following ...
1
vote
3answers
824 views

Can I have two kinds of point geometry in a shapefile or I should create multipoint shapefiles?

Following my previous question, can I have a mixture of two kinds of geometry in a shapefile of type point. Just like I have about shapefiles of type polygon or I should always create a shapefile of ...
0
votes
1answer
1k views

How current is GDAL in Java

I have used the ogr2ogr to import various formats to Postgres and have used GDAL utilities. Is there a complete Java port for these tools? Or are they simply wrappers calling JNI to C++ code? I have ...
9
votes
5answers
1k views

How to convert line simple features to topological network?

using Gdal/ OGR is there a way to convert a shp, kml, or PostGIS line layer into a network of nodes and segments so it can be used in packages such as networkx?
14
votes
7answers
7k views

What's the easiest way to install GDAL and OGR for Python?

I am developing some code in Python, and I want to use the GDAL/OGR python bindings. What is the minimum I need to install in order to use the GDAL and OGR python bindings? What is the easiest way to ...
9
votes
3answers
3k views

Divide a complex shape file into a grid

I have a decently detailed shapefile with polygon/multipolygon features (the file is about 500mb). It's actually a shapefile of the entire world, with the features representing coastlines. I need to ...
9
votes
3answers
3k views

Get all vertices of a polygon using OGR and Python

I'm having a little trouble with the Python OGR API. What I am trying to do is get all the coordinates of each vertex of the outer ring of a polygon. This is what I have so far: import osgeo.ogr ...
10
votes
5answers
3k views

installing GEOS, PROJ, GDAL/OGR into a python virtualenv on Mac OS X

I am trying to setup an isolated python virtualenv to work on GIS projects on my Mac OS X. Sounds like I will need to install the GEOS, PROJ, GDAL/OGR from the kyngchaos site here ...
5
votes
2answers
2k views

GDAL Python bindings not picking up OGR PostgreSQL driver

I have a windows server (Microsoft Windows Server 2003) with: Python 2.7, PostgreSQL 9.04-1, GDAL 1.8.1 (installed from the windows installer (gdal-18-1500-core.msi) hosted at ...
7
votes
2answers
3k views

How to convert GML Surface to SHP Using OGR?

I have a very large .gml file with multiple layers in it. I would like to export one of these layers to .shp. It is a polygon layer (of lakes). However, I am getting the error: ERROR 1: ...
1
vote
0answers
16 views

Asking about OFTInteger data type in OGR/GDAL?

I created the shape file by using the feature field type: OFTInteger. But when I open the file in Arcgis (ArcCatalog) the data type is: Double (not integer). Do you know how to fix this (I want it ...
1
vote
1answer
198 views

Writing shapefile with projection defined crashes fiona

I've just started trying to use Fiona to write out shapefiles. I found the example code below, which seems to work fine from shapely.geometry import mapping, Polygon import fiona # Here's an example ...
0
votes
1answer
156 views

Creating records in output shapefile using Python

I have a list (output from a previous loop) containing attributes from an input shapefile. What I am stuck with is inputting those attributes to a new shapefile. I have plotted the point data using ...
0
votes
1answer
2k views

How to clip a line layer based on polygons with QGIS?

I have a line layer and a polygon layer. Both files have the same SRS. I want in a new shape file only the lines covered by the polygons. I tried in QGIS the Vector -> Geoprocessing -> Clip ...
21
votes
2answers
3k views

Python Efficiency — Need suggestions about how to use OGR and Shapely in more efficient way

I'm looking for some suggestions about how to make my python code more efficient. Normally efficiency doesn't matter for me but I am now working with a text file of US locations with over 1.5 million ...
11
votes
3answers
1k views

ogr2ogr fails to convert GeoJson file > 200MB

As a followup to my previous question (Converting SimpleGeo Places GeoJSON file to shapefile), I am now struggling with what I perceive might be an ogr2ogr "memory" limitation, but I cannot be sure. ...
13
votes
1answer
3k views

How do I get the pixel value of a GDAL raster under an OGR point without NumPy?

I am working on a computational model of the abundance of wild pollinators across a landscape. The model itself is complete, and I am now struggling with a post-processing step. I have my GDAL ...
10
votes
2answers
2k views

How to add custom Feature attributes to ESRI Shapefile with Python?

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 ...
8
votes
4answers
2k views

Best way to find the polygons crossed by a line

I'm trying to find all the polygons crossed by a single line (a GPS track). I'm using the OGR library (from python) for computing this, but it's currently a bit 'brute-force' (and slow). For every ...
6
votes
1answer
4k views

R : convert a spatial polygon objet to spatial polygon data frame

My goal is to modify an existing shapefile by merging certain polygons. After importing the shapefile and using the UnionSpatialPolygons command, I get the polygon outline that I want. However, this ...
4
votes
3answers
1k views

Python OGR: convert a point geometry into polygon

I'm writing a routine for creating the convex hull envelop around shapefiles of islands. I could read the data, extract polygons vertices into a geometry and then compute the convex hull. Now I need ...
12
votes
2answers
4k views

API documentation for Gdal/Ogr with C#

I want to assign projection to shapefile in my web C# application, for this i am using Gdal/OGR/OSR C# bindings and add osr_csharp.dll and ogr_csharp.dll references. But i am facing some difficulty ...
10
votes
2answers
3k views

Point (of a linestring) within Polygon using ogr and Python

I'm currently working on a project in which I need to build a topological network out of the geometry features I find in shapefiles. So far using Ben Reilly's open source project I've managed to ...
5
votes
2answers
1k views

Call FWTools (ogr2ogr) from ArcGIS python script

In ArcGIS, I want to use a Python script (and a standard ArcGIS script tool UI) to call functionality from FWTools. How would I make the call to FWTools? I tried using ...
2
votes
1answer
2k views

Projecting shapefile with transformation using OGR in python

I want to change coordinate system of a shapefile from British National Grid to WGS84 (in order to be able to convert it to KML later on). To get the best results of projecting I would like to use ...
14
votes
1answer
749 views

How to rename field names in a shapefile from the commandline?

I need to rename the field names (attributes) in a shapefile. Is there an easy way to do this from the command line?
10
votes
3answers
2k views

getting dxf files out of PostgreSQL

I've successfully loaded a bunch of shapefiles into a PostGIS database. I would like to be able to retrieve specific geometry and layers as dxf files based on SQL queries. I'm using PostGIS, GDAL, ...
8
votes
6answers
899 views

How do I generate thumbnails images from lots of shapefiles?

A colleague and I recently released an Open Source project called Mapoteca which is a set of Python Scripts that integrates with a GDAL/FWTools installation allowing a full walk-through of directories ...
7
votes
2answers
512 views

How to catch PostgreSQL/PostGIS errors in GDAL/OGR Python bindings?

Is it possible to catch PostgreSQL output error messages in OGR after a query has failed? For example conn.ExecuteSQL('SELECT * FROM non_existing_table;') In Postgres this returns an error ...
7
votes
2answers
814 views

DXF attribute to z value

We have been given a DXF that contains a Elevation attribute but we would like to generate a 3D DXF. I know I can generate a 3D dxf from a shapefile using: ogr2ogr -f "DXF" out.dxf in.shp -zfield ...
6
votes
1answer
906 views

Spatial joins in OGR SQL

I have seen that OGR supports it's own form of SQL, I was wondering if it's possible to do spatial joins. Something like select all objects where one intersects the other. I did have a look around ...
5
votes
2answers
818 views

Python: how to speed up spatial search (nearest point)?

I'm working on a program that determines the closest location from a given point. The point cloud I'm testing against is very big (~800.000). However, this doesn't really explain why my implementation ...
5
votes
1answer
997 views

Python - OGR: Transform coordinates from meter to decimal degrees

I have a point in a shapefile. The shapefile is in a WGS_1984_Web_Mercator Projected Coordinate System. I want to get the coordinates of that point in decimal degrees with GDAL/OGR in Python. I am ...
4
votes
1answer
981 views

How to programatically populate a shapefile field with polygon areas in OGR?

I'm trying to programatically populate a shp field with polygon areas: import sys import ogr ds = ogr.Open( 'tttttttttt.shp', update = 1 ) if ds is None: print "Open failed./n" sys.exit( 1 ...
4
votes
1answer
399 views

ogr2ogr when importing from fgdb and use in python

I want import data from my GDB to PostGIS. It works fine on some datasets (all records -data- is imported or nothing is imported) from a gdb but just doesn't import others. I can't find any ...
4
votes
2answers
564 views

Issues with osgeo - qgis.core and arcpy modules

Is it possible to have the python shell from either qgis or argis to load (import) both qgis.core and arcpy? I am developing a metadata creation tool and have completed the core functionality using ...
3
votes
1answer
406 views

Clip and copy files to same directory structure using OGR/GDAL with Python

We need to clip all our data (many TB) by a new boundary and save it while maintaining the same data structure. I want to use OGR/GDAL as the data is in shp/tab/kml/geoTif/ecw etc. I can find the ...
3
votes
3answers
702 views

DXF to georeferenced SHP

I know how to set projection and georeference bounds of scanned TIFF file, by using gdal, but I don't know how to do the same for vector file. For example I georeferenced TIFF file by using this ...