21 Jan

Dowload OpenStreetMap (OSM) data and read it in QGIS

Happy New GIS,

Be sure to get the last version of GDAL (Ubuntu installation)

Go to Geofabrik.
Download the compressed .osm.pbf files corresponding to our area (Continent, Country).

Using ogr to convert the pbf file into a SQlite database which can be used directly in QGIS with Add SpatiaLite Layer.

ogr2ogr -f "SQLite" -dsco SPATIALITE=YES -spat xmin ymin xmax ymax GuruBlard_Region.db OSM_continent.pbf

where xmin ymin xmax ymax:
spatial query extents, in the SRS of the source layer(s) (or the one specified with -spat_srs). Only features whose geometry intersects the extents will be selected. The geometries will not be clipped unless -clipsrc is specified

For further information, visit this post of Anita Graser.

20 Feb

Merge shapefiles list using OGR (ogr2ogr)

Tired of using ArcGis to merge a huge number of shapefiles?

Here is a simple way to use ogr2ogr and merge shapefiles, so easy!

 
list_files<-Sys.glob('/path_to_shapefiles/*.shp')
 
#create destination file (copy of the first file to merge)
merged_file<-'/path_to_my_results/merged_shapefile.shp'
system(paste(
  'ogr2ogr',
  merged_file,
  list_files[1]))
 
# update the merged_fille by appending all the shapefiles of the list list_files
for (i in seq(2,length(list_files))){
system(paste('ogr2ogr',
             '-update',
             '-append',
             merged_file,
             list_files[i]
             ))
}