I've excavated some old code for generating line shapefiles and it no longer works (not atypical). 

I can't seem to get any traction searching to web on constructing an object that can pass through maptools::write.linelistShape()

The code went something like this:

stands <- deldir( pts, rw=c(0,x.dim,0,y.dim) )

RoadShapes <- vector( "list", nrow( stands$delsgs ) )

for( i in 1:nrow( stands$delsgs ) ) {
  RoadShapes[[i]] <- rbind( stands$delsgs[i,1:2], stands$delsgs[i,3:4])
}

write.linelistShape(RoadShapes, road.att.data, file="data/roads")




I can correctly generate polygon shapefiles, but for some reason, the errors I get when trying to write a line shapefile are:

> write.linelistShape(RoadShapes, road.att.data, file="data/roads")
Error in attr(x, "pstart")[[2]] : subscript out of bounds
In addition: Warning messages:
1: use writeSpatialShape:
objects other than Spatial objects defined in the sp package are deprecated 
2: In write.linelistShape(RoadShapes, road.att.data, file = "data/roads") :
  nParts changed to integer
3: In write.linelistShape(RoadShapes, road.att.data, file = "data/roads") :
  pstart changed to integer

Can anyone point me to an example where the geometry isn't already in a shapefile?

I do (something) like this for generating polygon shapefiles:

for( i in 1:stands$n.data ) {

  Shapes[[i]]$Pstart <- 0
  Shapes[[i]]$verts <- rbind( vert.list[[i]], vert.list[[i]][1,] )
  Shapes[[i]]$shp.type <- 5
  Shapes[[i]]$nVerts <- nrow( Shapes[[i]]$verts )
  Shapes[[i]]$nParts <- 1
  bb <- bbox( vert.list[[i]] )
  Shapes[[i]]$bbox <- c(bb[1,1],bb[2,1],bb[1,2],bb[2,2] )
  Shapes[[i]]$shpID <- i

  attr( Shapes[[i]], "nVerts" ) <- Shapes[[i]]$nVerts
  attr( Shapes[[i]], "nParts" ) <- Shapes[[i]]$nParts
  attr( Shapes[[i]], "shp.type" ) <- Shapes[[i]]$shp.type
  attr( Shapes[[i]], "bbox" ) <- Shapes[[i]]$bbox

}


Thanks,
Jeff.



Jeff Hamann, PhD
PO Box 1421
Corvallis, Oregon 97339-1421
541-754-2457
jeff.hamann[at]forestinformatics[dot]com
http://www.forestinformatics.com


	[[alternative HTML version deleted]]

