28
votes
Accepted
Import a shapefile to postgis with ogr2ogr gives: Unable to open datasource
As you discovered by trial and error, there were few nagging issues you needed to fix, the last of which was resolved using ogr2ogr's -nlt GEOMETRY* argument.
* Note the recommendation in @...
24
votes
Accepted
Uploading Geopackage contents to PostgreSQL
This tutorial shows how to import geopackges into postgres with ogr2ogr like:
ogr2ogr -f PostgreSQL "PG:dbname=gadm" DNK_adm.gpkg
Note importing into PostgreSQL like this will convert the case of ...
22
votes
Accepted
Piping data to ogr2ogr
OGR has its own idiom for stdin, /vsistdin/. Use that as ogr2ogr's first argument (the dst_datasource_name) and you can pipe curl's output to it:
curl "https://raw.githubusercontent.com/nvkelso/...
19
votes
Loading shapefile to a specific table in postgis using ogr2ogr
To be explicit about nickves' answer:
ogr2ogr -append -f "PostgreSQL" PG:"dbname=db" shapefile.shp -nln mytable
19
votes
Accepted
ogr2ogr merge multiple shapefiles: What is the purpose of -nln tag?
For GDAL there are datastores which contain layers. Some datastores, like the database ones or GML, can hold several layers but some others like shapefiles can only contain one layer.
You can test ...
18
votes
Accepted
ogr2ogr error importing shapefile into PostGIS : "numeric field overflow"
For making the conversion to success read the manual page http://www.gdal.org/drv_pg.html from section Layer Creation Options
PRECISION: This may be "YES" to force new fields created on this layer
...
16
votes
Accepted
Creating gpkg with many layers using ogr2ogr
You are overwriting dst.gpkg every time you run ogr2ogr. From the geopackage documentation:
For adding new layers into existing geopackage run ogr2ogr with -update.
So do:
ogr2ogr -f GPKG dst....
15
votes
How to export thousands of features from PostGIS to a single GeoJSON file?
There is, yes, using a combination of row_to_json, array_to_json, array_agg and ST_AsGeoJSON. I realize, on rereading your question, that you asked for ogr2ogr approach, but seeing as your source is ...
15
votes
Repairing broken GDAL and PROJ.4 on Ubuntu?
In https://gis.stackexchange.com/questions/158457/gdal2tiles-how-to-make-filenames-of-tiles-to-represent-xyz-coordinates, somebody mentions doing:
sudo ln -s /usr/lib/libproj.so.0 /usr/lib/libproj.so
...
15
votes
Accepted
How do I create/write a Shapefile with UTF-8 encoded attributes with ogr2ogr?
How can I get ogr2ogr to write a UTF-8 encoded *.dbf file when exporting to Shapefile?
Similar to How to encode shapefiles from LATIN1 to UTF-8?, this is possible with -lco ENCODING=UTF-8. So for my ...
15
votes
Accepted
How to assign a schema to ogr2ogr?
SCHEMA is a "layer creation option", specified with the -lco parameter. This should do the trick (split into multiple lines here for readability):
call ogr2ogr -overwrite -skipfailures -f ...
15
votes
How to clip very large shapefile in QGIS using ogr2ogr?
On windows environnement, if you installed Qgis with OSGeoW setup you have access to a shell which can run directly gdal/ogr.
to run a clic processing use this command
ogr2ogr -clipsrc clip_polygon....
14
votes
Accepted
ogr2ogr clip all shapefiles in a directory
Modifying the referenced answer, in the Windows command line:
for /R %f in (*.shp) do ogr2ogr "%~dpnf_clipped.shp" -clipsrc clipper.shp "%f"
You just add _clipped to the output. Note, this will also ...
14
votes
Accepted
Specify geom field name with ogr2ogr: gdb to PostgreSQL
In the help in ogr2ogr --long-usage, there is layer creation option:
-lco NAME=VALUE: Layer creation option (format specific)
You can use the driver specific option GEOMETRY_NAME=geom to
Set ...
13
votes
Accepted
Converting csv to kml/geojson using ogr2ogr or equivalent command line tools?
According to the ogr2ogr csv documentation and also this answer, you need to specify which fields contain the geometry in a VRT file:
<OGRVRTDataSource>
<OGRVRTLayer name="test">
...
13
votes
Accepted
select by location using ogr2ogr sqlite
At the following link all SQL functions that test spatial relationships are described:
http://www.gaia-gis.it/spatialite-2.4.0/spatialite-sql-2.4.html#p12.
The following spatial relationships can be ...
12
votes
Accepted
Moving SpatiaLite Table into PostgreSQL using ogr2ogr?
And, after a bit more reading the ogr2ogr help I found the answer more easily than I expected.
ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb -sql "SELECT * FROM table" -dialect spatialite -nln ...
12
votes
Converting csv to kml/geojson using ogr2ogr or equivalent command line tools?
Starting with GDAL 2.1, it is possible to directly specify the
potential names of the columns that can contain X/longitude and
Y/latitude with the X_POSSIBLE_NAMES and Y_POSSIBLE_NAMES open option....
12
votes
Accepted
Resolving relation does not exist in PostGIS?
This is a case sensitivity/quoting issue.
"PointsForGpxExport" and PointsForGpxExport are not the same table name.
PostgreSQL, per the SQL standard, case-folds unquoted identifiers. (It case-folds ...
12
votes
Accepted
Bulk csv to shapefile (using ogr2ogr)
A modern-enough GDAL can convert CSV files directly into shapefiles. For the test.csv file in the documentation, http://www.gdal.org/drv_csv.html - you can do:
ogr2ogr -s_srs EPSG:4326 -t_srs EPSG:...
11
votes
Piping data to ogr2ogr
You can use URLs as paths to OGR data sources, so you don't need curl or pipes.
ogr2ogr -f KML countries.kml https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/...
11
votes
Accepted
Repairing broken GDAL and PROJ.4 on Ubuntu?
After several wrong ways, including multiple reinstall of libproj0 package and even installing QGIS from sources different from the Ubuntu Software Center default (I think it's from the official QGIS ...
11
votes
Accepted
og2ogr character encoding problem
Type -lco before the ENCODING=UTF-8 part, a.k.a -lco ENCODING=UTF-8 and it should work (it did for me and my strange Polish characters).
11
votes
Accepted
ogr2ogr from file to PostgreSQL 12 table fails
I have the same issue (this morning) and started to search for some solutions and the only thing I found is that is a GDAL PG12 problem, which was solved in a commit of GDAL in July 2019.
This means ...
11
votes
Accepted
Creating point on surface in QGIS
In QGIS 3.10 this option is not available using Vector > Geometry Tools > Centroids.
However if you search for "Point on surface" in the Processing Toolbox (Ctrl+Shift+T) using QGIS ...
10
votes
Accepted
How to rename ogr2ogr tables on export to Spatialite?
From the ogr2ogr docs, use the -nln name option to assign an alternate name to the new layer.
10
votes
Execute ogr2ogr from python
subprocess.call and subprocess.check_call both take lists with strings as input and separate each argument with a blank space. Your command would be:
import os, subprocess
base_path = "some/file/...
10
votes
Accepted
ogr2ogr difference between -a_srs and -s_srs
From the ogr2ogr page:
-a_srs srs_def: Assign an output SRS
-t_srs srs_def: Reproject/transform to this SRS on output
-s_srs srs_def: Override source SRS
So we can see they have very different ...
10
votes
Accepted
ogr2ogr keep geometry when converting to CSV?
For the coordinates, see Getting list of coordinates for points in layer using QGIS? or Reproject CSV file to different projecton using ogr2ogr
-lco GEOMETRY=AS_XY is what you need.
For the error ...
10
votes
Accepted
Action to directly export selected features as GPX
If it were a single feature to export you could use an action with canvas scope (i.e., interacting with the canvas), but since you may export several features, an action with layer scope fits better.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ogr2ogr × 1021gdal × 293
shapefile × 190
postgis × 176
geojson × 110
ogr × 104
qgis × 98
postgresql × 93
python × 70
coordinate-system × 59
kml × 52
sql × 49
openstreetmap × 47
file-geodatabase × 47
sqlite × 41
convert × 39
spatialite × 36
sql-server × 35
geopackage × 31
csv × 29
dxf × 26
gml × 21
osgeo4w × 19
mapinfo × 17
sql-server-spatial × 17