Friday, August 8, 2014

transform openstreetmap file to shape file

  • I downloaded the openstreetmap of Saxony from geofabrik
  • I saved the file sachsen-latest.osm.pbf
  • use ogrinfo to show the layers

ogrinfo sachsen-latest.osm.pbf
: Had to open data source read-only.
: INFO: Open of `sachsen-latest.osm.pbf'
:       using driver `OSM' successful.
: 1: points (Point)
: 2: lines (Line String)
: 3: multilinestrings (Multi Line String)
: 4: multipolygons (Multi Polygon)
: 5: other_relations (Geometry Collection)

  • then use ogr2ogr to transform a layer to a shapefile
  • additional I used the spat argument for only including the Leipzig region

ogr2ogr -spat 12.2 51.2 12.6 51.45 -f "ESRI Shapefile" sachsen2.osm.pbf sachsen-latest.osm.pbf multipolygons

Author: Mandy Vogel

Created: 2014-08-08 Fr 09:25

Emacs 24.3.1 (Org mode 8.2.5h)

Validate

Wednesday, August 6, 2014

Filter SpatialPolygonsDataFrame

  • by id
> subset(sp.data.frame, id %in% myIDs)
  • by coordinates
> range <- cbind(c(long1,long2), c(lat1,lat2))
> centroids <- coordinates(sp.data.frame)
> spdf.subset <- sp.data.frame[centroids[,1] > range[1,1] &
                    centroids[,1] < range[2,1] &
                    centroids[,2] > range[1,2] &
                    centroids[,2] < range[2,2],]