Extract values in a Spatial Polygon dataframe - r

I'm currently trying to find out a value of a certain polygon in my Spatial Polygon dataframe. I need to know what "ID" was assigned to each "FSA" level. Below is the picture of how my data is set up. The dataset is called "FSA2015EditedFINAL2". I tried this:
FSA2015EditedFINAL2#polygons[[1]]#ID
But that just tells me the first polygons ID, and I don't know what FSA that corresponds to...
I'm hoping to be able to type in the FSA I need and pull out what ID it got.
Any help would be amazing!!!!
Thanks!

Related

Why is R only extracting a shapefile field values for certain points?

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 extract data points from rasterstack to a shapefile?

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.

Select multiple points on scatterplot, save selection to new table

I have a very large data set (~250,000 records) that I have used to create a linear model. I have plotted predicted vs. actual
.
I tried to use identify() to select the two cluster of values near the center of the graph and coord() to identify them. There are a few problems here: 1)There are many, many more points in those clusters than I can click on and identify individually, and 2)I need to know ALL of them, select all of them somehow with out selecting any others, and subset my data to just those points.
This model was created using a satellite image paired with ancillary spatial data. Each entry in the table corresponds to a particular point on the map. I need to identify where these two clusters are located on the map. My data frame includes the FID (which I can use to link back to the map), the original predictor, the response, and my predicted values.
I appreciate any help!

How can I see all argument options in R?

This seems like a stupid question, but I have not been able to find the answer by googling.
R Documentation often does not outline all possible values for particular arguments. Is there a command to print that information?
For example, I would like to draw some maps using the function map() in the maps package. The R Documentation states for the region argument:
regions: character vector that names the polygons to draw. Each
database is composed of a collection of polygons, and each polygon has
a unique name. When a region is composed of more than one polygon, the
individual polygons have the name of the region, followed by a colon
and a qualifier, as in michigan:north and michigan:south. Each element
of regions is matched against the polygon names in the database and,
according to exact, a subset is selected for drawing. The default
selects all polygons in the database.
Is it possible to get a list of the region names?
You can see the arguments and defaults with:
args(map)
I believe you are looking for elements in the database and not arguments since the map function will not know what database you are passing it. Its default is 'world'.
w <- map('world')
str(w) # not necessary, but good to look at
w$names
And further:
canada <- map(region = 'Canada')
canada$names

Extract raster values of particular polygons of a SpatialPolygonsDataFrame (indexation)

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)

Resources