vino radha
vino radha

Reputation: 33

how to read .shp files in R Tool

link for the .shp file dataset

I want to read a .shp file from R tool, am using the following script:

>scot_LL<-readOGR("C:/Documents and Settings/Admin/Desktop/scotlip/lip cancer/New Scot/scot.shp","scot"),

but when I run the script, am getting the below errors:

>Error in file(paste(DSN, .Platform$file.sep, layer, ".dbf", sep = ""),  <br/>: 
  cannot open the connection<br/>: 
In addition: Warning message:<br/>: 
In file(paste(DSN, .Platform$file.sep, layer, ".dbf", sep = ""),  :<br/>: 
  cannot open file 'C:/Documents and Settings/Admin/Desktop/scotlip/lip cancer/New Scot/scot.dbf': No such file or directory

Can you please help me.

Upvotes: 1

Views: 3483

Answers (1)

rozsasarpi
rozsasarpi

Reputation: 1641

Here is a solution using the maptools package:

library(maptools)

scot_mp <- readShapeSpatial('C:/Documents and Settings/Admin/Desktop/scotlip/lip cancer/New Scot/scot.shp')

proj4string(scot_mp) <- "+proj=longlat +datum=WGS84" # specify projection

plot(scot_mp)

and the result:

enter image description here


EDIT:

Solution using the rgdal package:

scot_mp <- readOGR('C:/Documents and Settings/Admin/Desktop/scotlip/lip cancer/New Scot', 'scot')

The first argument should not necessary contain the name of shape file, but the main problem seems to be that at least the dbf file is not in your folder, all of these are needed and should be in the same folder: scot.shp, scot.dbf, scot.shx. After that it proceeds as the other solution:

proj4string(scot_mp) <- "+proj=longlat +datum=WGS84"
plot(scot_mp)

Upvotes: 4

Related Questions