Last active
May 3, 2017 07:06
-
-
Save alfcrisci/46afa3b34aeb9f0bfe4523998ab79bbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(gdalUtils) | |
| require(rgdal) | |
| require(rgeos) | |
| require(Hmisc) | |
| require(overpass) | |
| #' retrieve_adm3_bound | |
| #' | |
| #' @description Retrieve by Overpass API query the bounding box of italian municipalities | |
| #' | |
| #' @param nameadm3 Character Italian name of municipalities ( ADM level 3). | |
| #' @author Istituto di Biometeorologia Firenze Italy Alfonso Crisci \email{a.crisci@@ibimet.cnr.it} | |
| #' @references \url{http://stackoverflow.com/questions/6364783/capitalize-the-first-letter-of-both-words-in-a-two-word-string} | |
| #' @keywords Openstreetmap, Estratti, Italian Extracts | |
| #' | |
| # | |
| #' | |
| #' @export | |
| #' | |
| retrieve_adm3_bound=function(nameadm3,level=8) { | |
| tryq <- paste0('[out:xml]; (rel["boundary"="administrative"]["admin_level"="', | |
| level, | |
| '"]["name"="', | |
| Hmisc::capitalize(nameadm3), | |
| '"];);(._;>;);out body;' | |
| ); | |
| base=try(overpass::overpass_query(tryq)); | |
| temp=try(rgeos::gPolygonize(base)); | |
| try(proj4string(temp)<- CRS("+init=epsg:4326")); | |
| try(proj4string(base)<- CRS("+init=epsg:4326")); | |
| temp$name=Hmisc::capitalize(nameadm3); | |
| res=list(base,temp) | |
| names(res)=c("sp_lines","sp_poly") | |
| return(res) | |
| } | |
| ogrinfo("WFS:http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Toponimi_2011.map") | |
| calenzano=retrieve_adm3_bound("calenzano") | |
| retrieve_toponimi_IGM=function(x,nameadm3) { | |
| system(paste0("ogr2ogr -f \'GML\' temp.gml WFS:\"http://wms.pcn.minambiente.it/ogc?map=/ms_ogc/wfs/Toponimi_2011.map&bbox=", | |
| raster::extent(x)[1],",", | |
| raster::extent(x)[3],",", | |
| raster::extent(x)[2],",", | |
| raster::extent(x)[4],"\"", " NG.TOPONIMI.")) | |
| toponimi=rgdal::readOGR(paste0(nameadm3,".gml"),layer="NG.TOPONIMI.","GML") | |
| return(as.data.frame(toponimi)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment