Create SpatialPointsDataFrame from txt-file

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

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

where

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