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

Paul Murrell p.murrell at auckland.ac.nz
Sat Feb 28 22:28:16 CET 2004


Patrick Giraudoux wrote:
> Hi,
> Thanks for all those information and the most valuable library you have developed.
> If somebody is to develop something to write shapefiles from polygon coordinates within R (most welcome), I don't think that the
> attribute file (dbf) will be an important issue. If we have got an output with the index to link the dbf records to each shape of a
> shapefile, any text file can be handled in R or Excel to create a dbf. The real issue is the encoding of the *.shp and *.shx  etc..
> (and an index file for the dbf)
> Most important is to consider that ESRI has stopped developping ArcView and AVENUE. They have moved to ArGIS and Visual Basic. In
> this new generation framework, importation is managed with ArcToolBox which, to my knowledge, is very limited considering
> importation of text objects (actually I even wonder if one can import something but attribute tables without ArcInfo). For instance,
> the way I found to solve the problem I met was to write a programme in R to wrap the polygon coordinates in a text file readable in
> GRASS (an opensource GIS), to import it into GRASS and to export the shapefile from GRASS. This shapefile was finally imported to
> ArcGIS.  I would not insist on ESRI client policy. I just want to say that the more I know corporates the more I love opensource...
> Anyway, there are many things that can be made in R which may deserve not only importation to R, but also exportation to many kinds
> of GIS. To write shapefiles from polygon, points or lines created in R would be most useful.

I don't know anything about shapefiles, but that's starting to sound 
like a "shapefile" graphics device (c.f. the gtkDevice, RSvgDevice 


> Many thanks for your interest and support,
> Patrick Giraudoux
> Université de Franche-Comté
> Laboratoire de Biologie environnementale
> EA3184 usc INRA
> F-25030 Besançon Cedex
> tél.: +33 381 665 745
> fax.: +33 381 665 797
> http://lbe.univ-fcomte.fr
> "Ce n'est pas en améliorant la bougie que l'on a inventé l'électricité", la recherche fondamentale est indispensable !
> ----- Original Message ----- 
> From: <Benjamin.STABLER at odot.state.or.us>
> To: <patrick.giraudoux at univ-fcomte.fr>
> Cc: <r-help at stat.math.ethz.ch>; <r-sig-geo at stat.math.ethz.ch>
> Sent: Thursday, February 26, 2004 7:11 PM
> Subject: Re: [R] writing polygons/segments to shapefiles (.shp) or other ArcGIS compatible file
>>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
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz

More information about the R-help mailing list