1# Author: Robert J. Hijmans 2# Date: December 2011 3# Version 1.0 4# Licence GPL v3 5 6if (!isGeneric('symdif')) { 7 setGeneric('symdif', function(x, y, ...) 8 standardGeneric('symdif')) 9} 10 11 12 13setMethod('symdif', signature(x='SpatialPolygons', y='SpatialPolygons'), 14function(x, y, ...) { 15 valgeos <- .checkGEOS(); on.exit(rgeos::set_RGEOS_CheckValidity(valgeos)) 16 17 haswarned <- FALSE 18 19 yy <- list(y, ...) 20 for (y in yy) { 21 if (! identical( .proj4string(x), .proj4string(y)) ) { 22 if (!haswarned) { 23 warning('non identical crs') 24 haswarned <- TRUE 25 } 26 y@proj4string <- x@proj4string 27 } 28 if (rgeos::gIntersects(x, y)) { 29 part1 <- erase(x, y) 30 part2 <- erase(y, x) 31 x <- bind(part1, part2) 32 } 33 } 34 x 35} 36) 37 38