Skip to content

Commit 3c774ff

Browse files
authored
Merge pull request #17 from RobLBaker/master
add get_custom_flags
2 parents c0b1b3e + fb47e54 commit 3c774ff

22 files changed

+882
-228
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Imports:
3939
ODataQuery,
4040
magrittr,
4141
stringr,
42-
base
42+
base,
43+
readr
4344
RoxygenNote: 7.2.1
4445
Suggests:
4546
knitr,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export(DC_col_check)
44
export(fuzz_location)
5+
export(get_custom_flags)
56
export(get_dc_flags)
67
export(get_df_flags)
78
export(get_dp_flags)

R/DC_col_check.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#' DC_col_check(yourdataframe)
1717
#' }
1818
DC_col_check <- function(working_df) {
19-
#dwc_terms<-read.csv("https://raw.githubusercontent.com/tdwg/dwc/master/dist/simple_dwc_vertical.csv", header=FALSE) #does not include measurementOrFact or resourceRelationship classes and thus has 179 items vs 196 in the list below.
20-
19+
# dwc_terms<-read.csv("https://raw.githubusercontent.com/tdwg/dwc/master/dist/simple_dwc_vertical.csv", header=FALSE) #does not include measurementOrFact or resourceRelationship classes and thus has 179 items vs 196 in the list below.
20+
2121
dwcterms <- data.frame(DarwinCore = c("type", "modified", "language", "license", "rightsHolder", "accessRights", "bibliographicCitation", "references", "institutionID", "collectionID", "datasetID", "institutionCode", "collectionCode", "datasetName", "ownerInstitutionCode", "basisOfRecord", "informationWithheld", "dataGeneralizations", "dynamicProperties", "occurrenceID", "catalogNumber", "recordNumber", "recordedBy", "recordedByID", "individualCount", "organismQuantity", "organismQuantityType", "sex", "lifeStage", "reproductiveCondition", "behavior", "establishmentMeans", "degreeOfEstablishment", "pathway", "georeferenceVerificationStatus", "occurrenceStatus", "preparations", "disposition", "associatedMedia", "associatedOccurrences", "associatedReferences", "associatedSequences", "associatedTaxa", "otherCatalogNumbers", "occurrenceRemarks", "organismID", "organismName", "organismScope", "associatedOrganisms", "previousIdentifications", "organismRemarks", "materialSampledID", "eventID", "parentEventID", "fieldNumber", "eventDate", "eventTime", "startDayOfYear", "endDayOfYear", "year", "month", "day", "verbatimEventDate", "habitat", "samplingProtocol", "sampleSizeValue", "sampleSizeUnit", "samplingEffort", "fieldNotes", "eventRemarks", "locationID", "higherGeographyID", "higherGeography", "continent", "waterBody", "islandGroup", "island", "country", "countryCode", "stateProvince", "county", "municipality", "locality", "verbatimLocality", "minimumElevationInMeters", "maximumElevationInMeters", "verbatimElevation", "verticalDatum", "minimumDepthInMeters", "maximumDepthInMeters", "verbatimDepth", "minimumDistanceAboveSurfaceInMeters", "maximumDistanceAboveSurfaceInMeters", "locationAccordingTo", "locationRemarks", "decimalLatitude", "decimalLongitude", "geodeticDatum", "coordinateUncertaintyInMeters", "coordinatePrecision", "pointRadiusSpatialFit", "verbatimCoordinates", "verbatimLatitude", "verbatimLongitude", "verbatimCoordinateSystem", "verbatimSRS", "footprintWKT", "footprintSRS", "footprintSpatialFit", "georeferencedBy", "georeferencedDate", "georeferenceProtocol", "georeferenceSources", "georeferenceRemarks", "geologicalContextID", "earliestEonOrLowestEonothem", "latestEonOrHighestEonothem", "earliestEraOrLowestErathem", "latestEraOrHighestErathem", "earliestPeriodOrLowestSystem", "latestPeriodOrHighestSystem", "earliestEpochOrLowestSeries", "latestEpochOrHighestSeries", "earliestAgeOrLowestStage", "latestAgeOrHighestStage", "lowestBiostratigraphicZone", "highestBiostratigraphicZone", "lithostratigraphicTerms", "group", "formation", "member", "bed", "identificationID", "verbatimIdentification", "identificationQualifier", "typeStatus", "identifiedBy", "identifiedByID", "dateIdentified", "ientificationReferences", "identificationVerificationStatus", "identificationRemarks", "taxonID", "scientificNameID", "acceptedNameUsageID", "parentNameUsageID", "originalNameUsageID", "naemAccordingToID", "naemPublishedInID", "taxonConceptID", "scientificName", "acceptedNameUsage", "parentNameUsage", "originalNameUsage", "nameAccordingTo", "namePublishedIn", "namePublishedInYear", "higherClassification", "kingdom", "phylum", "class", "order", "family", "subfamily", "genus", "genericName", "subgenus", "infragenericEpithet", "specificEpithet", "infraspecificEpithet", "cultivarEpithet", "taxonRank", "verbatimTaxonRank", "scientificNameAuthorship", "vernacularName", "nomenclaturalCode", "taxonomicStatus", "nomenclaturalStatus", "taxonRemarks", "measurementID", "measurementType", "measurementValue", "measurementAccuracy", "measurementUnit", "measurementDeterminedBy", "measurementDeterminedDate", "measurementMethod", "measurementRemarks", "resourceRelationshipID", "resourceID", "reationshipOfResourceID", "relatedResourceID", "relationshipOfResource", "relationshipAccordingTo", "relationshipEstablishedDate", "relationshipRemarks"))
2222

2323

R/geography.R

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ get_park_polygon <- function(unit_code) {
3535
#' qc_ValidateCoordinates("OBRI", 36.07951, -84.65610)
3636
#' }
3737
validate_coord <- function(unit_code, lat, lon) {
38-
3938
# get geography from NPS Rest Services
4039
park <- get_park_polygon(unit_code)
4140

@@ -75,13 +74,13 @@ fuzz_location <- function(lat, lon, coord_ref_sys, fuzz_level) {
7574
## Function to get the UTM zone for a given longitude
7675
(floor((long + 180) / 6) %% 60) + 1
7776
}
78-
77+
7978
tempcrs <- if (lat > 0) {
8079
long2UTM(lon) + 32600
8180
} else {
8281
long2UTM(lon) + 32700
8382
}
84-
83+
8584
point <- sf::st_point(c(lon, lat))
8685
point <- sf::st_sfc(point, crs = 4326)
8786
pointutm <- sf::st_transform(x = point, crs = tempcrs)
@@ -91,7 +90,7 @@ fuzz_location <- function(lat, lon, coord_ref_sys, fuzz_level) {
9190
locationlat <- lat
9291
locationlon <- lon
9392
}
94-
93+
9594
# do rounding of UTMs based on fuzz_level
9695
if (fuzz_level == "Fuzzed - 1km") {
9796
fuzzfactor <- 1000
@@ -100,14 +99,14 @@ fuzz_location <- function(lat, lon, coord_ref_sys, fuzz_level) {
10099
} else {
101100
fuzzfactor <- 1
102101
}
103-
102+
104103
locationlat <- locationlat / fuzzfactor
105104
locationlon <- locationlon / fuzzfactor
106105
locationlathi <- ceiling(locationlat) * fuzzfactor
107106
locationlatlo <- floor(locationlat) * fuzzfactor
108107
locationlonhi <- ceiling(locationlon) * fuzzfactor
109108
locationlonlo <- floor(locationlon) * fuzzfactor
110-
109+
111110
# construct simple feature geometry polygon from UTM points
112111
polygon_list <- list(rbind(
113112
c(locationlatlo, locationlonlo),
@@ -117,18 +116,18 @@ fuzz_location <- function(lat, lon, coord_ref_sys, fuzz_level) {
117116
c(locationlatlo, locationlonlo)
118117
))
119118
utmsfg <- sf::st_polygon(polygon_list)
120-
119+
121120
# convert sfg to sfc with appropriate crs
122121
if (coord_ref_sys == 4326) {
123122
utmsfc <- sf::st_sfc(utmsfg, crs = tempcrs)
124123
} else {
125124
utmsfc <- sf::st_sfc(utmsfg, crs = coord_ref_sys)
126125
}
127-
126+
128127
# convert polygon to decimal degrees
129128
wkt <- sf::st_transform(x = utmsfc, crs = 4326)
130129
wkt <- sf::st_as_text(wkt)
131-
130+
132131
# return WKT string
133132
return(wkt)
134133
}
@@ -148,14 +147,15 @@ fuzz_location <- function(lat, lon, coord_ref_sys, fuzz_level) {
148147
#' @return The function returns your dataframe, mutated with an additional two columns of decimal Longitude and decimal Latitude.
149148
#' @export
150149
#'
151-
#' @examples
150+
#' @examples
152151
#' \dontrun{
153-
#' utm_to_ll(df = mydataframe,
154-
#' EastingCol = "EastingCoords",
155-
#' NorthingCol = "NorthingCoords",
156-
#' zone = "17",
157-
#' datum = "WGS84"
158-
#' )
152+
#' utm_to_ll(
153+
#' df = mydataframe,
154+
#' EastingCol = "EastingCoords",
155+
#' NorthingCol = "NorthingCoords",
156+
#' zone = "17",
157+
#' datum = "WGS84"
158+
#' )
159159
#' }
160160
utm_to_ll <- function(df, EastingCol, NorthingCol, zone, datum = "WGS84") {
161161
Base <- as.data.frame(df)
@@ -166,24 +166,26 @@ utm_to_ll <- function(df, EastingCol, NorthingCol, zone, datum = "WGS84") {
166166
Final[1:2] <- lapply(Final[1:2], FUN = function(z) {
167167
as.numeric(z)
168168
})
169-
169+
170170
Final <- cbind(Final$b, Final$a)
171-
172-
v <- terra::vect(Final, crs = paste0("+proj=utm +zone=",
173-
zone,
174-
" +datum=",
175-
datum, "
176-
+units=m"))
177-
171+
172+
v <- terra::vect(Final, crs = paste0(
173+
"+proj=utm +zone=",
174+
zone,
175+
" +datum=",
176+
datum, "
177+
+units=m"
178+
))
179+
178180
converted <- terra::project(v, "+proj=longlat +datum=WGS84")
179-
181+
180182
lonlat <- terra::geom(converted)[, c("x", "y")]
181183

182184
df <- cbind(Mid, lonlat)
183185
df <- plyr::rbind.fill(df, Mid2)
184-
df <- dplyr::rename(df, EastingCol = "b", NorthingCol = "a",
185-
"decimalLongitude" = x, "decimalLatitude" = y)
186+
df <- dplyr::rename(df,
187+
EastingCol = "b", NorthingCol = "a",
188+
"decimalLongitude" = x, "decimalLatitude" = y
189+
)
186190
return(df)
187191
}
188-
189-

0 commit comments

Comments
 (0)