Page 1 of 1 (5 posts)

  • talks about »
  • ogr

Last update:
Sat Jan 19 11:00:18 2019

A Django site.

QGIS Planet

WFS to PostGIS in 1 Step

This is an update to my previous post “WFS to PostGIS in 3 Steps”. Thanks to Even Rouault’s comments and improvements to GDAL, it is now possible to load Latin1-encoded WFS (like the one by data.wien.gv.at) into PostGIS in just one simple step.

To use the following instructions, you’ll have to get the latest GDAL (release-1600-gdal-mapserver.zip)

You only need to run SDKShell.bat to set up the environment and ogr2ogr is ready for action:

C:\Users\Anita>cd C:\release-1600-gdal-mapserver
C:\release-1600-gdal-mapserver>SDKShell.bat
C:\release-1600-gdal-mapserver>ogr2ogr -overwrite -f PostgreSQL PG:"user=myuser password=mypassword dbname=wien_ogd" "WFS:http://data.wien.gv.at/daten/geoserver/ows?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:BEZIRKSGRENZEOGD&srsName=EPSG:4326"

Thanks everyone for your comments and help!


Batch Shapefile Clipping

This is just a quick “note to self” on some interesting information I picked up from the QGIS mailing list today. Kudos to David J. Bakeman for sharing this:

If both the input and the output arguments to ogr2ogr are directories then it will clip all of the shapes in the source directory and write them to the output directory.

So: ogr2ogr -clipsrc mask.shp output source

Shapefiles are the default so you don’t even need the -f “ESRI Shapefile”.


Batch SHP to CSV Conversion with Reprojection

The following Shell script performs a conversion and reprojection of a folder full of Shapefiles to CSVs:

for f in `ls *.shp`; do
ogr2ogr -s_srs EPSG:4326 -t_srs EPSG:3035 -f CSV $f.csv $f -lco GEOMETRY=AS_XYZ
done

Thanks OGR!


How to Specify Data Types of CSV Columns for Use in QGIS

If you load .csv files through “Add vector layer”, all columns are interpreted as strings. That’s most likely not what you want, but it’s OGR’s default behaviour:

The OGR CSV driver returns all attribute columns with a type of string if no field type information file (with .csvt extension) is available.

Let’s create a .csvt file then!

The .csvt file has to have the same name as the .csv file it describes. (Same concept used in shapefiles.) It enables definition of the following data types: Integer, Real, String, Date (YYYY-MM-DD), Time (HH:MM:SS+nn) and DateTime (YYYY-MM-DD HH:MM:SS+nn).

A .csvt file contains only one line and the types for each column have to be quoted and comma separated, e.g.

"Integer","Real","String"

You can even specify width and precision of each column, e.g.

"Integer(6)","Real(5.5)","String(22)"

Read more at: www.gdal.org/ogr/drv_csv.html


GDAL/OGR 1.8.0 Released

The 1.8.0 release is a major new feature release with the following highlights:

  • New GDAL drivers: GTX, HF2, JPEGLS, JP2OpenJPEG, JPIPKAK, KMLSUPEROVERLAY, LOS/LAS, MG4Lidar, NTv2, OZI, PDF, RASDAMAN, XYZ
  • New OGR drivers: AeronavFAA, ArcObjects , GPSBabel, HTF, LIBKML, MSSQLSpatial, NAS, OpenAir, PDS, PGDump, SOSI, SUA, WFS
  • Significantly improved OGR drivers: DXF, GML
  • New implemented RFCs
  • New utility: gdallocationinfo

More complete information on the new features and fixes can be found in the GDAL/OGR 1.8.0 Release News.


  • Page 1 of 1 ( 5 posts )
  • ogr

Back to Top

Sponsors