I need to extract daily weather data points from a raster stack and place it over a shapefile of various sewer sheds in my state. My boss wants me to use the writeRaster and extract function to do this. He said this would create a GeoTiff. I am new to R and unsure how to do something like this. Anything that can point me in the right direction would be appreciated.
Related
Apologies if this belongs in GIS stackexchange, I'm happy to be redirected there, but I have a feeling it's something in my code that is the problem.
I have a shapefile of the Terrestrial Ecoregions of the World that contains fields such as Ecoregion Name, Biome, and, Realm, that I want to extract for a range of ~50,000 lat/long points. An example of the data would be
ID
ddlat
ddlong
221784
6.133
37.700
221814
26.450
74.700
221826
-17.716
-63.633
221827
47.933
8.083
221830
-24.283
131.600
My code (sample from within a much larger script) currently looks like the following:
teow <- shapefile("~/wwf_terr_ecos.shp")
teowlltest <- read.csv(file="~/teow_csv.csv",stringsAsFactors=FALSE)
teowlltest <- na.omit(teowlltest)
teowlltestSPT <- SpatialPoints(teowlltest, proj4string = CRS(proj4string(teow)))
overteow <- over(teowlltestSPT, teow)
bindtest <- cbind(teowlltest,overteow)
My problem is that the code works ... but only for 15 of the latlong points. I'm not expecting a 100% success rate, as I know the shapefile isn't perfect in coastline areas etc, but when mapped, far more than 15 points lie within the TEOW shapefile. The 15 that are being extracted are also incorrect when compared to maps of the biomes/realms etc. How do I get it to extract the field data for all the points and do it correctly? I've tried renaming/reorganising the csv (for example Y,X or Latitude, Longitude instead of ddlat, ddlong, and placing longitude as the first field), and subsetting the data, but only the same 15 keep extracting. I can't separate the Lat/Long information from the ID either, so I'm hoping that's not the problem here, but I can't see why it would be, if some of the points extract fine. Any help will be much appreciated, and I'm happy to answer any questions/supply more information if needed. Thanks!
Example output currently:
Showing that some have extracted (but not correctly) and all the others have just refused. Duplicate lat/longs removed for brevity.
How to store polygons created by addDrawToolbar in variables as sf data
By using addDrawToolbar, I was able to draw polygons on the map. Is it possible to store this polygon in a variable as sf format?
In the subsequent processing, I intend to combine (st_union) with the existing polygon (Administrative district data).
Therefore, I am looking for a way to save it as sf format data.
If you know or have a web page that you can refer to, please let me know.
I have a csv file containing latitude, longitude and temperature for san joaquin valley. I want to plot the latitude and longitude on the y and x axes respectively.I want to use the google base map. The temperature at a particular latitude and longitude should be plotted as a surface map like shown in the image below.
Please guide me to achieve the output as shown in the picture.
http://i.stack.imgur.com/r8loG.png
Thank you so much.
You can very easily use ggvis to make the type of map that you want. You will need more than just lat and lon to make it happen if you are looking ot have some kind of color transition based on a prevalence of some kind. It may be in another column and tied to your labeling method.
Here is a solid site to help you get started.
ggvis mapping
Work through the examples to figure out what is happening beneath the code before you dive right into your own unless you are very familiar with R and the ggvis environment.
Without a starting code base, no one is going to be able to help you more than this...get started and then ask more specific questions.
I would like to know how to plot latitude and longitude readings in R.
Drive Route:
I want something like the above image. The route is for a street in Nigeria and the lat/long readings were obtained from a GPS. The plot was done with MapInfo but I would appreciate if someone can show me how it is done in R. I am still a newbie in R.
I agree with Andy on doing some more research before asking questions, but to get you started I would suggest you have a look at the ggplot2 and ggmap package combination. Which can be used to set up maps and plot gps locations on these maps.
I mainly use it to plot sample locations, but I guess you could also use it to plot routes/lines.
I have a SpatialPolygonsDataFrame with 120 Polygons and some associated data. Now I’d like to extract the mean of the values on a raster within each polygon separately. I succeded in plotting individual polygons with:
plot(SpatialPolygons(SPdataframe#polygons)[i])
But it did not work to extract the values in the same manner:
extract(raster, SpatialPolygons(SPdataframe#polygons)[i],fun="mean",na.rm=TRUE,method="simple")
Can anyone explain the difference between the use of the same indexation in this two cases? What is the official way to choose particular polygons of a SpatialPolygonsDataFrame with indices?
Thank you a lot for your help in advance!
The correct indexation for single polygons of a SpatialPolygonsDataFrame is: SPdataframe[i,]
(Merci to R-sig_geos user Rafael Wüest)