Questions tagged [ogr2ogr]

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

Filter by
Sorted by
Tagged with
32
votes
1answer
25k views

Converting GeoJSON to 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:...
29
votes
7answers
13k 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 ...
27
votes
8answers
21k views

Using ogr2ogr to convert all shapefiles in 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 ...
26
votes
3answers
22k views

Selecting feature types when using ogr2ogr to convert to shapefile?

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 ...
25
votes
4answers
26k views

Using ogr2ogr to convert 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 ...
23
votes
3answers
9k views

Uploading Geopackage contents to PostgreSQL

As a bit of background, we are looking to transition away from the use of shapefiles. We've already started using Geopackages for desktop work (QGIS / ArcGIS) but often have a requirement to upload ...
22
votes
2answers
20k views

How to Import ESRI Geodatabase format .gdb into PostGIS

I ran into a problem when loading a ESRI Geodatabase format .gdb into PostGIS. I have data 2.5GB GDB file. I followed some tutorials on the internet, but it seems that doesn't work out. I created a ...
20
votes
1answer
14k views

Selecting features by attributes using ogr2ogr?

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 ...
20
votes
2answers
22k 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" encoding="UTF-8"?>...
19
votes
2answers
13k views

Dissolve/aggregate polygons with ogr2ogr or gpc?

I have a large number of polygons representing the boundaries of US counties which I need to merge into as few polygons as possible. Is it possible to do this with non-commercial software, or ...
18
votes
3answers
15k 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 output....
17
votes
9answers
11k views

Adding 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 %...
17
votes
1answer
20k views

Import a shapefile to postgis with ogr2ogr gives: Unable to open datasource

I want to use ogr2ogr in order to import a shapefile in a postgis database. I have successfully installed ogr2ogr and I run from the pgsql the following command: ogr2ogr -f "PostgreSQL" PG:"host=...
15
votes
4answers
22k views

Repairing broken GDAL and PROJ.4 on Ubuntu?

I solved the library problem, but others remain, only vaguely related to that of PROJ.4 library not loaded. I asked a follow-up question for these. My GDAL package and PROJ.4 library are damaged, ...
15
votes
2answers
12k views

ogr2ogr merge multiple shapefiles: What is the purpose of -nln tag?

The basic script in order to iterate recursively over sub-folders and merge all shapefiles into single one is: #!/bin/bash consolidated_file="./consolidated.shp" for i in $(find . -name '*.shp'); do ...
15
votes
3answers
42k views

Is it possible to convert regular JSON to GeoJSON?

I have JSON data I've exported from Openpaths.cc which contains lat and lon values. However, the data is not in GeoJSON format so can't be read by OGR2OGR. Could anyone point me in the right direction ...
14
votes
2answers
13k views

Loading shapefile to a specific table in postgis using ogr2ogr

I have already created a geometry table in postgis. I want to load several shapefiles into that table using ogr2ogr. But I didn't find the parameter which could specify that table. ogr2ogr -append -...
14
votes
2answers
3k views

ogr2ogr from file to PostgreSQL 12 table fails

Using CentOS 8.0 with PostgreSQL 12, PostGIS 3, and GDAL/OGR 3.0.1. I want to append a file to a database table. Previously (before upgrading to the new system) I used ogr2ogr -f "PostgreSQL" PG:"...
12
votes
2answers
3k views

Piping data to ogr2ogr

Is it possible to directly pipe data to ogr2ogr? I'm trying to curl a GeoJSON file and pipe it to ogr2ogr to covert it to another format. Without using a pipe, I was able to achieve this by first ...
12
votes
1answer
2k 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 ...
11
votes
3answers
7k views

How to find the attributes of a shapefile from the command line?

I'm following Mike Bostock's tutorial "Let's Make A Map." He explains how to filter a shapefile using ogr2ogr based on the attributes of the features. I can open a shapefile in QGIS and look at the ...
11
votes
1answer
5k views

og2ogr character encoding problem

When I'm dissolving a shapefile: ogr2ogr "b:\out.shp" "b:\Tele.shp" -dialect sqlite -sql "SELECT ST_Union(geometry), nev, jar FROM Tele GROUP BY jar" I got error message like: Warning 1: One or ...
10
votes
1answer
20k 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). ...
10
votes
2answers
8k 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 ...
9
votes
4answers
18k views

Converting multipoint layer to point using PostGIS?

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 ...
9
votes
1answer
4k 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. ...
9
votes
1answer
8k views

How do I create/write a Shapefile with UTF-8 encoded attributes with ogr2ogr?

I'm using GDAL/OGR's ogr2ogr command line tool to export data from a PostGIS-enabled PostgreSQL database to various GIS file formats, Shapefile amongst them. To create a shapefile with the default ...
9
votes
2answers
975 views

ogr2ogr encoding on Windows using os4geo shell with Census data

I'm trying to load Census county level TIGER/line spatial layers into PostGIS using ogr2ogr in Windows. Is there anyway to configure the encoding to LATIN1? example: ogr2ogr -f "PostgreSQL" PG:"...
9
votes
1answer
1k views

Using shp2pgsql instead of ogr2ogr to import shapefile to PostGIS? [closed]

I may very well be doing something wrong here, but: If I import some shapefile to a PostGIS database using shp2pgsql, I have to first figure out the SRID/EPSG of that shapefile. I think this is, at ...
9
votes
1answer
815 views

Why isn't QGIS detecting CRS from .prj file?

I have a number of 1 km hexagonal grids that cover various counties in the United States in a postgreSQL/postGIS database. Each grid has the CRS EPSG:3857, and the counties layer has EPSG:3857. When ...
8
votes
2answers
4k views

ogr2ogr error importing shapefile into PostGIS : "numeric field overflow"

I'm trying to import a shapefile into a PostGIS database using ogr2ogr as follows: ogr2ogr -lco GEOMETRY_NAME=geom -lco LAUNDER=NO -a_srs "EPSG:4326" -f "PostgreSQL" PG:"dbname=db" test.shp This is ...
8
votes
3answers
6k views

How to make a local copy of a large WFS dataset?

We are writing a application in which a part of the job is to fetch a relatively large (>10000 features) and often updated dataset from a WFS server, store a local copy, and do geospatial analyses on ...
8
votes
3answers
7k views

Execute ogr2ogr from python

I tried to execute ogr2ogr from python with this shell command: ogr2ogr.exe --config PG_LIST_ALL_TABLES YES -f "PostgreSQL" -append PG:"host=hostnamet user=username password=password dbname=dbname" ...
8
votes
1answer
2k views

select by location using ogr2ogr sqlite

I have a shapefile containing polygons and a shapefile containing points. Now I would like to select the polygons that contain points. How can I do this from the command line using ogr2ogr?
8
votes
1answer
14k views

ogr2ogr : Converting KML to GeoJson

I have a requirement to convert .KML file to GeoJSON or JSON. Can you please recommend open source command line tools on GNU/Linux(2.6.32-358.14.1.el6.x86_64)? I have installed gdal, when I run.. ...
8
votes
1answer
1k views

QGIS Point on Surface

As far as I can tell, the option to "Create point on surface for each part" in the QGIS Centroid tool is not returning the correct geometry when activated in QGIS (version 3.8.1-Zanzibar/GDAL v 2.2.3 ...
8
votes
2answers
4k views

ogr2ogr sql query from text file

In ogr2ogr or ogrinfo, I can successfully query an Oracle database using this command as a test: ogrinfo -al -so "OCI:USER/PASSWORD@SERVER/DATABASE" -sql "SELECT * FROM SCHEMA.TABLE" However, ...
8
votes
1answer
3k views

Specifying element type for DXF creation using ogr2ogr

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 ...
8
votes
1answer
137 views

"Flooded" islands in converted OSM data

I'm having a problem with "flooded" islands when converting OSM natural=water data to shapefiles and opening it in qgis. It doesn't happen consistently; as you can see from the attached screenshot, ...
8
votes
1answer
293 views

ogr2ogr TPS spline method creates progressive error

I am trying to adjust a shapefile using ogr2ogr spline transformation with cmd commands like: C:\OSGeo4W64\bin\ogr2ogr.exe -f "ESRI Shapefile" C:\path\output.shp -tps --optfile C:\path\gcp.txt C:\...
8
votes
1answer
668 views

How do I load 1 billion points into PostGIS?

I have a file geodatabase containing research data that I need to load into PostGIS. The GDB contains one feature class with one billion records with three columns (the FID, a FK, and the geometry (...
7
votes
3answers
5k views

Converting multilayer KML files to GeoJSON using ogr2ogr

I have a kml file that I'm trying to convert to GeoJSON. However, it turns out there's multiple layers, and ogr2ogr isn't happy. $ ogr2ogr -f GeoJSON shapes.json shapes.kml ERROR 6: GeoJSON driver ...
7
votes
1answer
4k views

How to assign a schema to ogr2ogr?

According to http://www.gdal.org/drv_mssqlspatial.html I should be able to add a SCHEMA to my connection string to override the default "dbo" schema: SCHEMA: Set name of schema for new table. If ...
7
votes
2answers
3k views

ogr2ogr clip all shapefiles in a directory

I am new to ogr2ogr. Does anyone know if it is possible to loop through all shapefiles in a directory, clip and output them into an identical directory with a suffix "_clipped"? I saw this similar ...
7
votes
1answer
2k views

Specify geom field name with ogr2ogr: gdb to PostgreSQL

I use the following ogr2ogr command to import my open file geodatabase into PostgreSQL. # Note, I use the -append because I am adding to preexisting tables with the same structure ogr2ogr -append -f ...
7
votes
2answers
3k views

Moving SpatiaLite Table into PostgreSQL using ogr2ogr?

How can I move a Spatialite table from a Spatialite db to a PostgreSQL db using ogr2ogr?
7
votes
1answer
721 views

Creating gpkg with many layers using ogr2ogr

I am trying to merge many shapefiles into a single gpkg using ogr2ogr (version 3.0.2). The command I am using is: ogr2ogr dst.gpkg src.shp -nln layerOne ogr2ogr dst.gpkg src.shp -nln layerTwo BUT ...
7
votes
2answers
6k 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: ...
7
votes
1answer
17k views

Problem 'unable to open datasource" with ogr2ogr to reproject shapefile

I have no idea why I get the following error: FAILURE: Unable to open datasource `Sydney2.shp' with the following drivers. I have already checked successfully the shape with ogrinfo. I am using the ...
7
votes
1answer
2k views

Reading GeoPackage with large feature classes is very slow

I'm running a project which provides OpenStreetMap data on a global scale as GeoPackages. The data is created/transferred from a PostGIS database to GeoPackage by ogr2ogr. Issue: Initially reading of ...

1
2 3 4 5
20