-
Notifications
You must be signed in to change notification settings - Fork 1
04_df_qc_spatial
mike edited this page May 4, 2018
·
1 revision
May 2, 2018 - Mike McMahon (mike.mcmahon@dfo-mpo.gc.ca)
This function identifies points that aren't in the northern hemisphere (i.e. LAT between 0 and 90) and aren't in the western hemisphere (i.e. LON between 0 and 180). By default, it returns the "good" points, but the "return.bad" flag allows it to return only the "bad" points. Southern hemisphere points are not technically invalid, but for Maritimes purposes, they should never come up.
In the example below, we see that by default, running df_qc_spatial on our data gives 1435 records. If we manually make 2 of the coordinates bad, and run it again, those 2 records are omitted. If we want to see what the records were, we can set return.bad=TRUE and they are revealed.
#check how many rows we find by default
> nrow(df_qc_spatial(data))
[1] 1435
# manually mess up 2 records
> data[1,"LATITUDE"]<-91
> data[2,"LONGITUDE"]<-NA
> nrow(df_qc_spatial(data))
[1] 1433
# we find 2 less coordinates
>sp::plot(df_to_sp(data))
Error in .local(obj, ...) : NA values in coordinates
# and we can't plot them!
# if we do our spatial qc prior to plotting them, we can!
>data_clean = df_qc_spatial(data)
>sp::plot(df_to_sp(data_clean))
>
# let's see which records are bad
> df_qc_spatial(data, return.bad = T)
MISSION SETNO LATITUDE LONGITUDE TOTNO
1 ATC1970176 10 91.00000 -60.88333 1642
2 ATC1970176 13 44.81667 NA 1107
>