2

I can see that it's possible to load in csv data to R (as per here: Load a CSV as Simple Features R), however, it appears to me that there is a limitation on the range of delimiters allowed given the direct use of GDAL (COMMA/SEMICOLON/TAB/SPACE, see "Layer Creation options" here).

So with sp() I could use sep as follows:

pow_pointX <- read.csv("./data/poi_2015_12_scot06340459.csv", sep="|")

Given that the pipe character "|" is default for Ordnance Survey datasets distributed in the UK, this seems like a serious limitation. Has anyone found a workaround that doesn't require the use of sp()?

3
  • Not clear what you are getting at here. The read.csv is a base function and has nothing to do with sp or sf. The function results in a data.frame that can then be coerced into a spatial object. It is looking like your issue is reading the file. Do you, in fact, have multiple delimiters or are you trying to use a pipe delimiter? If you need more flexibility in reading your flat file take a look at read.table Mar 10, 2020 at 15:06
  • Sorry - I should add in a more substantial vignette to show the issue I'm referencing- will do so asap and edit question Mar 10, 2020 at 15:18
  • Perhaps what you want is not something to read a table, but something to convert the read-in CSV to simple features?
    – Mox
    Mar 11, 2020 at 16:31

1 Answer 1

2

The GDAL CSV driver documentation documents that only the following separators are implemented:

SEPARATOR=COMMA/SEMICOLON/TAB/SPACE

Alternatively, read in as a plain CSV using read.csv or read.table or data.table::fread perhaps, and then convert to sf using:

sfd = read.table(filename, sep="|")
sfd = st_as_sf(sfd, coords=c("long","lat"), crs=27700)

(adjusting parameters to fit your CSV file).

Your Answer

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

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