Skip to content

writing polygons/segments to shapefiles (.shp) or other ArCGIS compatible file

5 messages · Stéphane Dray, Patrick Giraudoux, Barry Rowlingson

#
I am not sure a previous e-mail reached the list (no mail aknowledgement from R-boundle etc.). The question was how to write polygon
or segment coordinates into a shapefile set or any other ArcGIS supported format. The library shapefiles seems to do something but
the documentation is a bit beyond of my mind.... and I cannot get the meaning of the functions write**** and its application to the
case below:

In simple words, is there a somewhere a function taking polygon coordinates (or simple segments) within R to a "ready to read" set
of files ***.shp, ***.shx, etc...

Thanks in advance for any hint

Patrick



----- Original Message ----- 
From: "Patrick Giraudoux" <patrick.giraudoux at univ-fcomte.fr>
To: "r-help" <r-help at stat.math.ethz.ch>
Sent: Wednesday, February 25, 2004 1:08 PM
Subject: writing polygons/segments to shapefiles (.shp)
#
I think It could not be done for the moment .. Perhaps, I am wrong !

In the package maptools, there is  read.shape shape2poly, shape2line... 
These functions allow to read shapefiles files but not to write it.
With the shapefiles package you can write shape object to files. I think 
that one solution is to write poly2shape, lines2shape,....or perhaps a more 
general write.Maps (to save Maps in GIS file format).
Another and provisory solution exist. I have write an arcview 3.x extension 
(AVADE) to allow the interface between Arc-View and ADE-4 software. You can 
download the extension at www.steph280.freesurf.fr. If you have a poly object,
you can convert it to an area object (poly2area in the ade4 library)
save the area object within a file with write.table
and convert this text file to a shapefile with the AVADE extension in Arcview.

Hope this helps,
At 10:32 25/02/2004, Patrick Giraudoux wrote:
St?phane DRAY
-------------------------------------------------------------------------------------------------- 

D?partement des Sciences Biologiques
Universit? de Montr?al, C.P. 6128, succursale centre-ville
Montr?al, Qu?bec H3C 3J7, Canada

Tel : 514 343 6111 poste 1233
E-mail : stephane.dray at umontreal.ca
-------------------------------------------------------------------------------------------------- 

Web                                          http://www.steph280.freesurf.fr/
#
There is a little problem with the approach I described in my previous email.
In ADE-4, coordinates are given in pixel and so Y are inverted. You must 
invert your Y coordinates to obtain the good representation in ArcView. An 
example:

 > library(ade4)
 > library(shapefiles)
 > library(maptools)
 > try1 <- read.shapefile(paste(ShapeDir, "columbus", sep="/"))
 > shppolys <- shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
 > obj=poly2area(shppolys)
 > obj[,3]=-obj[,3]
 > write.table(obj,"try.area",col.names=F,quote=F,row.names=F)
 >

Then, use the 'From AREA' function in AVADE.
At 10:32 25/02/2004, Patrick Giraudoux wrote:
St?phane DRAY
-------------------------------------------------------------------------------------------------- 

D?partement des Sciences Biologiques
Universit? de Montr?al, C.P. 6128, succursale centre-ville
Montr?al, Qu?bec H3C 3J7, Canada

Tel : 514 343 6111 poste 1233
E-mail : stephane.dray at umontreal.ca
-------------------------------------------------------------------------------------------------- 

Web                                          http://www.steph280.freesurf.fr/
#
Thanks a lot for the hints. I will try.  Actually I was focusing (in a first stage) on simple segments (small mammal traplines...).
I turned the problem out writing some lines to export the coordinates into a "simple" GRASS ascii file, imported it into GRASS as
vector file and then used the export tool to get  shapefiles...  Not that direct: needs to have GRASS installed and an elementary
knowledge on the export/import commands in this open source GIS.

It would be fantastic to have the reverse functions of Map2poly(Map), Map2lines(Map), Map2points(Map) read.shape (eg poly2map,
lines2map, points2map, and write.map) to write shapefiles.... I must however admit that I don't know enough about shapefile formats
and R programming to do this by myself... and I would unfortunately be really out of my current job in the university...


----- Original Message ----- 
From: "Stephane DRAY" <dray at biomserv.univ-lyon1.fr>
To: "Patrick Giraudoux" <patrick.giraudoux at univ-fcomte.fr>; "r-help" <r-help at stat.math.ethz.ch>
Sent: Wednesday, February 25, 2004 5:35 PM
Subject: Re: [R] writing polygons/segments to shapefiles (.shp) or other ArCGIS compatible file
#
Patrick Giraudoux wrote:
The  shapelib library comes with command-line utilities for creating 
shapefiles, so at a stretch you could use those:

  % shpcreate fnord polygon             # creates new shapefile
  % shpadd fnord  0 0  1 0  1 1  0 1    # adds a unit square polygon

  % shpdump fnord
Shapefile Type: Polygon   # of Shapes: 1

File Bounds: (       0.000,       0.000,0,0)
          to  (       1.000,       1.000,0,0)

Shape:0 (Polygon)  nVertices=4, nParts=1
   Bounds:(       0.000,       0.000, 0, 0)
       to (       1.000,       1.000, 0, 0)
      (       0.000,       0.000, 0, 0) Ring
      (       1.000,       0.000, 0, 0)
      (       1.000,       1.000, 0, 0)
      (       0.000,       1.000, 0, 0)

  So you could quite easily create shapefiles from some text format with 
a bit of R that calls 'system' (on Unix at least). You wouldn't have to 
deal with C and the shapelib directly. This might be a bit slow though. 
You can also create the dbf library on the command line.

  Shapefile creation is on my list of things that would be nice for my 
Rmap library...

Baz