ogr2ogr is an open source command line utility popular for converting to and from various vector spatial data formats.

learn more… | top users | synonyms

11
votes
2answers
5k views

ogr2ogr converting to shapefile - how to select feature types?

Shapefiles can only have one geometry type, but many other formats (kml, geojson) can have multiple types. When converting to shapefiles, is it possible to to tell ogr2ogr to create multiple ...
10
votes
3answers
4k views

How to create a GeoJSON that works with D3?

I'm simply trying to convert a .shp file to a geoJSON format using: ogr2ogr -f geoJSON output.json input.shp After executing the command nothing seems to be wrong. Here's an excerpt from the ...
9
votes
7answers
2k views

How to add field with filename when merging shapefiles with ogr2ogr?

I'm merging some shapefiles and I had some problems doing so inside QGIS, so i'm using ogr2ogr directly. I'm doing this (in a batch): ogr2ogr -overwrite %destination% %n1% ogr2ogr -update -append ...
8
votes
5answers
1k views

How can I update ogr2ogr to include the PostgreSQL driver?

I'm trying to use ogr2ogr to upload a shapefile to a remote PostGres installation. When I ran this command: celenius:~ celenius$ ogr2ogr -f PostgreSQL PG:"host=255.34.00.00 user=postgres dbname=mydb ...
8
votes
2answers
677 views

How to reduce the file size of GeoJSON data?

For my project I am trying to convert the tiger shapefile information for us states into GeoJSON format However when I use the ogr2ogr tool the data file is about 20 MB. I have seen the geoJSON file ...
8
votes
1answer
590 views

GeoJson to ESRI Shapefile using ogr2ogr

I have a GeoJson file that I want to convert to ESRI Shapefile using ogr2ogr in FWTools. I tried using ogr2ogr -F "ESRI Shapefile" filename.shp geojsonfile.json OGRGeoJSON I got output ERROR ...
6
votes
7answers
4k views

ogr2ogr convert all shapefiles in a directory

I have a directory with several shapefiles. How can convert all these shapefiles to MapInfo with ogr2ogr. I know how I can convert one file. And I can make a batch script writing a line for each file. ...
5
votes
1answer
2k views

How to re-project shapefiles?

I wanted to re-project a QGIS project, but there is no such option. When searching for an answer I see ogr2ogr suggested for this task, by re-projecting each vector layer (shapefile in this example). ...
5
votes
1answer
141 views

ogr2ogr selecting features by attributes

I am writing a shapefile after some processing; however, in the final step I need to do some selection by attributes from the the shapefile. I am using the command in a shell with the aim of using it ...
5
votes
2answers
418 views

OGR to read from oracle, and then write a CSV

I need to read an Oracle (not spatial) table with OGR. I have no problem with ogrinfo. I use this command: ogrinfo -ro OCI:user/password -sql "select * from HR.EMPLOYEES" I have this kind of ...
5
votes
1answer
3k views

How to import KML file, with custom data, to Postgres/PostGIS database?

By custom, I don't mean a different structure of KML file, but in <description></description> section, I have data with HTML tags of this kind: <?xml version="1.0" ...
5
votes
2answers
2k views

ogr2ogr kml to shp conversion created 184 shapefiles?! What am I missing?

I'm trying to convert this KML dataset of ice arenas to a shapefile using ogr2ogr (GDAL 1.8). After some initial troubleshooting to get the script running, it's creating 184 different shapefiles (736 ...
5
votes
2answers
349 views

OGR merge shapefiles of different geom type into a single GeoJSON feature collection

I'd like to merge shapefiles of different geometry types into a single geojson feature collection, but OGR says it doesn't support update of GeoJSON files: $ ogr2ogr -f GeoJSON -t_srs crs:84 -lco ...
5
votes
1answer
972 views

OGR Shapefile to CSV: Using Python to get WKT for multipart Polys.

Using ogr2ogr and python, I'm running into a wall with trying to create a csv with WKTs for a shapefile that contains multipart polygons. Currently this is this code I'm using (found it on interweb): ...
5
votes
1answer
2k views

Importing KML in QGIS - what are all the node elements that QGIS looks for other than Name and Description?

Of all elements given at (ref: http://service.kmlvalidator.com/ets/ogc-kml/2.2/) only Name and Description seem to be recognized on importing KML using QGIS 1.8.0-Lisboa. I would like to know if this ...
5
votes
2answers
477 views

Translating all features in a shape file

I have a friend with a bit of a problem. He has 1000+ shape files mapping paddocks and being used for precision agriculture. He's recently discovered the base station positions used to create these ...
5
votes
1answer
373 views

Ogr2Ogr exported this boundary 90 degrees incorrectly

I've got some GEOGRAPHY data in my Sql Server 2008. I wish to export it as a shapefile (so I can import it into QGIS) and when I do, it's rotated 90 degrees to the left and then flipped 180 degrees to ...
4
votes
1answer
61 views

How do I teach ogr2ogr about a projection?

I have JSON generated from ArcGIS that I want to convert to GeoJSON in EPSG 4326. This fails: $ ogr2ogr -f GeoJSON -t_srs EPSG:4326 out.geo.json in.arcgis.json OGRGeoJSON ERROR 6: EPSG PCS/GCS code ...
4
votes
1answer
181 views

Is there a way to handle file names with spaces in ogr2ogr?

I'm trying to convert .shp files to .kml files. I used a batch file to find all .shp files in a directory and its sub-directories and convert them to .kml. Some converted and some gave me the error ...
4
votes
1answer
232 views

Can ogr2ogr be used to append multiple DBF files?

Can ogr2ogr be used to append multiple DBF files? It works with SHP files, but I can't see how to do it with DBF files on their own. It ought to be possible, considering DBF is a subset of SHP.
4
votes
1answer
143 views

Why does ogr2ogr silently skip some rows?

I have a CSV file called office_locations.csv that contains point data. I want to load it into a SQL Server geospatial database using ogr2ogr. The CSV file is encoded in UTF-8. It contains a header ...
4
votes
1answer
126 views

ogr2ogr: How to specify element type for DXF creation

I am trying to create a DXF from a Polygon Shapefile using ogr2ogr: ogr2ogr -f DXF parcels.dxf parcels.shp The problem is that the polygons are written as hatch elements. How do I specify that ...
4
votes
1answer
504 views

Can't export a polygon shapefile to MySQL using ogr2ogr?

I am having problems with ogr2ogr and keep getting different versions of the error: ERROR 1: MySQL error message: The used table type doesn't support SPATIAL indexes. Description: ALTER TABLE ...
4
votes
1answer
117 views

GDALWARP and OGR2OGR / CS2CS not agreeing on transformation

I am trying to transform some data (both raster and vector) from WGS84 to a Croatian Coordinate system defined by: +proj=tmerc +lat_0=0 +lon_0=15 +k=0.9999 +x_0=5500000 +y_0=0 +ellps=bessel ...
4
votes
1answer
453 views

Importing multiple shapefiles with tablespace and inheritance defined

In the UK we are very fortunate to have the Ordnance Survey who provide the whole of Britain in vector format. The data is provided as over 60 tiles, each of which contains something like 16 ...
4
votes
1answer
637 views

Why are GeoJSON coordinates different exported from QGIS vs. ogr2ogr?

I have a shapefile with a Google Mercator projection (900913) that I need converted to GeoJSON. I need to do this on a regular basis amongst other things so I wrote a shell script to do it using ...
3
votes
4answers
1k views

How to convert multipoint layer to point

I have a Spatialite layer which is multipoint (following a QGIS Save As from shapefile). I need it to be PostGIS and POINT. I have tried ogr2ogr -nlt POINT and got 'new row for relation "xxx" violates ...
3
votes
4answers
2k views

How do I use ogr2ogr to convert a GML to shapefile in Python

I am trying to convert a GML to an ESRI shapefile using ogr2ogr utility in a python script. I have successfully installed the GDAL/OGR package via osgeo but I am now struggling to find/understand ...
3
votes
2answers
162 views

Is it possible to create CAD file from shapefile and also create CAD blocks from the database fields

I am trying to find out if there is any software or plugin/code that I can bundle that will take a shapefile and export it to a CAD file with CAD blocks generated so our CAD mappers can just move the ...
3
votes
1answer
417 views

Setting geometry types importing to PostGIS with OGR

I'm using ogr2ogr to import data into a PostGIS database. Each dataset I need to import has (theoretically) the same exact data structure, but it appears that they are not the same geometry types. ...
3
votes
1answer
590 views

ogr2ogr coverting DXF to shapefile, why am I losing part of the feature?

I'm starting to mess around with some of the GDAL toolsets, specifically the ogr2ogr. I'm working with converting a 2000 ACSII DXF file to shapefiles depending on geometry. Everything seems to work ...
3
votes
1answer
52 views

New attribute creation using ogr and regex

I've got a folder full of dxf files with elevation values included as part of a long text attribute. I've written a regex expression to extract the elevation value, and would like to add it as a new ...
3
votes
1answer
159 views

Projection of Shapefiles for Spain (INE)

I downloaded the official shapefiles for the municipalities of Spain from INE here. It has a lot of shapefiles, but I found out that the right one for what I need is esp_muni_0109.shp. I would like ...
3
votes
2answers
816 views

How did QGIS fix a shapefile's character encoding, and can I do this on the command line with ogr2ogr?

Solved: I'm not sure why, but it works fine if I specify --config SHAPE_ENCODING "ISO-8859-1" in my ogr2ogr command. For whatever reason, this allowed ogr2ogr to go from the original TigerLine ...
3
votes
1answer
313 views

ogr2ogr / GDAL remove features in FileGDB while in use by ArcGIS Server map service

I'm using ogr2ogr to pull features out of Oracle and put them into a File GeoDatabase. The FGDB is being used by an active ArcGIS Server map service. This is all done for performance / reducing DB ...
3
votes
1answer
382 views

Change Layer name when converting from GeoJSON

I am converting GeoJSON files to other formats (including KML) using ogr2ogr. As you may know, there is no field in a GeoJSON file to specify the name of the layer, causing every conversion to have ...
3
votes
1answer
3k views

Converting kml to shape file via ogr2ogr including all attributes

Here is the example kml file I am using: <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <name>My Golf Course Example</name> <Placemark> <name>Club ...
3
votes
2answers
499 views

How to preserve non-ASCII characters in ogr2ogr import?

I want to import a list of international place names and their locations into a SQL Server database using ogr2ogr. The source data is a CSV file encoded in UTF-8. I've prepared a five-record sample ...
3
votes
1answer
351 views

Export KML ExtendedData with OGR2OGR

I would like to export with ogr2ogr the data I have in a kml as ExtendedData <Placemark> <ExtendedData> <SchemaData schemaUrl="#15540_punti"> ...
3
votes
1answer
352 views

ogr2ogr from Postgres to GeoJSON missing crs key

I'm using ogr2ogr to convert some OSM data for Greenland (not really important for the question), from a PostGIS database to a file containing GeoJSON. The problem is that the GeoJSON gets written ...
3
votes
2answers
428 views

Why does Ogr2Ogr Postgres import fail?

I have a lot of S57 files that need to be imported to PostgresDB. The process takes over 2 hours. In order to improve performance, I have tried using PG_USE_COPY to use copy instead of DB inserts. I ...
3
votes
1answer
730 views

How do I split polygons that cross the dateline?

I have a dataset of country borders which I obtained from: http://thematicmapping.org/downloads/world_borders.php/ I have that dataset in both shp and SQL, but I'll put out there that I don't feel ...
3
votes
0answers
20 views

How can you prevent ogr2ogr from truncating trailing zeros when setting coordinate_precision=0 and saving to GeoJSON?

This weekend I started using ogr2ogr and discovered that it's a great tool for converting from one spatial reference system to another. I used it to convert a shapefile to GeoJSON, from WGS84 to a ...
3
votes
1answer
53 views

Ogr2ogr does not support file name with non-ASCII character?

I tried to use the following script to convert shapefile to mif: ogr2ogr -f "MapInfo File" D:\docs\arcgis_data\shp_mif\BOU.mif D:\docs\arcgis_data\shp\BOU.shp it works. But I found that if the ...
3
votes
0answers
113 views

How do I clip Geojson FeatureCollection with another Geojson polygon

I have a GeoJSON file that contains one FeatureCollection with a bunch of features that are polygons. I also have the boundary of the continental USA in another GeoJSON file. I'd like to clip the ...
3
votes
1answer
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 ...
3
votes
1answer
408 views

Convert non-spatial Oracle table to spatial Oracle table in a different database

I'm trying to use ogr2ogr to convert data from a non-spatial table (has X & Y values) in an Oracle database (1) to a spatial format in a different Oracle database (2). This will be scheduled to ...
3
votes
0answers
308 views

How to save table from PostgreSQL to MapInfo File?

I have two tables: 1 with geometry in WGS 2 with geometry in Local System I tried this: ogr2ogr -f "MapInfo File" output2.tab PG:"host=localhost user=postgres password=123456 dbname=postgis" -sql ...
2
votes
4answers
3k views

How to convert SHP into GPX or JSON?

I would like to convert the tree inventory shape files of London (Canada) into a GPX file and if possible into a JSON file. You can download the archive from their Open Data website. It contains the ...
2
votes
2answers
746 views

merge shapefile using ogr2ogr and retrieve the attribute of both

Ciao, I have two shape files that I want merge (overlay/intersect) having in the destination the attributes of the two sources file. ogr2ogr file_merged.shp tl_2010_us_uac10_conus_albersUA.shp ...