2

I'm cleaning an sf file using package sf. When I write out the file using write_sf, all of the geometry is there. But when I read it back in using readOGR, it reports: "Dropping null geometries" and drops 430 lines. I need to read it back in with OGR because I'm then binding it to another object. The way I'm subsetting is kind of wonky - is that what's causing it to drop geometries? Any help is appreciated!

'fsvtrt <- read_sf("C:/Users/A02305035/Desktop/JamelaResearch/Data/GIS/FS/fsvtrt.shp") #raster package'

Add ObjectID

fsvtrt$OBJECTID <- seq(1:5464)  

Remove incomplete treatments

fsunwanted1 <- fsvtrt$DATE_COMPL[is.na(fsvtrt$DATE_COMPL)]
incomplete <- fsvtrt[fsvtrt$DATE_COMPL %in% fsunwanted1,]

salvagetx <- incomplete[na.omit(incomplete$STAGE_VALU),]

unique(incomplete$STAGE_VALU)

Find and remove planned future treatments

planned <- fsvtrt$DATE_PLANN[fsvtrt$DATE_PLANN>as.Date("2020-02-13")]

Identify planned future treatments

fsvtrt <- fsvtrt[!fsvtrt$DATE_PLANN %in% planned,]

Show treatments that have occurred, excluding planned ones

Remove incomplete treatments

incomplete <- fsvtrt$DATE_COMPL[is.na(fsvtrt$DATE_COMPL)]
fsvtrt <- fsvtrt[!fsvtrt$DATE_COMPL %in% incomplete,]

Remove wildfires

wildfires <- fsvtrt$ACTIVITY[fsvtrt$ACTIVITY == "Wildfire - Natural Ignition"]
fsvtrt <- fsvtrt[!fsvtrt$ACTIVITY %in% wildfires,]

wildfires1 <- fsvtrt$ACTIVITY[fsvtrt$ACTIVITY == "Wildland Fire Use"]
fsvtrt<-fsvtrt[!fsvtrt$ACTIVITY %in% wildfires1,]

wildfires2 <- "Wildfire - Fuels Benefit"
fsvtrt <- fsvtrt[!fsvtrt$ACTIVITY %in% wildfires2, ]

wildfires3 <- "Wildfire - Human Ignition"
fsvtrt <- fsvtrt[!fsvtrt$ACTIVITY %in% wildfires3, ]
2
  • Could you bind the other object in sf using rbind? r-spatial.github.io/sf/reference/bind.html Feb 14, 2020 at 0:19
  • you can try either reading it with sf::st_read(), or if you want to stick with readOGR you can try setting the dropNULLGeometries argument to FALSE (BTW: looking at your code, you may have NULL geometries already in the input. Did you check that?)
    – lbusett
    Feb 23, 2020 at 21:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.