Skip to content

rgdal writeOGR - clipping variable names

3 messages · Barry Rowlingson, James Rooney, Lee Hachadoorian

#
"Ten characters in field names should be enough for everyone" - Jack
Dangermond (ESRI founder and billionaire)

Okay, he didn't really say that (just as Bill Gates didn't say
something similar about 640K of RAM) but at some point someone decided
it was enough for DBF files.

So, you might want to think about not using shapefiles...

Alternatives include GML (which most modern GISs will read and write
but can be verbose and I've heard people swearing at it almost as much
as shapefiles) or SpatiaLite databases...

If your rgdal package has SQLite drivers then you can use SpatiaLite
databases now. eg:

writeOGR(scot, "scotland.sqlite","scot",driver = "SQLite",
dataset_options=c("SPATIALITE=yes"))

[note some options may have changed, I'm using a slightly old system here]

this creates a *single* file (win #1 over shapefiles) called
scotland.sqlite with a map layer in it, and preserves long field names
(win #2 over shapefiles). The SQLite database is an open standard
(that's a tie with shapefiles) but is being actively developed into a
wider geodatabase package standard (win #3 over shapefiles).

you can also store non-spatial data in it, since its a SQLite database
file (win #4 over shapefiles) and so send someone a whole bunch of
spatial and non-spatial data in a single file (win #5).

Spatialite DBs can be read in to QGIS and I think they can be read
into the leading proprietary GIS package (call that a tie too).

At the moment with rgdal I can't figure out how to add several layers
to a single Spatialite file or overwrite a single existing layer but I
suspect I'm just missing an option or two. I can just delete the
.sqlite file and recreate it, but that's an annoyance... Oh well,
there has to be one doesn't there?

Barry
On Mon, Jul 7, 2014 at 8:16 AM, James Rooney <ROONEYJ4 at tcd.ie> wrote:
#
Haha thanks very much for the comparison.

Hmm it is something I shall have to think about. There was some reason I decided to use shapefiles that escapes my memory. Apart from that at I'm kind of invested now - if I change it could be a nightmare to trace through the workflow.
However - I take your thoughts on board and will think about it if a natural breakpoint in the work to make such a change presents itself!

Thanks again,

James
#
On Mon, Jul 7, 2014 at 4:44 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:

            
Interesting. This can be done at the terminal with ogr2ogr, but
requires the -update switch. ogr2ogr requires the -update switch to
add a layer to a SpatiaLite file, but not to PostGIS. Hence, writeOGR
can add layers to PostGIS but not to SpatiaLite.

I don't think there's any way to pass the -update switch via writeOGR,
as it is not a dataset creation option or layer creation option.

Best,
--Lee