[R-sig-Geo] manipulate SpatialPolygons object

Tom_R tom.richardson at bristol.ac.uk
Sat Jan 8 22:19:42 CET 2011


Hi Roger, 
Thanks very much for replying! Your input is very much appreciated.

Perhaps I better first give more detail about what I'm trying to do. I have
the trajectories for several animals, for which I have calculated their home
ranges (using kernelUD), and the degree of overlap between the HR's of
different animals. Now I want to conduct a randomisation by reallocating the
observed areas amongst the observed HR's. I want to keep the HR shape &
centroids, whilst either enlarging or shrinking the HR. Then I would
recalculate the overlap for the randomised HR's & compare to the observed
overlap. 

Anyway, long story short, there doesn't seem to be a function that will, 
shrink/enlarge a shape with an area x to area, y, whilst keepin it fixed to
the same centroid.

I though of using a (really embarrassing) brute-force trial & error method
using 'shrinkXY' - see below. This is very dodgy- so far it only
approximates the 'new-area' and doesn't stop when it's near- just flip-flops
around it. Also shrinkXY shifts the object so it does not stay fixed to the
same centriod, which is problematic, but solvable. 


	old_HR_area <- 500
	new_HR_area <- 1000		
	
	temp_area <-0 
	while (temp_area < old_HR_area)			## if we're SHRINKING
		{
		shapefile_HR <- 	scaleXY(shapefile_HR, 1.01)	## shrink shapefile_HR
		blobby <- shape2poly(shapefile_HR, region.id=NULL)
		plot(blobby, add=TRUE)
		for (h in 1:length(blobby))
			{
			if (h == 1) {temp_area <- areapl(blobby[[h]]) } 
			if (h > 1)  {temp_area <- blob_area + areapl(blobby[[h]]) }
			}
		print("shrinking")
		print(temp_area)
		
		while (temp_area < new_HR_area )			## if we're GROWING 
			{
			shapefile_HR <- 	scaleXY(shapefile_HR, .99)	## grows shapefile_HR
			blobby <- shape2poly(shapefile_HR, region.id=NULL)
			plot(blobby, add=TRUE)
			for (h in 1:length(blobby))
				{
				if (h == 1) {temp_area <- areapl(blobby[[h]]) } 
				if (h > 1)  {temp_area <- blob_area + areapl(blobby[[h]]) }
				}
			print("growing")
			print(temp_area)
			}

		}


I already posted a query on this earlier this month- but it didn't attract
any feedback; FYI:
http://r-sig-geo.2731867.n2.nabble.com/changing-the-area-of-a-shapefile-to-a-new-value-td5879842.html

that's all folks!
Tom

-- 
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/manipulate-SpatialPolygons-object-tp5902903p5903163.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list