[R] Error opening SHP file

Amoy Yang amoy_y at yahoo.com
Fri Jan 22 18:24:27 CET 2016


This is the results that addresses David's advice.
> library(maptools)
> library(maps)
> state.map <- readShapeSpatial("maps/st24_d00.shp")
Error in getinfo.shape(fn) : Error opening SHP file
> # David question: What does list.files('maps') return? Is there a 'st24_d00.shp' value in there?
> list.files('maps')
character(0)
I actually use the link below to learn how to load state/zip-data on USA map.

# http://stackoverflow.com/questions/1441717/plotting-color-map-with-zip-codes-in-r-or-python
Plotting color map with zip codes in R or Python
|   |
|   |  |   |   |   |   |   |
| Plotting color map with zip codes in R or PythonI have some US demographic and firmographic data. I would like to plot zipcode areas in a state or a smaller region (e.g. city). Each area would be annotated by col... |
|  |
| View on stackoverflow.com | Preview by Yahoo |
|  |
|   |




 

    On Friday, January 22, 2016 10:03 AM, Barry Rowlingson <b.rowlingson at lancaster.ac.uk> wrote:
 

 We can duplicate the error by giving a path to a non-existent
shapefile, which is probably the original problem:

 > require(maptools)
Loading required package: maptools
Loading required package: sp
Checking rgeos availability: TRUE
 > foo=readShapeSpatial("fnord.shp")
Error in getinfo.shape(fn) : Error opening SHP file

The error message there isn't totally explicit, and might cover a
range of other possibilities such as a corrupted shapefile, or a
missing .shx component of the shapefile or whatever.

BUT you probably shouldn't be using readShapeSpatial anyway, as it has
a habit of not reading the coordinate system in the .prj file. I find
it much easier to use `raster::shapefile` which *does* read the
coordinate system *and* gives a more explicit error message for a
missing shapefile:

 > require(raster)
Loading required package: raster
 > foo=shapefile("fnord.shp")
Error in normalizePath(x, winslash = "/", mustWork = TRUE) :
  path[1]="fnord.shp": No such file or directory

"No such file or directory"

Barry



On Fri, Jan 22, 2016 at 2:25 AM, boB Rudis <bob at rudis.net> wrote:
> Agreed with the others. After finding that shapefile and getting it to
> work you are definitely not in the proper working directory.
>
> On Thu, Jan 21, 2016 at 8:40 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>>
>>> On Jan 21, 2016, at 4:39 PM, Amoy Yang via R-help <r-help at r-project.org> wrote:
>>>
>>> Any advice for the following errors?
>>> state.map <- readShapeSpatial("maps/st24_d00.shp")
>>> Error in getinfo.shape(fn) : Error opening SHP file
>>
>> What does list.files('maps') return? Is there a 'st24_d00.shp' value in there?
>>
>>
>> --
>> David.
>>
>>>
>>>      [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  
	[[alternative HTML version deleted]]



More information about the R-help mailing list