2

So I'm mapping out the postal regions of my country and it's an enormous, 5.4million row dataframe. I don't need every single little twist and turn of the boundries, so I was super excited to discover mapshaper.org. Seemed easy enough, I just threw my .shp file into it, and it spit back a file 10% of the size! Excellent!

Nope.. now it doesn't play with readShapeSpatial... Hopefully I won't need to provide the shapefile (i can track it down if that parts really necessary)

Original code, works:

canada.shp <- readShapeSpatial("canada", verbose=TRUE, delete_null_obj=TRUE)

New map, doesn't:

canada.shp <- readShapeSpatial("simplecanada", verbose=TRUE, delete_null_obj=TRUE)
Shapefile type: Polygon, (5), # of Shapes: 1621
Error in `rownames<-`(`*tmp*`, value = c("0", "1", "2", "3", "4", "5",  : 
  attempt to set 'rownames' on an object with no dimensions
In addition: Warning message:
In .Map2PolyDF(Map, IDs = IDvar, proj4string = proj4string, force_ring = force_ring,  :
  Null objects with the following indices deleted: 895

traceback() reveals:

4: stop("attempt to set 'rownames' on an object with no dimensions")
    3: `rownames<-`(`*tmp*`, value = c("0", "1", "2", "3", "4", "5", 
   "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", 
   "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", 
   "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", 
   "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", 
   "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", (ETC!!!!)
2: .Map2PolyDF(Map, IDs = IDvar, proj4string = proj4string, force_ring = force_ring, 
       delete_null_obj = delete_null_obj, retrieve_ABS_null = retrieve_ABS_null)
1: readShapePoly("simplecanada", 
       verbose = TRUE, delete_null_obj = TRUE)
  • 1
    And with readOGR() of the rgdal package? – user32309 Sep 25 '14 at 22:33
  • 1
    @mythstified Can you provide a link to your data, in order to reproduce the issue, and investigate a solution? thanks – eblondel Sep 27 '14 at 19:40
1

I am wondering why he bothered to send the data to an external service at all, while sitting in front of a powerful tool like R?

For simplifying shapes, you can e.g. use gSimplify from rgeos package.

See https://gis.stackexchange.com/a/151941/8202 for correct handling of the output.

  • 2
    Better yet, use rmapshaper::ms_simplify to get the same functionality as that website, although it wasn't around when OP posted this question. gSimplify doesn't preserve between-polygon topology, which leaves it with a pretty narrow range of acceptable use cases. And that website is pretty great for getting a sense of how simplifying algorithms work - I'd use it to pick appropriate tolerance values, for sure. – obrl_soil Feb 19 '17 at 12:39
-1

Is it possible you are actually reading a point file, not polygon file? In that case, you might try instead:

readShapePoints("simplecanada", verbose=TRUE, delete_null_obj=TRUE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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