0
votes

I have seen code for this in python, but can't figure out how to do it in R. I have some code but it isn't working for me.

My data has a column with latitude and a column with longitude but they are in the national grid system. I don't know how to post a data set to help

I am trying to use rgdal. I take the lat and long and make a lat, long variable. The code I have found that should help is this

library(rgdal)
whiskies$whiskies.coord = paste0(whiskies$Latitude, ", ", whiskies$Longitude)
proj4string(whiskies$whiskies.coord) = CRS("+init=epsg:27700") # Specify that our coords are in osgb grid coord
whiskies.coord <- spTransform(whiskies.coord, CRS("+init=epsg:4326"))  # spTransform to convert osgb grid to lat/lon

I don't know if I set up the whiskies.coord properly is the base problem. When I run the third command I get this error

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘proj4string<-’ for signature ‘"character", "CRS"’

RowID Distillery Latitude Longitude 1 Aberfeldy 286580 749680 2 Aberlour 326340 842570 3 AnCnoc 352960 839320

1
How big is your data? If it is not prohibitively large can you edit your question to post dput(whiskies) otherwise post dput(whiskies[1:15,]). Good to have a little data to play with.user20650

1 Answers

0
votes

I am going to assume you are using point data.

I think you have not defined whiskies as a spatialpointsdataframe?

In place of your second line I would use the following

coordinates(whiskies)<-~Longitude+Latitude
proj4string(whiskies)<-CRS("+init=epsg:27700")