Vincenzo,

The coordinates in your sp data.frame 'coords' appear to be just off the
coast when I enter them into GoogleEarth as (41.3, -71.35) etc.  It's
consistent with what I see when I run your script, then use

zoom(hosp) #click twice to create a box around RI
plot(coords_trans, add = TRUE)



Perhaps recheck the coordinates?


On Thu, Oct 17, 2013 at 3:12 PM, Vincenzo Ellis <vincenzoaellis@gmail.com>wrote:

> Dear R users,
>
> I'm pretty new to GIS techniques and have a question about matching up
> points to a raster in order to extract raster values to the points. I'm
> using a shapefile from the Breeding Bird Survey of bird abundances, and
> points that I have from Rhode Island seem to always fall outside the
> shapefile once I rasterize it. I've included an example below to illustrate
> the problem. The example uses the house sparrow which is everywhere on land
> and Rhode Island still falls off the map. I double checked the Rhode Island
> coordinates on Google Earth and they are definitely on land, so I'm
> guessing that I'm making some kind of transformation error in the
> projection or coordinate systems. But it seems to be off only by a little.
>
> Thanks for any help/insights!
>
> Vincenzo
>
> # download the shapefile here-->
> http://www.mbr-pwrc.usgs.gov/bbs/ra10/ra06882.zip
> library(rgdal)
> library(raster)
>
> # read in the shapefile and rasterize it based on the variable "STAT1"
> housesparrow <- readOGR("your working directory/house_sparrow", "ra06882")
> r <- raster()
> extent(r) <- extent(housesparrow)
> hosp <- rasterize(housesparrow, r, 'STAT1')
>
> # get coordinates
> sites <- c("SC_1", "SC_2", "SC_3", "NC_1", "MN_1", "MN_2", "RI_1", "RI_2",
> "RI_3", "RI_4") # RI is Rhode Island
> lat <- as.numeric(c(33.19, 33.07, 33.22,35.53, 44.06, 47.1, 41.3, 41.27,
> 41.36, 41.44))
> long <- as.numeric(c(-81.38, -81.39, -81.34, -79, -91.44, -95.1, -71.35,
> -71.29, -71.46, -71.43))
> coords <- data.frame(sites, lat, long)
> coordinates(coords)= ~ long+ lat
> projection(coords) <- CRS("+proj=longlat +ellps=WGS84")
> coords_trans <- spTransform(coords, CRS(projection(hosp)))
>
> # plot...looks good, but...
> plot(hosp, col=rev(heat.colors(n=5)))
> points(coords_trans)
>
> # extract data to points always leaves off Rhode Island...
> hosp_values <- extract(hosp, coords_trans) # the RI sites always come out
> as "NA", maybe b/c they are off the map? transformation problem?
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
*Andrew P. Vitale*
Masters Student
Department of Geography
University of Nevada, Reno
vitale232@gmail.com

	[[alternative HTML version deleted]]

