Subset a SpLineDF
By assigning slots directly, you always take a serious risk that you create objects that are considered invalid in a next step, as is the case in your example. My guess is that when you subset @data, you should also replace the @lines slot with the corresponding subset of @lines (which is a list). The more straightforward (and safe) way is to subset the whole object as if it were a data.frame: TRONCON_TOPO_DSAV_coor[! TRONCON_TOPO_DSAV_coord$doublon, ] (note the absence of @)
On 22/02/17 11:49, Tristan Bourgeois wrote:
Dear all, I'm facing a problem I can't solve even if the solution should not be so hard to find. I want to delete the duplicates in a spatial line dataframe .Those duplicates have been created by shapesfiles merging on QGis (boundary rivers are duplicated by the merging of neighbouring departments layers) So here's the code I wrote : TRONCON_TOPO_DSAV_coord <-readOGR(dsn = "Sorties/Tron?on BDTOPO/TRONCON_TOPO_DSAV/Avec coordonn?es", layer = "TRONCON_TOPO_DSAV_coord") TRONCON_TOPO_DSAV_coord at data $doublon<-duplicated(TRONCON_TOPO_DSAV_coord at data$ID)### Create a fied for duplicate identification TRONCON_TOPO_DSAV_coord at data<-subset(TRONCON_TOPO_DSAV_coord at data ,TRONCON_TOPO_DSAV_coord at data$doublon=="FALSE")### Subset to delete the duplicate TRONCON_TOPO_DSAV_coord at data ### Checking results writeOGR(TRONCON_TOPO_DSAV_coord,dsn = path,layer="TRONCON_TOPO_DSAV_coord_unique_test",driver ="ESRI Shapefile") When I want to export my OGR file, I get this error message :"Error in writeOGR(TRONCON_TOPO_DSAV_coord, dsn = path, layer = "TRONCON_TOPO_DSAV_coord_unique_test", : number of objects mismatch It seems that I have not the same number of objects in the different shapefile slots. How to update these objets after my subset ? Cheers ! "
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: OpenPGP digital signature URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170222/c2f0b74d/attachment.bin>