[R-sig-Geo] R-sig-Geo Digest, Vol 43, Issue 21

Nicholas Lewin-Koh nikko at hailmail.net
Sat Mar 24 21:01:11 CET 2007


Hi Katrina,
If your data are really only points all you need to do if you have dat1
and dat2
as two datasets like you described is,
i1<-which(dat1$lat%in%dat2$lat & dat1$long%in%dat2$long)
i2<-which(dat2$lat%in%dat1$lat & dat2$long%in%dat1$long)
o1<-order(dat1$lat[i1],dat1$long[i1]
o2<-order(dat2$lat[i2],dat2$long[i2]
(dat1[i1,-c("lat","long")])[o1,]-(dat1[i2,-c("lat","long")])[o2,]

Mind you this is not elegant, and there is probably a faster ways,
but it will get you what you need.

Cheers
Nicholas

> Message: 1
> Date: Fri, 23 Mar 2007 12:51:39 -0700
> From: "Katrina Bennett" <kbennett at uvic.ca>
> Subject: [R-sig-Geo] Query for overlapping points in R
> To: <r-sig-geo at stat.math.ethz.ch>
> Message-ID: <000901c76d84$b067c5d0$ca0f688e at pcic.uvic.ca>
> Content-Type: text/plain
> 
> Hello, I am trying to query in a spatial data set where overlapping
> points
> exist between two data sets, and then average between these two data sets
> in
> R.
> 
>  
> 
> The problem is that my data sets have slightly difference spatial arrays
> -
> therefore when I go to subtract them, I get an error.
> 
>  
> 
> The data sets are set up as follows, columns of - Lat, Long, 10, 11, 12,
> 1,
> 2, 3, 4, 5, 6, 7, 8, 9 (which represent months in the year)
> 
>  
> 
> Here is the portion of my script that does this. I've played around with
> overlay and merge, but neither seems to do what I want to do - just
> extract
> and then calculate on the common data points between these two files.
> 
>  
> 
>  
> 
>  
> 
> require(sp)
> 
> for (region in regions){
> 
>           #Create an empty holder
> 
>           monthly_variables = NULL
> 
>           
> 
>           #Clip regions (have to examine maptools package)
> 
>           clip_variance <- clip(cbind(variances, io =
> point.in.polygon(variances$Long, variances$Lat,
> shape$shp$shp[[region]]$points$X, shape$shp$shp[[region]]$points$Y)))
> 
>           clip_normal <- clip(cbind(normals, io =
> point.in.polygon(normals$Long, normals$Lat,
> shape$shp$shp[[region]]$points$X, shape$shp$shp[[region]]$points$Y)))
> 
>           #HERE IS WHERE I WANT TO SELECT AND CALCULATE DIFFERENCES ONLY
>           ON
> THE POINTS THAT MATCH in X, Y SPACE
> 
>       
> 
>           # calculate differences, sd (in the time domain) for the 
> 
>             for (month in 1:12){
> 
>              # generate anomalies
> 
>               
> 
>               monthly_anom <- clip_variance[, 3:ncol(clip_variance)] -
> clip_normal[, 3:ncol(clip_normal)]
> 
>               
> 
>               monthly_variables <- rbind(monthly_variables, c(Lat = Lat,
> Long = Long, monthly_anom = monthly_anom))
> 
>         
> 
>             }
> 
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 
> End of R-sig-Geo Digest, Vol 43, Issue 21
> *****************************************




More information about the R-sig-Geo mailing list