[R-sig-Geo] question on writing shapefiles from OSM data

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Sun Feb 2 15:21:08 CET 2020


On Sat, 1 Feb 2020, Gabriel Cotlier wrote:

> Dear users,
> I would like to download OSM data and convert it to shapefile and change
> coordinates to same as Landsat data.
> I'm following the code bellow.
> Is this the correct way for saving/writing to swapfile the OSM data?

Since you are using the sf package, why not use it for the other 
operations? There is no need to involve sp or rgdal unless you want to for 
some other reason. Maybe you are copying from an old blog or SO source? 
Have you visited: https://www.r-spatial.org/ with plenty of posts on 
migrating to sf?

With regard to coordinate operations, you (and everybody else) will need 
to find out how to define CRS without using Proj.4 strings; this change is 
coming soon! Yours looks like EPSG:32636. Both sf and sp will be moving 
very soon to WKT2-2019 from Proj.4 strings (Proj.4 strings will still be 
available, but datums and other specification components may simply drop 
out without warning because of changes in PROJ and GDAL).

Finally, stop using shapefiles and change to GeoPackage straight away, 
there is no reason to continue to use a format past its end-of-life.

Roger

> Thanks a lot for your response.
> Best,
>
> library(osmar)
> library(osmdata)
> library(OpenStreetMap)
> library(tmap)
>
> # Paris administrative borders ID
> id<-c(7444)
> dat2 <- opq_osm_id (type = "relation", id = id) %>%
>  opq_string () %>%
>  osmdata_sf ()
> qtm(dat2$osm_multipolygons)
>
> library(sf)
> st_write(dat2$osm_multipolygons, "s.shp")
> # change coordinate system to Landsat data
> landst_crs= "+proj=utm +zone=36 +datum=WGS84 +units=m +no_defs +ellps=WGS84
> +towgs84=0,0,0"
> s=readOGR('/Users/gcotlier/Desktop/s.shp')
> S <- spTransform(s, CRS(landst_crs))
> writeOGR( obj = S, dsn = '/Users/gcotlier/Desktop',layer = "S1", driver =
> "ESRI Shapefile")
> S1=readOGR('/Users/gcotlier/Desktop/S1.shp')
> plot(S1)
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en



More information about the R-sig-Geo mailing list