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

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Thu Feb 26 13:43:53 CET 2004


Patrick Giraudoux wrote:
> 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...
> 

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




More information about the R-help mailing list