1

I am trying to apply a projection to the following dataset from the USGS: https://www.sciencebase.gov/catalog/item/581d052be4b08da350d524ce. After reading in the dataset, the "proj4string" slot shows the data has these CRS arguments:

+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0

Here is a simplified piece of code that results in the error in question:

library(rgdal)
library(maps)
Highway_longlat <- readOGR(dsn = "SourceFolder")
Highway_merc <- spTransform(x = Highway_longlat, CRSobj = CRS(projargs = "+proj=merc"))
map(database = Highway_merc)

I get this error:

Error in par(pin = p) : invalid value specified for graphical parameter "pin"

I was not able to find any information on this error that seemed related to my situation.

1
  • The command plot(Highway_merc) produces the expected image with no error so it seems like the error is not coming from spTransform but rather from the map function. Mar 7, 2017 at 21:30

1 Answer 1

2

Usually one would define the projection in R, before applying spTransform. Did you try this?

library(sp)
coordinates(highway_longlat) <- ~long+lat #Refers to your Long and Lat columns
proj4string(highway_longlat) <- CRS("+init=epsg:4326") # set it to WGS84
highway_merc <- spTransform(highway_longlat,CRS("+proj=merc")) 
#I usually set it to the EPSG code within the CRS ( ), but the above should work as well
2
  • I gave it a shot but ran into a couple issues. (1) I think the 'coordinates' function is for a SpatialPointsDataFrame whereas my dataset is a SpatialLinesDataFrame. (2) When applying CRS to proj4string, I get a warning that I am overriding the existing CRS. Thanks for your suggestion. Mar 7, 2017 at 20:47
  • You can exclude the coordinates function. It is optional. If you can e-mail your code to vjjan91 at gmail ; happy to take a look. Mar 7, 2017 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.