Create SpatialPointsDataFrame from txt-file

This code can be used to create an SpatialPointsDataFrame from coordinates in a text-file.

coordDF <- read.table(file="coord.csv", header=T, sep=";", stringsAsFactors=F)
coordEvalSP <- SpatialPointsDataFrame(data=coordDF, coords=coord[, c("E_sweref99", "N_sweref99")])

where

  • E_sweref99 is the east-coordinate (a named field in the text-file)
  • N_sweref99 is the north-coordinate