gge-ucd / wRangling_Seminar

The home directory for all live scripts, lecture material, data, etc that we'll use in the ECL290 seminar NOT easily found at the website.
0 stars 2 forks source link

writeOGR error #3

Closed tombatter closed 7 years ago

tombatter commented 7 years ago

Hey @ryanpeek I am trying to repeat what we did today with my elk data... I am getting the following error when i try to execute the writeOGR command:

writeOGR(LPBBull.Sp, dsn = "data/LPBBull.shp", layer = "LPBBull_points", driver="ESRI Shapefile") # i am getting an error saying inherits (obj, "spatial") : object 'LPBBull.Sp Error in writeOGR(LPBBull.Sp, dsn = "data/LPBBull.shp", layer = "LPBBull_points", : STRING_ELT() can only be applied to a 'character vector', not a 'list' In addition: Warning message: In writeOGR(LPBBull.Sp, dsn = "data/LPBBull.shp", layer = "LPBBull_points", : Field names abbreviated for ESRI Shapefile driver

can you have a look at my code in LPBBull_test ? thanks!

ryanpeek commented 7 years ago

The answer is to avoid using the readr::read_csv function to read in your csv. I added an explanation in the code and in the Discussion repo, and updated my Rmd from today...check it out. This code worked for me, give it a shot:

LPBBull <- read.csv("https://raw.githubusercontent.com/gge-ucd/wRangling_Seminar/master/data/GIS/LPB_762B_20170302.csv") head(LPBBull) LPBBull%>% filter(is.na(Latitude)) %>% tally #how many NA in lat LPBBull%>% filter(is.na(Longitude)) %>% tally #how many NA in long LPBBull%>% filter(is.na(Altitude)) %>% tally

LPBBull <- LPBBull %>% filter(!is.na(Latitude)) # filter out NA's

LPBBull.Sp <- SpatialPointsDataFrame(coords = LPBBull[, c("Longitude","Latitude")], data = LPBBull) # coords need to be x, y

lats <-CRS("+init=epsg:4326") proj4string(LPBBull.Sp) <- lats # assign the CRS raster::crs(LPBBull.Sp) # check CRS

writeOGR(LPBBull.Sp, dsn = "data/LPBBull", layer = "LPBBull_points", driver="ESRI Shapefile")

tombatter commented 7 years ago

awesome, that worked! thank you!