Re: [R-sig-Geo] Elevation data
R raster::getData("SRTM", ...) will return elevation rasters at 90m resolution. See: https://www.rdocumentation.org/packages/raster/versions/2.5-8/topics/getData http://www.cgiar-csi.org/data/srtm-90m-digital-elevation-database-v4-1 --Mel. On 1/11/2017 6:26 AM, Miluji Sb wrote: Dear Michael, Thank you for your reply and the suggestions. Ideally, I would like a raster from which I can extract elevation at 1° x 1° resolution. I do not have much experience with working with DEM but have work with data such as GPW. I will definitely look at the datasets. Could you kindly suggest one that I could convert to raster and extract? Hope that's not a silly question. Sincerely, Milu On Wed, Jan 11, 2017 at 1:51 AM, Michael Sumnerwrote: Passed through? Maybe you want ?raster::extract There are a few versions of global elevation on CRAN, necessarily at low resolution but no overall summary afaik (someone should do this :). This is one: https://cloud.r-project.org/web/packages/GEOmap/index.html If you have the stomach for development versions of packages see elevatr: https://github.com/jhollist/elevatr I tend to have the high-resolution files at hand because we use them constantly, the main ones are Gebco14/Gebco08 and Etopo1/Etopo2 (from Smith-Sandwell). There's a reasonable overview here, you probably should find a specific data set that is at the resolution you are after already, and you can cite its derivation for your work: http://vterrain.org/Elevation/global.html Cheers, Mike. On Wed, 11 Jan 2017 at 10:20 Miluji Sb wrote: Dear all. Is there a way to download global elevation data at the 1° x 1° resolution in R using a given set of coordinates? I know about the getData() function but can many coordinates be passed through this? Thanks! Sincerely, Milu [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo University of Tasmania Electronic Communications Policy (December, 2014). This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise. . -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] shortestPath in a loop
Generically independent of R, A graph and the connectivity between points needs defined before a shortest path algorithm can be applied. If it assumes all points are connected, than the shortest path will be a straight line. What you are looking for is some sort of minimum spanning tree for the vertices. Eric On Thu, Jan 12, 2017 at 11:17 AM, marta azoreswrote: > Dear forum members, > > I would like to know how join several points with the aim to track a ship. > > After reading the documentation of some packages, I decided to use the > function shortestPath, but I only got the line between the first and the > last location of my points list. I need the complete survey, including also > the middle points. I try a loop to build the survey of the boats using > their locations, but It didn't work to me. > > > Any idea? > > Thanks in advance, > > Marta > > #script# it's also attached in a R.file: question loop2.R > ## > # > #raster# it's attached > azoTS1<- raster("C:/Users/Documents/azoTS1.tif")#wgs84 > # > #10 points# it's attached > boat <- read.table("C:/Users/Documents/10pontos.csv", header=TRUE, > sep=",", na.strings="NA", dec=".", strip.white=TRUE)# > head(boat) > > #raster to transitionlayer > trCostS4<- transition(1/azoTS1, mean, directions=4) > > # points to spatialpointsdataframe > x=boat$Long1 > y=boat$Lat1 > coords = cbind(x, y) > plot(coords) > sp = SpatialPoints(coords, proj4string=CRS("+proj=longlat +ellps=WGS84 > +datum=WGS84"), bbox = NULL) > sp > spdf=SpatialPointsDataFrame(sp,boat) > spdf > nrow(spdf) > plot(sp,axes=TRUE) > plot(spdf,add=TRUE, axes=TRUE) > > #shortestpath > > ## 1) this script only join the first point of the list and the last one, > and the points in the middle are not used. > CostpathSPdf <- shortestPath(trCostS4, spdf[1,], spdf[10,], > output="SpatialLines") > plot(CostpathSPdf,add=TRUE,axes=TRUE,col=2)#R_plot1.png (it's attached) > > ## 2) this script didn't work to me > > #first way from website: http://stackoverflow.com/ > questions/8127066/loop-or-sapply-function-for-multiple- > least-cost-analysis-in-r?answertab=active#tab-top > for(i in 1:nrow(spdf)) { > # Computation > Costpath <- shortestPath(trCostS4, spdf[i,], spdf[10,], > output="SpatialLines") > plot(Costpath) > > } > > #Error in validObject(.Object) : > #invalid class “SpatialLines” object: bbox should never contain infinite > values > > ___ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] shortestPath in a loop
This seems impossible ( to get right, you can certainly get an answer) in general terms, do you really not know either an order of the points and/or their relative spacing in time? On Fri, Jan 13, 2017, 03:18 marta azoreswrote: > Dear forum members, > > I would like to know how join several points with the aim to track a ship. > > After reading the documentation of some packages, I decided to use the > function shortestPath, but I only got the line between the first and the > last location of my points list. I need the complete survey, including also > the middle points. I try a loop to build the survey of the boats using > their locations, but It didn't work to me. > > > Any idea? > > Thanks in advance, > > Marta > > #script# it's also attached in a R.file: question loop2.R > ## > # > #raster# it's attached > azoTS1<- raster("C:/Users/Documents/azoTS1.tif")#wgs84 > # > #10 points# it's attached > boat <- read.table("C:/Users/Documents/10pontos.csv", header=TRUE, > sep=",", na.strings="NA", dec=".", strip.white=TRUE)# > head(boat) > > #raster to transitionlayer > trCostS4<- transition(1/azoTS1, mean, directions=4) > > # points to spatialpointsdataframe > x=boat$Long1 > y=boat$Lat1 > coords = cbind(x, y) > plot(coords) > sp = SpatialPoints(coords, proj4string=CRS("+proj=longlat +ellps=WGS84 > +datum=WGS84"), bbox = NULL) > sp > spdf=SpatialPointsDataFrame(sp,boat) > spdf > nrow(spdf) > plot(sp,axes=TRUE) > plot(spdf,add=TRUE, axes=TRUE) > > #shortestpath > > ## 1) this script only join the first point of the list and the last one, > and the points in the middle are not used. > CostpathSPdf <- shortestPath(trCostS4, spdf[1,], spdf[10,], > output="SpatialLines") > plot(CostpathSPdf,add=TRUE,axes=TRUE,col=2)#R_plot1.png (it's attached) > > ## 2) this script didn't work to me > > #first way from website: > http://stackoverflow.com/questions/8127066/loop-or-sapply-function-for-multiple-least-cost-analysis-in-r?answertab=active#tab-top > for(i in 1:nrow(spdf)) { > # Computation > Costpath <- shortestPath(trCostS4, spdf[i,], spdf[10,], > output="SpatialLines") > plot(Costpath) > > } > > #Error in validObject(.Object) : > #invalid class “SpatialLines” object: bbox should never contain infinite > values > ___ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[R-sig-Geo] Difference in coordinates to country conversion
I have a set of coordinates at 1° x 1° which look like this: structure(list(longitude = c(-179L, -178L, -177L, -177L, -177L, -176L), latitude = c(-15L, -15L, -14L, 51L, 52L, -22L)), .Names = c("longitude", "latitude"), row.names = c("1", "2", "3", "4", "5", "6"), class = "data.frame") I am trying to obtain country names for them and tried the following two methods. There are some difference (mostly between USA and Canada). While sometimes method 1 provides a country name but method 2 cannot. Is there a way to say if either of the methods are more accurate? Or another more accurate method? Or am I doing something wrong? Thanks! Sincerely, Shouro library(raster) library(tmap) library(rworldmap) library(countrycode) # Method 1 { countriesSP <- getMap(resolution='low') #countriesSP <- getMap(resolution='high') #you could use high res map from rworldxtra if you were concerned about detail # convert our list of points to a SpatialPoints object # pointsSP = SpatialPoints(points, proj4string=CRS(" +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")) #setting CRS directly to that from rworldmap pointsSP = SpatialPoints(coord_dams, proj4string=CRS(proj4string(countriesSP))) # use 'over' to get indices of the Polygons object containing each point indices = over(pointsSP, countriesSP) # return the ADMIN names of each country indices$ADMIN #indices$ISO3 # returns the ISO3 code #indices$continent # returns the continent (6 continent model) #indices$REGION # returns the continent (7 continent model) } # Method 2 pts_dams <- SpatialPoints(coord_dams,proj4string=CRS(proj4string(worldmap))) indices_dams <- over(pts_dams, worldmap,na.rm=TRUE) indices <- cbind(indices_dams, coord_dams) #Keep only ISO3, log, lat foo_dams<-indices[,c(3,12,13)] [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo