Skip to content

Writing ArcGIS Shapefiles from R; advice?

4 messages · Gavin Simpson, Barry Rowlingson, Michael Sumner

#
Dear List,

Firstly, a confession: I'm not a GIS expert and I have next to no
experience of using ArcGIS or shapefiles. Apologies if anything I write
below is stupid!

I have an ESRI ASCII grid file that I have read into R and successfully
(with the help of this list) processed it into a
SpatialPolygonsDataFrame object (via SpatialPixelsDataFrame). I have
unionised the polygons to a set of depth intervals, so all the
individual polygons associated with depths (say) between 1 and 2 m are
given the same ID; there are several depth intervals, therefore several
IDs. This is fine, and I'm happy with this, but I need to export this
object to ESRI Shapefile(s).

I have exported the whole SpatialPolygonsDataFrame object to a single
shapefile but when my colleagues open this in ArcGIS, there is a single
layer for all depth levels and they'd like to be able to have a layer
per polygon ID. Is this possible, to write out the
SpatialPolygonsDataFrame object such that ArcGIS knows that each polygon
ID is a separate layer?

I have worked out how to break apart the SpatialPolygonsDataFrame object
into the equivalent but with a single ID (depth interval), and have
written those out into separate shapefiles, one per depth interval,
which when loaded into ArcGIS are represented by separate layers, but
dealing with more than a few shapefiles at once is proving
"difficult" (!??!) for some, hence if it were possible to produce a
single shapefile with separate "layers" that might solve that particular
issue.

Second Q is; is there a way to include information about how ArcGIS
displays each layer/shapefile? For example, we'd like to give each
layer/shapefile a particular fill colour, so that when loaded by a user
into ArcGIS, the particular depth polygons have a nice gradient
representing depth. Is this even remotely possible from within R, or is
this something ArcGIS does and is separate from the shapefile per se?

Currently I am using writeOGR to read out these objects to ESRI
shapefiles.

The reason I ask these questions is because we have a lot of these lake
bathymetries and dealing with them in ArcGIS (to get separate layers and
colour those layers accordingly) by hand is a non starter and we don't
want to start writing VB scripts in Arc at this stage.

Thanks in advance for any pointers or suggestions you may have. And
apologies again for showing my ignorance as regards shapefiles.

All the best,

Gavin
#
Shapefiles don't have separate layers, and one layer can only have one
geometry type (point, line, or polygon). GDAL can treat a single
folder with multiple shapefiles as if each shapefile were a separate
layer in a single dataset, but that is just GDAL functionality,
reflecting the OGR model, and is supported by other vector formats.

I'm not very familiar with Arc? products, so I'm not 100% on this, but
I think you would need to write each separate set of polygons, each
with an individual depth value, to a separate shapefile and proceed
from there. I don't know anything about how to get Arc to understand
configurations of shapefiles, but perhaps you could use one of the
other ESRI formats such as E00 (guessing here, I'll have a closer look
at the OGR formats - see rgdal's ogrDrivers() for the ones available
on your system).

If your SpatialPolygonsDataFrame really has multiple duplicate (in
X/Y) polygons with the separate depths, you can subset it for
individual depths with "[" and write those out individually:

e.g.

depth0 <- splydf[splydf$depth == 0, ]

HTH

Cheers, Mike
On Wed, Sep 8, 2010 at 8:07 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:

  
    
#
On Tue, Sep 7, 2010 at 11:07 PM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:

            
There are some open standards for styling geospatial data, namely SLD
and OpenGIS Symbology Encoding. They are XML files that define how map
layers appear.

 If ArcGIS supports these then you just have to work out how to write
the XML for the data. That probably means understanding the OGC Specs:

http://www.opengeospatial.org/standards/sld
http://www.opengeospatial.org/standards/symbol

 or you might find some desktop GIS that can save them - possibly Qgis or gvSIG.

I have a vague memory of once reverse-engineering an ArcGIS file that
encoded the style of a map, but it was all binary and a mess and I'd
need a few examples to work it out.

 A bit more googling shows there is an SLD plugin for Qgis and ArcGIS
can export them. So that might work...

Barry
#
I can't see any easy way through this, since the other ESRI formats
that do support separate layers are not writeable by OGR:

(from the OGR formats page: http://www.gdal.org/ogr/ogr_formats.html)
Arc/Info Binary Coverage  AVCBin
 Arc/Info .E00 (ASCII) Coverage  AVCE00
 ESRI Personal GeoDatabase  PGeo
 ESRI ArcSDE  SDE

I would see if any of the other OGR formats can work for your
colleagues, but it doesn't look hopeful.

Shapefiles do not support formatting (colours, line styles etc) at
all. There is an auxiliary format file that can accompany shapefiles,
but AFAIK this is only understood by ESRI and is not part of the
shapefile definition (much as PRJ/WKT is not either).

Again, some of the other OGR formats may work for you.  A (desperate?)
non-open source, Windows-only solution might be to use Manifold
Enterprise to write .E00 - I'd be happy to try this out with example
data, at least to see what might be possible.

Cheers, Mike.
On Wed, Sep 8, 2010 at 8:19 AM, Michael Sumner <mdsumner at gmail.com> wrote: