Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

importShapefile

Import an ESRI Shapefile


Description

Import an ESRI shapefile (.shp) into either a PolySet or EventData.

Usage

importShapefile (fn, readDBF=TRUE, projection=NULL, zone=NULL, 
   minverts=3, placeholes=FALSE, show.progress=FALSE)

Arguments

fn

character – file name of the shapefile to import; specifying the extension is optional.

readDBF

logical – if TRUE, import the associated ".dbf" (database containing feature attributes) and add as an attribute to the output PolySet | EventData object.

projection

character – optional projection attribute to override the internally derived value.

zone

numeric – optional zone attribute to override the default value of NULL.

minverts

numeric – minimum number of vertices required for a polygon representing a hole to be retained (does not affect solids).

placeholes

logical – if TRUE then for every PID identify solids and holes, and place holes under appropriate solids.

show.progress

logical – if TRUE, display on the command console the progress of placing holes under solids.

Details

This routine imports an ESRI shapefile (.shp) into either a PolySet or EventData, depending on the type of shapefile. It supports types 1 (Point), 3 (PolyLine), and 5 (Polygon) and imports type 1 into EventData and types 3 and 5 into a PolySet. In addition to the shapefile (.shp), it requires the related index file (.shx).

If a database containing feature attributes (.dbf) exists, it also imports this database by default. For EventData, it binds the database columns to the EventData object. For a PolySet, it saves the database in a PolyData object and attaches that object to the PolySet in an attribute named “PolyData”.

If a .prj file exists, this information is attached as an attribute. If the first 3 characters are ‘GEO’, then a geographic projection is assumed and projection="LL". If the first 4 characters are ‘PROJ’, and ‘UTM’ occurs elsewhere in the string, then the Universal Transverse Mercator projection is assumed and projection="UTM". Otherwise, projection=1.

If an .xml file exists, this information is attached as an attribute.

Shapes of numeric shape type 5 exported from ArcView in geographic projection identify solids as polygons with vertices following a clockwise path and holes as polygons that follow a counter-clockwise path. Unfortuantely, either the export from ArcView or the import using a C-routine from the package maptools often does not report solids followed by their holes. We employ a new R function placeHoles to do this for us. Ideally, this routine should be rendered in C, but for now we use this function if the user sets the argument placeholes=TRUE. Depending on the size and complexity of your shapefile, the computation may take a while.

Value

For points, EventData with columns EID, X, and Y, possibly with other columns from the attribute database. For polylines and polygons, a PolySet with columns PID, SID, POS, X, Y and attribute projection. Other attributes that may or may not be attached: parent.child (boolean vector from original input), shpType (numeric shape type: 1, 3, or 5), prj (projection information from .prj file, xml (metadata from an .xml file), PolyData (data from the attribute database .dbf), and zone (UTM zone).

Author(s)

Nicholas M. Boers, Associate Professor – Computer Science
MacEwan University, Edmonton AB

Rowan Haigh, Program Head – Offshore Rockfish
Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC
opus locus: Institute of Ocean Sciences (IOS), Sidney BC
Last modified Rd: 2018-09-07

See Also


PBSmapping

Mapping Fisheries Data and Spatial Analysis Tools

v2.73.0
GPL (>= 2)
Authors
Jon T. Schnute [aut], Nicholas Boers [aut], Rowan Haigh [aut, cre], Alex Couture-Beil [ctb], Denis Chabot [ctb], Chris Grandin [ctb], Angus Johnson [ctb], Paul Wessel [ctb], Franklin Antonio [ctb], Nicholas J. Lewin-Koh [ctb], Roger Bivand [ctb]
Initial release
2021-01-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.