5

I have a list of suburbs in Queensland, Australia along with their lat/longs.

However, when I try to read in the file in R and assign a CRS, R is giving the following error message:

Error in proj4string<-(*tmp*, value = ) : Geographical CRS given to non-conformant data: 153.53332931

Here are relevant lines of the code,

# Loading suburb list 
qs <- read.csv(file = '../data/Australian_Post_Codes_Lat_Lon.csv', 
               header = TRUE,
               stringsAsFactors = FALSE)

suburb <- qs %>% 
  filter(state == 'QLD') %>% 
  select(postcode,
         suburb,
         lat,
         lon) 

coordinates(suburb) <- c('lat', 'lon')
# Assigning proper Coordinate Reference System (CRS) to Lat/Long.
proj4string(suburb) <- CRS("+init=epsg:4326")

I am using the csv file provided here

  • 7
    Try coordinates(suburb) <- c('lon', 'lat') i think sp expects coordinates in xy not yx. – TimSalabim Oct 8 '17 at 14:08
3

It is what TimSalabim commented, one need to pass coordinates function in xy order, hence, longitude and latitude.

I tested the .csv data and the following code works:

qs <- read.csv(file = '.../data/Australian_Post_Codes_Lat_Lon.csv', sep = ',')
suburb <- subset(qs, qs$state == 'QLD')

library(sp)
coordinates(suburb) <- c('lon', 'lat') #this is the line which answers the question.
proj4string(suburb) <- CRS("+init=epsg:4326")
str(suburb)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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