eblondel / cleangeo

Cleaning geometries from spatial objects in R

Home Page:https://github.com/eblondel/cleangeo/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The clgeo_Clean function doesn't clean my data

andrestoroq opened this issue · comments

Hello Emmanuel,

I'm trying to make a spatial join between a SpatialPointsDataFrame and a SpatialPolygonsDataFrame (I create this from a SpatialLinesDataFrame, through the functions SpatialLines2PolySet and PolySet2SpatialPolygons). But my Spatial Polygons have some problems (GEOM_VALIDITY and ORPHANED_HOLE), which I can't make the spatial join that I want. I used your package, and the function clgeo_Clean, but it doesn't clean my shape.

My code is the next.

Malla_vial5 <- 
  readShapePoly("Malla_vial3_", proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), verbose = TRUE, repair= TRUE, delete_null_obj = TRUE, force_ring = TRUE, retrieve_ABS_null = TRUE)

report <- 
      clgeo_CollectionReport(Malla_vial5)
clgeo_SummaryReport(report)
sp.clean <- 
      clgeo_Clean(Malla_vial5, errors.only = "ORPHANED_HOLE")
report.clean <- 
      clgeo_CollectionReport(sp.clean)
clgeo_SummaryReport(report.clean)

However, I can't upload the shape,the system don't support that file type. I have it in dropbox. Could you give your email to share you the fIle?

PD: Thank you for your package, it is the only package that try to fix these problems with the spatial objects.

Thanks @andrestoroq for reporting. They are many potential problems of geometry validity, and possibly your data highlights some new rules of cleaning that are not yet supported (beyond the type of geometry validity issue you have).

If you can share with me the dataset (dropbox,etc). Send it to emmanuel.blondel1 (at) gmail.com
I will have a look, try to reproduce the issue, and i hope to improve clgeo_Clean. Since you created a SpatialPolygonDataFrame from lines data, maybe the best is to share the source data + the piece of R script you run so far. Thanks in advance

I already have shared you the file in dropbox, with the original source (SpatialLines) and the another I created (SpatialPolygons).

The complete code is this:

Malla_viall <- 
  readShapeLines("MallaVial_wgs84", proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), verbose=FALSE,
                 repair=TRUE, delete_null_obj=T)

Malla_vial1 <- 
  SpatialLines2PolySet(Malla_viall)

Malla_vial2 <- 
  PolySet2SpatialPolygons(Malla_vial1, close_polys = TRUE)

proj4string(Malla_vial2) <- 
  proj4string(Malla_vial)

Malla_vial3 <- 
  SpatialPolygonsDataFrame(Malla_vial2, data= slice(Malla_viall@data, 0:29177))

Malla_vial5 <- 
  readShapePoly("Malla_vial3_", proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), verbose = TRUE, repair= TRUE, delete_null_obj = TRUE, force_ring = TRUE, retrieve_ABS_null = TRUE)

Malla_vial5 <- 
  readShapePoly("Malla_vial3_", proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), verbose = TRUE, repair= TRUE, delete_null_obj = TRUE, force_ring = TRUE, retrieve_ABS_null = TRUE)

report <- 
      clgeo_CollectionReport(Malla_vial5)
clgeo_SummaryReport(report)
sp.clean <- 
      clgeo_Clean(Malla_vial5, errors.only = "ORPHANED_HOLE")
report.clean <- 
      clgeo_CollectionReport(sp.clean)
clgeo_SummaryReport(report.clean)

Thanks for anything you can make about it.

@andrestoroq i had a look, i will need to spend more time on it. I didn't look in the isolated case of orphaned holes (1 single issue in your data), but as i suspected, i need to add some additional rule to deal with GEOS exceptions (most of geometry issues are raised are warnings). I need enhance the clgeo_Clean function. I let you know ASAP.

@andrestoroq With the improvement done in #16, i could clean your entire dataset. However, please consider that on a total of 29177 features in your polygon dataset, the cleaning process removed 10105 corresponding for most of them to false polygons (ie. lines of type A-B-A) introduced by PolySet2SpatialPolygons function and causing GEOS errors.

You could reproduce the exercise if you reinstall cleangeo from Github:

require(devtools)
install_github("eblondel/cleangeo")

Anyway i'm going to share with you the output as ESRI Shapefile and possibly GML.

Hi @andrestoroq did you have the chance to test?

Hello @eblondel, excuse me for the delay in the response.

Yes, the change you made was perfect for me :) :D. Now, my data don't have any problem and I can make the spatial join. It's a pity that in the process it removes some elements, but at least now I can move forward in my project.

Thank you so much for all your help with your package, also thank you for your fast answer.

Have a agreat day.

Thanks @andrestoroq good to see it solved your issue!