[R] writing polygons/segments to shapefiles (.shp) or other A rcGIS compatible file

Benjamin.STABLER@odot.state.or.us Benjamin.STABLER at odot.state.or.us
Thu Feb 26 19:11:40 CET 2004

The main limitation of the shapefiles package that I put together is that it
does not create shapefiles from R objects - rather it only writes shapefiles
that have been read into R and manipulated within the constraints of the
existing file structure.  By this I mean that for example you can change the
coordinates of points and write them back out.  Or you can add a bunch of
blank columns in the DBF outside of R and then fill them in with R.  But I
did not write any code to calculate byte offsets and such and that are
needed when creating a shapefile from scratch.  

So what I do when I want to create a new shapefile from within R is write
out the format required by the ASCII Tool ArcView (Avenue) script.  This
script is available at: http://arcscripts.esri.com/details.asp?dbid=11442
The format is simple: 

Works for space delimited ascii to point, polygon and polyline. The format
for point ascii file is id, x, y (no comma for real data, space delimited).
For polygon & polyline ascii files, the format is code (1 for start point, 2
for middle points, 3 for end point), x, y (no comma for real data, space
delimited). Export shapefile to ascii file works for point, polyline and
polygon shapefiles. The output format file is id, x, y. For polygon and
polyline, the id is the sequence id of vertices.

Thus all you have to do is write a text file, install the script in ArcView
and then use the ArcView extension to create a shapefile from the ASCII
file.  Unfortunately ASCII tool only works with the geography - you have to
add the attributes later.  

With all of that said, I would like to add to the shapefiles package the
ability to write out shapefiles from scratch.  Since the shapefiles format
is rather unique, I think it would be best to use the maptools ShapeList/Map
class format (or r-spatial's classes).  For starters the package would just
write out the geography (like the ASCII tool Avenue script).  Later would be
added the ability to write the dbf data out from the att.data element of the
Map object.

Unfortunately I don't know when I will have the time to do this.  If anyone
else wants to do then please go ahead and I can help via email if needed.
But adding the ability to write out shapefiles from scratch is on my list.
Once I finish coding our travel demand model and we enter the application
phase (probably in a few months) then will our demand to output shapefiles
from R increase and I can justify spending the time to write the code.  

I apologize that I have not paid much attention to the r-sig-geo discussion
or Edzer's r-spatial project.  If there is an effort underway to write out
shapefiles then can someone please inform me of its status.  If not, then
maybe I can help.  Thanks.

Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301  Ph: 503-986-4104

More information about the R-help mailing list