Error In Getinfo.shapefilen Error Opening Shp File
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more readshapepoly error about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users error in readogr missing layer Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping error in .asspatialpolygonsshapes(map$shapes, ids, proj4string = proj4string, : not polygon shapes each other. Join them; it only takes a minute: Sign up Error opening SHP file in R using maptools readShapePoly up vote 13 down vote favorite 1 I am new to R and was following the following tutorial on could not find function readshapepoly the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the basic shapefile. I have used the following code: library("ggplot2") library("gpclib") library("maptools") setwd("~/Documents/R Projects/Intro to ggplot2") #Intro to ggplot 2 contains the .shp file and associated data sport <- readShapePoly("london_sport.shp") which gets me: Error in getinfo.shape(filen) : Error opening SHP file I have tried omitting the file extension. I have also tried downloading other .shp files which throw the same
Readshapepoly R
error too. I have also tried calling readShapePoly using the full file path, which doesn't work either. I am using R studio (mac OSX), but I get the same error using the standard R window. I have tried the suggestions on the previous closed threat "Error opening SHP file in Rstudio", but to no avail. I would be grateful for any help. Thanks for your attention. Edit: the error was with a missing .dbf file. Thanks to @Spacedman for the fix. r shapefile maptools share|improve this question edited May 17 '13 at 16:54 asked May 17 '13 at 11:09 Steve Senior 66116 Are you sure the shape file works? Have you tried readOGR? –Ari B. Friedman May 17 '13 at 11:27 Try list.files() and see what is returned. Is your shapefile there, so named? Definitely don't add the extension when trying to read it in with readShapePoly –Simon O'Hanlon May 17 '13 at 11:40 8 Have you ALSO got the london_sport.shx and london_sport.dbf files in the same folder? You need all three to make a "Shapefile". –Spacedman May 17 '13 at 12:09 @Spacedman - Good tip, the .dbf file was missing. Have tracked it down and the problem is fixed. Sorry for the basic error. Kinda embarrassed now. Thx all. –Steve Senior May 17 '13 at 14:09 add a comment| 5 Answ
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
Readogr Shapefile
the workings and policies of this site About Us Learn more readshapespatial about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow readogr shapefile r Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each http://stackoverflow.com/questions/16607532/error-opening-shp-file-in-r-using-maptools-readshapepoly other. Join them; it only takes a minute: Sign up error using readShapeSpatial() up vote -1 down vote favorite I am trying to use the below code using maptool: stateShape <- readShapeSpatial("tl_2013_us_state") but i get an error: Error in getinfo.shape(fn) : Error opening SHP file my directory is correct r shapefile shp share|improve this question edited Oct 31 http://stackoverflow.com/questions/26665437/error-using-readshapespatial '14 at 6:01 Olli J 309216 asked Oct 30 '14 at 23:55 Pirates_say_R 1 1 Have you seen this post? –jazzurro Oct 31 '14 at 2:39 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote To read in spatial data you need the .shp, .shx, and .dbf files. You get the following behaviour if bits are missing: NO error if all there: > m=readShapeSpatial("metro") Let's remove the .dbf > file.remove("metro.dbf") [1] TRUE > m=readShapeSpatial("metro") Error in read.dbf(filen1) : unable to open DBF file Now without the .shx: > file.remove("metro.shx") [1] TRUE > m=readShapeSpatial("metro") Error in getinfo.shape(fn) : Error opening SHP file which looks like your error. Do you also have the corresponding .shx file? Shapefiles may also have a .prj file, but readShapeSpatial ignores this, which is why you shouldn't use it. ALWAYS use the rgdal package: > m = readOGR(".","metro") OGR data source with driver: ESRI Shapefile Source: ".", layer: "metro" with 5 features and 12 fields Feature type: wkbPolygon with 2 dimensions > summary(m
Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://gis.stackexchange.com/questions/144011/reading-and-plotting-shapefiles-with-a-custom-function-in-r workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Geographic Information Systems Questions Tags http://qaoverflow.com/question/error-opening-shp-file-when-loading-from-package-data/ Users Badges Unanswered Ask Question _ Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute: error in Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Reading and plotting shapefiles with a custom function in R? up vote 3 down vote favorite 1 I have this piece of code that want to turn into a function r <- readShapeSpatial("roads") b <- readShapeSpatial("buildings") lc error in getinfo.shapefilen <- readShapeSpatial("landcover.shp") here is the preparation laer <- function(x,y,z) { r <- readShapeSpatial(x) b <- readShapeSpatial(y) lc <- readShapeSpatial(z) plot(lc) plot(b,add=T) plot(r,add=T) } Then i use the function that i just created laer("railways.shp","buildings.shp","natural.shp ") and i get this Error in getinfo.shape(filen) : Error opening SHP file the working directory is in check and i also tried putting it inside the script to no avail. shapefile r import function share|improve this question edited Sep 13 '15 at 2:28 scw 13.2k44590 asked Apr 25 '15 at 13:06 gsa 396417 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted I would suggest reading and plotting the data separately. Since you are likely reading different feature classes (points, lines, polys) it will be difficult to define the plotting symbology in a function. However, given your question here is an example that illustrates translating your workflow into a function. The example function does not limit the arguments to three options, but rather allows a vector of n length defining the shapefile names that you want to import. The plot function is optional (TRUE/FA
us Login or Register ASK A QUESTION QuestionsBadgesCategoriesTagsUsers ©2016 site design / logo © 2015 qaoverflow.com; user contributions licensed under cc by-sa 3.0 with attribution required Terms & Privacy Home "Error opening SHP file" when loading from package data 0 I want to shift some of my most commonly used shapefiles to github. I have a new package in development. It worked when built in RStudio, but when I pull the package from github and run it I get the error "Error in getinfo.shape(filen) : Error opening SHP file". When I look inside the package the shapefiles are in place in the data folder. They're being called by individual functions, e.g.load_lon = function(){ require(maptools) lon <<- readShapePoly('data/london_outline_simple.shp', proj4string=CRS('+init=epsg:27700')) } Presumably this method means R is wrongly looking for subfolder ‘data' in the working directory. But I can't think how else to call them, as data() doesn't support shp. Grateful for advice how to load them in. geotheory Asked on March 10, 2015 in No Category. This question was posted in Stack Exchange Share Comment(7) Dason You shouldn't be putting .shp files in the data folder. http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Data-in-packages on March 10, 2015. Update Cancel Josh O'Brien Put the data somewhere like `$SOURCEDIR/ext/external` (in your sources) and then use the path returned by `system.file("external/shapfilename.shp", package="packagename")` to load it from your installed package. You'll find many examples in R's spatial packages, e.g. [here](http://www.inside-r.org/packages/cran/raster/docs/intersect), where a shapefile is loaded using `p on March 10, 2015. Update Cancel geotheory @josh-obrien do you mean folder `/ext/external` within the project root folder? `system.file(..)` is returning an empty string (although the function is reaching the right directory). Using straight `/external` doesn't work either. And when I l