inst/scripts/polygons.r

# Roll your own polygon via mouse interaction

# Example

  # load helper functions
  bioLibrary( "bio.polygons", "bio.coastline" )
  Rlibrary( "rgdal", "sp", "raster", "maps", "mapdata")

  p = list() # start parameter list

  # define "extents" or "bounding box" in lon/lat
  p$xlim = c(-72, -56 ) # longitudes
  p$ylim = c(42, 49) # latitudes
  p$regions = c("Canada", "USA") # library "map" polygon designations
  p$output.directory = project.datadirectory("bio.polygons", "data","Science")
  p$output.filename = "test.dat"   # must have an "extention" like dat or txt etc,

  # plot background map and using mouse interaction define region:
  # left mouse click to register, right mouse click to finish (or [Esc] is using Rstudio)
  polygon.db( DS="create", p=p )


  # Access method 1: low level
  # read the data with read.table or read.csv
  polygon.db( DS="map.background", p=p )
  scotianshelf = read.table( find.bio.gis( "test"  ) )
  lines( scotianshelf, col="green" )  # plot to confirm we have the right data

  # Access method 2: medium
  polygon.db ( DS="map.background", p=p )
  scotianshelf = polygon.db( id="test" )
  lines( scotianshelf, col="orange" )

  # Access method 3: one step .. just the data (projected or not)
  scotianshelf = polygon.db( id="test", crs="+proj=utm +ellps=WGS84 +zone=20 +units=km" )

  # Access method 4: one step data and plot it too
  scotianshelf = polygon.db( id="test", crs="+proj=utm +ellps=WGS84 +zone=20 +units=km", p=p, plotmap=TRUE ) # p contains the extent
AtlanticR/bio.polygons documentation built on May 28, 2019, 11:34 a.m.