When I use readOGR to read a shapefile from thematicmapping.org, the shapefile is successfully displayed by leaflet in a shinyapp.

However, when I use readOGR to read a shapefile from mt.gov, the result is an Error in ogrInfo.

download.file("http://ftp.geoinfo.msl.mt.gov/Data/Spatial/MSDI/Cadastral/Parcels/Sheridan/SheridanOwnerParcel_shp.zip" , destfile="SheridanOwnerParcel_shp.zip")
#Unzip them ##
SheridanCountyMTParcelShapes = readOGR(dsn=getwd(), layer="SheridanOwnerParcel_shp")

Resulting error :

Error in ogrInfo (dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer

closed as off-topic by Spacedman, Vince, Fran Raga, LaughU, JGH May 28 at 11:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – Spacedman, Vince, Fran Raga, LaughU
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please don't put more than one question in a post. We've fixed your projection problem and I know the solution to the second (shapefile reading) problem. If you can delete it from here and create a new question with just that problem then I'll answer it. – Spacedman May 16 at 6:57
  • You've mutilated this question now so that my answer to one of your questions is now pointless. And as it stands we dont know where your data comes from or how you've saved it. – Spacedman May 27 at 22:23

leaflet requires vector layers to be in WGS84 coordinates.

Your shapefile is not in WGS84 coordinates.

Transform to WGS84 coordinates with:

SCMP_trans = spTransform(SheridanCountyMTParcelShapes,CRS("+init=epsg:4326"))

Test leaflet outside of shiny with:

leaflet(SCMP_trans) %>% addTiles() %>% addPolygons()
  • The shinyapps.io problem is a problem there and you should take it up with them (which I think you have). Let's keep this question to one question for which the solution is "reproject your map to epsg:4326". – Spacedman May 16 at 6:55
  • Thank you @Spacedman. This is the solution to this problem. However, this led to another problem, which i have posted as another question at gis.stackexchange.com/questions/322990/… – Drew May 16 at 12:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.