1

Originally I had a TIGER shape file downloaded from the U.S. Census website. The shape file contains all roads in Harris county, Texas. It contained 7 features, 1) the identifying number (FID), 2) its shape (polyline), 3) the linear id, 4) The street name, 5) the route type code, 6) the MAF/TIGER feature class code, and 7) the distance of each road in feet.

I imported it into R so I could assign speeds based on the feature class code and calculate the drive time on each road. I need to import this back into ArcGIS, in the form of a shape file.

writeOGR(revised.data, "harris_shape_file", layer = "harris_travel_revised", driver = "ESRI Shapefile")

However, this is throwing an error saying "inherits(ojb, "Spatial") is not TRUE". Now I don't work with shape files often and am a novice in GIS. I am looking for some quick feedback/suggestions as to what might be going on. Obviously R doesn't recognize the data frame as a 'spatial' one, but I'm not sure how to change that.

I imported the data file and converted the attributes to a frame with

roads.data <- readORG(dsn="harris_shape_file/")
roads <- roads.data@data

I made revised data as the following...

# mtfcc.codes are based off of unique mtfcc values, excluding parking lot 
# roads, government use, private roads, vehucular trails, bike paths and 
# pedestrian walkways.
mtfcc.codes <- c("S1400", "S1200", "S1100", "S1630", "S1730")

revised.data <- data.frame(matrix(nr=0, nc=6))
colnames(revised.data) <- c("LINEARID", "FULLNAME", "RTTYP", "MTFCC", "DISTANCE")

# assign speed limit based on mtfcc code
for(i in as.character(mtfcc.codes)){
  m.sub <- subset(roads, grepl(paste(i), roads[,4]))
  if(i == "S1400"){
    m.sub[,6] <- "25"
  }
  if(i == "S1200"){
    m.sub[,6] <- "45"
  }
  if(i == "S1100"){
    m.sub[,6] <- "65"
  }
  if(i == "S1630"){
    m.sub[,6] <- "25"
  }
  if(i == "S1730"){
    m.sub[,6] <- "15"
  }
  revised.data <- rbind(revised.data, m.sub)
  print(i)
}
colnames(revised.data)[6] <- "SPEED"

# calculate drive time on each route
revised.data[,5] <- as.numeric(as.character(revised.data[,5]))
revised.data[,6] <- as.numeric(revised.data[,6])

for(i in 1:nrow(revised.data)){
  revised.data[i,7] = revised.data[i,5]*(60/revised.data[i,6])
  print(i)
}

colnames(revised.data)[7] <- "TIME"
DPek
  • 180
  • 2
  • 15
  • how did you make `revised.data` ? – SymbolixAU Nov 03 '17 at 00:03
  • @SymbolixAU I added the rest of my code into my question. After I named column 7 I used writeOGR. – DPek Nov 03 '17 at 00:09
  • I think you may have overcomplicated things. See if this thread helps you - it sounds to me like you don't need to convert it to a data frame in the first place: https://stackoverflow.com/questions/17252235/manipulate-shapefile-attribute-table-using-r (aka, can you just add a column in the shapefile attribute table and then calculate what you need like you normally would in R?) – HFBrowning Nov 03 '17 at 00:13
  • You probably just need somrthing like: `new_roads <- roads.data` ; `new_roads@data <- revised.data`. Now "new_roads should be a spatial datasert with geometries from "roads.data" and data from revised.data. – lbusett Nov 05 '17 at 08:41

0 Answers0