QGIS med SOSI-støtte på Windows

This post is also available in English.

  • Last ned og kjør OSGeo4W network installer, i stedet for frittstående QGIS.
  • Velg avansert installasjon.
  • Velg ønsket QGIS-versjon å installere fra Desktop-kategorien. [2]
  • Velg pakken gdal-sosi fra Libs-kategorien for å installere sammen med QGIS.
  • Kjør C:\OSGeo4W\bin\ogrinfo.exe ‐‐formats (hvis du valgte å installere på standard sted) og forsikre deg om at SOSI er på listen over støttede formater.
  • Start QGIS og se under Innstillinger -> System at GDAL_DRIVER_PATH viser til C:\OSGeo4W\bin\gdalplugins.

Det var det hele! Men i praksis kan det hende at du heller vil konvertere filene til et annet format:

Alternativ 1: Ett nytt verktøy fra Espen Andersen, sosicon, gjør det veldig enkelt å konvertere SOSI-filer til ESRI Shape-formatet. Dersom det ikke er nødvendig å åpne SOSI-filer direkte i QGIS (eller du ikke bruker QGIS i det hele tatt) anbefaler jeg at du prøver sosicon først. Windows, Linux og Mac OS X-utgaver er tilgjengelige på Andersens github.

Alternativ 2: QGIS, GRASS og annen GIS-programvare basert på åpen kildekode benytter seg av GDAL og OGR-bibliotekene for å åpne raster og vektordata, og disse kommer med sine egne kommandolinjebaserte verktøy, som kan brukes for å konvertere filene uten å involvere QGIS. Tidligere måtte man kompilere bibliotekene på egen hånd for å få SOSI-støtte, slik man må for Linux og OSX, men en enklere mulighet er nå tilgjengelig for Windows-brukere.

For å konvertere filer med ogr2ogr-verktøyet: [3]

  • C:\OSGeo4W\bin\ogr2ogr.exe <output>.shp <input>.sosi <layer>
  • (Eller bare ogr2ogr <output>.shp <input>.sosi <layer> dersom du bruker et OSGeo4W Shell-vindu)

Hvor <layer> typisk er enten points, lines eller polygons, slik:

  • C:\OSGeo4W\bin\ogr2ogr.exe somefile_pol.shp somefile.sosi polygons

“ESRI Shapefile” er formatet det skrives til som standard; for å velge et annet støttet lagringsformat tilføyes kommandoen -f fulgt av navnet slik det står i lista over tilgjengelige formater, slik:

  • C:\OSGeo4W\bin\ogr2ogr.exe -f “GPX” paths.gpx tfr.sosi lines

Det går også an å lage et script for å automatisere dette siste trinnet, eller prøve min script-versjon for linux eller windows.

 

Fotnoter:

1: Konvertering til Shape-formatet vil medføre at lange attributt-navn vil kuttes til ti tegns lengde, uten at det pleier å være noe problem.

2: Dersom du bruker en datamaskin med flere kjerner/prosessorer, vil jeg på det sterkeste anbefale at du velger QGIS 2.4 eller nyere, og at du passer på å aktivere multithreaded/parallell rendering fra menyen settings->options->rendering.

3: Det kan hende at norske tegn blir ødelagt i konverteringen; i slike tilfeller har løsningen for meg vært å definere inn- og ut-tegnsett via SHAPE_ENCODING og ENCODING.

QGIS with SOSI support on Windows

Denne posten er også tilgjengelig på norsk.

  • Download and run the OSGeo4W network installer, rather than standalone QGIS
  • Choose advanced installation
  • Select your preferred QGIS version to install from the Desktop category [2]
  • Select the package named gdal-sosi from the Libs category to install alongside QGIS
  • Run C:\OSGeo4W\bin\ogrinfo.exe ‐‐formats (if you chose to install in the default location) and verify that SOSI is on the list of supported formats
  • Run QGIS and under Settings -> System verify that GDAL_DRIVER_PATH is set to C:\OSGeo4W\bin\gdalplugins

That’s it! But in reality you might prefer to just convert the SOSI files to a different format:

Option 1: A new tool by Espen Andersen, sosicon, now makes it very easy to convert SOSI files to ESRI Shape format. If it is not necessary to access SOSI files directly in QGIS (or you’re not using QGIS at all) I recommend you try sosicon first. Windows, Linux and Mac OS X versions are available at Andersen’s github.

Option 2: QGIS, GRASS and other open source GIS-software rely on the GDAL and OGR libraries to access raster and vector data, and these come with their own command line tools that can be used to convert your files without involving QGIS. Previously you would have had to compile your own replacement library first to get SOSI support, like you do on Linux and OSX, but an easier option is now available for Windows users.

To convert files with the ogr2ogr tool: [3]

  • C:\OSGeo4W\bin\ogr2ogr.exe <output>.shp <input>.sosi <layer>
  • (Or just ogr2ogr <output>.shp <input>.sosi <layer> if you use the OSGeo4W Shell)

With <layer> typically being one of points, lines or polygons, like:

  • C:\OSGeo4W\bin\ogr2ogr.exe somefile_pol.shp somefile.sosi polygons

“ESRI Shapefile” is the default output format; to specify another (write-enabled) format, add the -f option and the name as written in the list of supported formats, like:

  • C:\OSGeo4W\bin\ogr2ogr.exe -f “GPX” paths.gpx tfr.sosi lines

You could also create a script to automate this final step, or try my script version for linux or windows.

 

Footnotes:

1: Converting to the Shape format will cause long attribute names to be truncated at ten characters; this is usually not a problem.

2: If you’re using a multi-core/CPU computer and QGIS 2.4 or newer, make sure you enable multi-threaded/parallel rendering from the settings->options->rendering menu.

3: Norwegian SOSI files tend to contain Norwegian characters, that may get lost in conversion. In such cases explicitly defining input and output character sets via SHAPE_ENCODING and ENCODING has solved the issue for me.

QGIS with SOSI support on Ubuntu 13.10

Denne posten er også tilgjengelig på norsk.

Update: A new tool by Espen Andersen, sosicon, now makes it very easy to convert SOSI files to ESRI Shape format. If it is not necessary to access SOSI files directly in QGIS (or you’re not using QGIS at all) I recommend you try sosicon first. Windows, Linux and Mac OS X versions are available at Andersen’s github.

I have recently been familiarising myself with QGIS and GRASS, two open source GIS suites that are available in Linux, OSX and Windows versions.

The datasets I am interested in are mostly from the Norwegian Mapping Authority, which means that being able to work with the Norwegian SOSI format is quite useful. Both of the GIS packages rely on GDAL and OGR for accessing raster and vector data, but to get SOSI support, you will have to remove the standard GDAL library and compile the library yourself, with SOSI enabled.

These are the steps I took to get SOSI support:

  1. Uninstall the gdal-bin package
  2. Follow the instructions at trac.osgeo.org/gdal/wiki/SOSI:
    • Install the dependencies, unless they are already installed
    • Download and build the Mapping Authority’s FYBA library
    • Download and build GDAL with SOSI enabled (building took close to an hour on my really slow computer)
    • I had to update the library cache (on Ubuntu 13.10)
  3. Somewhere along the path QGIS’ Python support had been uninstalled (and you probably want to have it) so just reinstall the python-qgis package
  4. Tada! I’m enjoying SOSIges!

As an added bonus, it feels like handling vector data is faster with the newer library, but that might be my imagination.

Note: If you would like to convert .sosi files into a different format, you want the ogr2ogr tool. Have a look at my Windows version of this post for a little more info on that.