[R-sig-Geo] Plotting GPS Coordinates on a Polar Projection Using rgdal

Mortimer, Linsey Anne l.mortimer.14 at aberdeen.ac.uk
Mon Oct 23 18:42:43 CEST 2017


Hello,

I am new to R and attempting to plot a map of Antarctica with the GPS coordinates from a circumpolar navigation of the Southern Ocean. I have searched the archives and rgdal-related manuals/blogs/papers to find variations of the code below. I have two issues: firstly, removing the vertical line at -90 degrees on the plot of Antarctica. Secondly, adding the coordinates to this plot using points(). I have tried transforming the coordinates of the points to fit the projection but every time the output is a single point plotted at the end of the vertical line on the Antarctica map, a separate plot of points in a world map projection (stretched) rather than polar projection, or simply an error about coercing an S4 class to a vector. Any advice on how to correct the code or a point in the direction of a guide to this kind of mapping and spatial analysis would be of great help.

An idea of what my dataset looks like (10774579 obs. of 9 variables):

> head(GPS)

ï..GPS_fix    GPS_date  GPS_time GPS_milliseconds  Latitude Longitude GPS_status

1          0  2016-12-24  14:26:03              878 -44.76846  35.36859          2

2          1  2016-12-24  14:26:04              309 -44.76846  35.36859          2

3          2  2016-12-24  14:26:04              878 -44.76849  35.36866          1

4          3  2016-12-24  14:26:05              309 -44.76849  35.36866          2

5          4  2016-12-24  14:26:05              878 -44.76852  35.36873          1

6          5  2016-12-24  14:26:06              305 -44.76852  35.36873          2

GPS_filename    Distance

1  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw 0.000000000

2  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw 0.000000000

3  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw          NA

4  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw 0.003509715

5  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw          NA

6  D:\\Leg1\\0 CT to Marion\\12500\\ACE-D20161224-T142556.raw 0.007045702




The code I’m using:

> install.packages(c("sp", "raster", “crs”))

> library(maptools)

> gpclibPermit()

> data(wrld_simpl)

> antarctica <- wrld_simpl[wrld_simpl$NAME == "Antarctica", ]

> library(rgdal)

> pr <- "+proj=laea +lat_0=-90 +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0" #define projection

> antarctica.laea <- spTransform(antarctica, CRS(pr))

> plot(antarctica.laea)

> ## Now I attempt to make the GPS table into a spatial object and plot the coordinates

> attach(GPS)

> coordinates(GPS) <- c("Longitude","Latitude")

> points(Longitude, Latitude, pch=19, col="red", cex=0.5) #This only plots a singular point at the end of vertical line on the map

> ## Also tried to transform the coordinates but receive an error

>proj4string(GPS) <- CRS("+proj=laea +lat_0=-90 +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")

> gps.ant <- spTransform(GPS, CRS(antarctica.laea))

Error in CRS(antarctica.laea) :

  no method for coercing this S4 class to a vector

In addition: Warning message:

In is.na(projargs) : is.na() applied to non-(list or vector) of type 'S4'

> sessionInfo()

R version 3.4.2 (2017-09-28)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows >= 8 x64 (build 9200)



Matrix products: default



locale:

[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252

[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C

[5] LC_TIME=English_United Kingdom.1252



attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base



other attached packages:

[1] maptools_0.9-2 rgdal_1.2-13   sp_1.2-5



loaded via a namespace (and not attached):

[1] compiler_3.4.2  tools_3.4.2     foreign_0.8-69  grid_3.4.2      lattice_0.20-35



Many thanks,



Linsey Mortimer



	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list