User Tools

Site Tools


osm_qgis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
osm_qgis [2023/03/04 18:50] bushwalkingosm_qgis [2023/12/11 09:20] (current) – osmconf changes bushwalking
Line 1: Line 1:
 +====== Mapping with OSM Data in QGIS ======
 +
 This topic builds on the [[nsw_lidar|Mapping from NSW Lidar with QGIS]] tutorials, though the data can also be used standalone. This topic builds on the [[nsw_lidar|Mapping from NSW Lidar with QGIS]] tutorials, though the data can also be used standalone.
  
Line 5: Line 7:
 There's a few steps to get going. There's a few steps to get going.
  
-====== Download raw data ======+===== Download raw data ===== 
  
 Download the .PBF file (australia-latest.osm.pbf) from Download the .PBF file (australia-latest.osm.pbf) from
Line 11: Line 14:
 http://download.geofabrik.de/australia-oceania/australia.html http://download.geofabrik.de/australia-oceania/australia.html
  
-====== Convert data ======+===== Convert data =====
  
-===== Basic =====+==== Basic ====
  
 Open up the OSGEO4W Shell that comes with QGIS (look under Start -> All Programs -> QGIS) Open up the OSGEO4W Shell that comes with QGIS (look under Start -> All Programs -> QGIS)
Line 21: Line 24:
  https://github.com/AmericanRedCross/workflows/blob/master/converting_pbf_into_spatialite.md   https://github.com/AmericanRedCross/workflows/blob/master/converting_pbf_into_spatialite.md 
    
-''ogr2ogr -f "SQLite" -dsco SPATIALITE=YES {name_of_new_file}.db {name_of_extracted_file}.pbf'' +<code>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES {name_of_new_file}.db {name_of_extracted_file}.pbf</code>
  
-eg ''ogr2ogr -f "SQLite" -dsco SPATIALITE=YES E:\geodata\ausosm-20230303.db E:\geodata_raw\australia-20230303.osm.pbf''+eg <code>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES E:\geodata\ausosm-20230303.db E:\geodata_raw\australia-20230303.osm.pbf</code>
  
 It's useful to include the date in the filenames so you know when the data is from. It's useful to include the date in the filenames so you know when the data is from.
  
-===== Cropping =====+==== Cropping ====
  
 If you need to crop the PBF file, the use the following command: If you need to crop the PBF file, the use the following command:
-''ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat {x min} {y min} {xmax} {ymax} {output filename}.db {input file name}.osm.pbf''+<code>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat {x min} {y min} {xmax} {ymax} {output filename}.db {input file name}.osm.pbf</code>
  
-eg For NSW data only, you could run: ''ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat 141 -37.5 153.75 -28 E:\geodata\nswosm-20230303.db E:\geodata_raw\australia-20230303.osm.pbf''+eg For NSW data only, you could run: <code>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat 141 -37.5 153.75 -28 E:\geodata\nswosm-20230303.db E:\geodata_raw\australia-20230303.osm.pbf</code>
  
 The coordinates above are in the following order: West South East North  The coordinates above are in the following order: West South East North 
  
-===== Fields =====+==== Fields ====
  
 You may want to control the fields that you are importing from OSM. This is done using the osmconf.ini file, that can be found under your QGIS installation eg C:\Program Files\QGIS 3.22.10\apps\gdal\share\gdal\osmconf.ini You may want to control the fields that you are importing from OSM. This is done using the osmconf.ini file, that can be found under your QGIS installation eg C:\Program Files\QGIS 3.22.10\apps\gdal\share\gdal\osmconf.ini
Line 52: Line 55:
 If you make any changes, take a backup of your osmconf.ini file. If you upgrade QGIS, it will revert to the default, and you'll need to restore osmconf.ini if you want those fields to come through next time you process an OSM file. If you make any changes, take a backup of your osmconf.ini file. If you upgrade QGIS, it will revert to the default, and you'll need to restore osmconf.ini if you want those fields to come through next time you process an OSM file.
  
-====== Load data in QGIS ======+It may be worth storing a copy of it in (say) your profile folder for QGIS, which is retained on upgrade eg C:\Users\<username>\AppData\Roaming\QGIS\QGIS3\profiles\default, and doesn't need admin permissions to edit. 
 + 
 +You can then use the ''-oo'' flag in the convert data process to point to the file location eg: 
 + 
 +<code>ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -oo CONFIG_FILE=C:\Users\brennant\AppData\Roaming\QGIS\QGIS3\profiles\default\osmconf.ini E:\geodata\ausosm-20231210.db E:\geodata_raw\australia-20231210.osm.pbf</code> 
 + 
 +===== Load data in QGIS =====
  
 Open QGIS. Open QGIS.
Line 62: Line 71:
 Once you have set up the connection, you can extract data using (for example) the Processing Toolbox->Vector Overlay->Extract/clip by extent. Select one of the layers within the file (points, lines, multipolygons) as the Input Layer, and select an area to load - by map or by file. Be careful not to make it too large, or you'll get very slow performance. Once you have set up the connection, you can extract data using (for example) the Processing Toolbox->Vector Overlay->Extract/clip by extent. Select one of the layers within the file (points, lines, multipolygons) as the Input Layer, and select an area to load - by map or by file. Be careful not to make it too large, or you'll get very slow performance.
  
-====== Style data in QGIS ======+===== Style data in QGIS =====
  
 Here are some sample bushwalking-based style files for OSM points and OSM lines: Here are some sample bushwalking-based style files for OSM points and OSM lines:
Line 79: Line 88:
  
  
-====== Links ======+===== Links =====
  
 Some other methods of getting OSM data into QGIS can be found at https://wiki.openstreetmap.org/wiki/QGIS_tutorial Some other methods of getting OSM data into QGIS can be found at https://wiki.openstreetmap.org/wiki/QGIS_tutorial
  
osm_qgis.1677916218.txt.gz · Last modified: 2023/03/04 18:50 by bushwalking

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki