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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Benjamin.STABLER@odot.state.or.us
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



Reply | Threaded
Open this post in threaded view
|

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

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

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



Reply | Threaded
Open this post in threaded view
|

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

Paul Murrell
Hi


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
packages).

Paul


> 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
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



Reply | Threaded
Open this post in threaded view
|

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

Nicholas Lewin-Koh
In reply to this post by Benjamin.STABLER@odot.state.or.us
Hi again,
I took a look at maptools code and shapelib last night. It should not be
hard to modify to create and write
shapefiles. I think I never developed it in maptools because I never
really thought of R as
being suitable for editing maps. I thought R would be very suitable for
designing cartographic dispays for
statistical purposes.

That said, If I can get it working in an evening or two I will submit it
to Roger for inclusion in maptools.
Do any of the other geo interfaces in development write map formats? Eg
the Rgdal interface?

Nicholas



Reply | Threaded
Open this post in threaded view
|

Re: [R] writing polygons/segments to shapefiles(.sh p)o r other A rcGIS compatible file

Roger Bivand
Administrator
On Mon, 1 Mar 2004, Nicholas Lewin-Koh wrote:

> Hi again,
> I took a look at maptools code and shapelib last night. It should not be
> hard to modify to create and write
> shapefiles. I think I never developed it in maptools because I never
> really thought of R as
> being suitable for editing maps. I thought R would be very suitable for
> designing cartographic dispays for
> statistical purposes.

I think you are correct in principle, but I can see situations where
people want to export subsets of say polygons, lines, or points.

>
> That said, If I can get it working in an evening or two I will submit it
> to Roger for inclusion in maptools.

That's very generous - if you can make a first attempt at making your code
work, that will give us a start. The places where my head ached were
whether we need to check shapes for compliance before writing them to file
- but maybe shapelib does that - I don't think so? Should we just let
people write anyway?


> Do any of the other geo interfaces in development write map formats? Eg
> the Rgdal interface?
>

It should but doesn't - you can (I think) overwrite bands, but this is
something that needs fixing - for those interested, rgdal is on
sourceforge, so checking out under cvs is possible, so that improvements
and additions can be brought in under control.

Roger

> Nicholas
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no



Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

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

Nicholas Lewin-Koh
Hi Roger,
Just working on it now. Just created an empty shapefile from R
complete with segmentation fault :)
debugging it now.

I think the code in shapelib, shprewind, is an example of using
the shapelib api to do shape checking. I will follow this up further.
meanwhile i will work on getting something started.

Nicholas



On Tue, 2 Mar 2004 15:42:39 +0100 (CET), "Roger Bivand"
<Roger.Bivand at nhh.no> said:

> On Mon, 1 Mar 2004, Nicholas Lewin-Koh wrote:
>
> > Hi again,
> > I took a look at maptools code and shapelib last night. It should not be
> > hard to modify to create and write
> > shapefiles. I think I never developed it in maptools because I never
> > really thought of R as
> > being suitable for editing maps. I thought R would be very suitable for
> > designing cartographic dispays for
> > statistical purposes.
>
> I think you are correct in principle, but I can see situations where
> people want to export subsets of say polygons, lines, or points.
>
> >
> > That said, If I can get it working in an evening or two I will submit it
> > to Roger for inclusion in maptools.
>
> That's very generous - if you can make a first attempt at making your
> code
> work, that will give us a start. The places where my head ached were
> whether we need to check shapes for compliance before writing them to
> file
> - but maybe shapelib does that - I don't think so? Should we just let
> people write anyway?
>
>
> > Do any of the other geo interfaces in development write map formats? Eg
> > the Rgdal interface?
> >
>
> It should but doesn't - you can (I think) overwrite bands, but this is
> something that needs fixing - for those interested, rgdal is on
> sourceforge, so checking out under cvs is possible, so that improvements
> and additions can be brought in under control.
>
> Roger
>
> > Nicholas
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at stat.math.ethz.ch
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
> e-mail: Roger.Bivand at nhh.no
>
>