Learn R Programming

marmap (version 1.0.10)

subsetSQL: Creating and querying local SQL database for bathymetric data

Description

subsetSQL queries the local SQL database created with setSQL to extract smaller data subsets.

Usage

setSQL(bathy, header = TRUE, sep = ",", db.name = "bathy_db")
subsetSQL(min_lon, max_lon, min_lat, max_lat, db.name = "bathy_db")

Value

setSQL returns TRUE if the database was successfully created. subsetSQL returns a matrix of class bathy that can directly be used with plot.bathy.

Arguments

bathy

A text file containing a comma-separated, three-column table with longitude, latitude and depth data (no default)

header

does the xyz file contains a row of column names (default = TRUE)

sep

character separating columns in the xyz file, (default=",")

min_lon

minimum longitude of the data to be extracted from the local SQL database

max_lon

maximum longitude of the data to be extracted from the local SQL database

min_lat

minimum latitude of the data to be extracted from the local SQL database

max_lat

maximum latitude of the data to be extracted from the local SQL database

db.name

The name of (or path to) the SQL database to be created on disk by setSQL or from which subsetSQL will extract data ("bathy_db" by default)

Author

Eric Pante

Details

Functions setSQL and subsetSQL were built to work together. setSQL builds an SQL database and saves it on disk. subsetSQL queries that local database and the fields min_lon, max_lon, etc, are used to extract a subset of the database. The functions were built as two entities so that multiple queries can be done multiple times, without re-building the database each time. These functions were designed to access the very large (>5Go) ETOPO 2022 file that can be downloaded from the NOAA website (https://www.ncei.noaa.gov/products/etopo-global-relief-model)

References

NOAA National Centers for Environmental Information. 2022: ETOPO 2022 15 Arc-Second Global Relief Model. NOAA National Centers for Environmental Information. tools:::Rd_expr_doi("doi.org/10.25921/fd45-gt74")

Examples

Run this code
if (FALSE) {
# load NW Atlantic data
data(nw.atlantic)

# write data to disk as a comma-separated text file
write.table(nw.atlantic, "NW_Atlantic.csv", sep=",", quote=FALSE, row.names=FALSE)

# prepare SQL database
setSQL(bathy="NW_Atlantic.csv")

# uses data from the newly-created SQL database:
subsetSQL(min_lon=-70,max_lon=-50,
             min_lat=35, max_lat=41) -> test

# visualize the results (of class bathy)
summary(test)

# remove temporary database and CSV files
system("rm bathy_db") # remove file, for unix-like systems
system("rm NW_Atlantic.csv") # remove file, for unix-like systems
}

Run the code above in your browser using DataLab