Skip to content

sp::overlay() not conserving row.names ?

4 messages · Agustin Lobo, Edzer Pebesma

#
I'm using sp::overlay between a SpPolDF and a SpPointsDF:
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
[1] "data.frame"

but I'm confused by the fact that the row.names(delme) are not the same
as the row.names(q1km):
ID       id      val
X1  356.3333 357.3333 643.3162
X2  454.3333 455.3333 653.1833
X3  305.0000 306.0000 101.8930
X4  486.7143 487.7143 448.4612
X5  456.2500 457.2500 544.1646
X6  255.4000 256.4000 139.7507
X7  403.6667 404.6667 659.8114
X8  462.5000 463.5000 537.7209
X9  629.2000 630.2000 399.1040
X10 416.5000 417.5000 278.2879
idname ID   XMIN   XMAX   YMIN   YMAX
X0     X0  0 -8.994 -8.594 43.595 43.995
X1     X1  1 -8.594 -8.194 43.595 43.995
X2     X2  2 -8.194 -7.794 43.595 43.995
X3     X3  3 -7.794 -7.394 43.595 43.995
X4     X4  4 -7.394 -6.994 43.595 43.995
X5     X5  5 -6.994 -6.594 43.595 43.995
X6     X6  6 -6.594 -6.194 43.595 43.995
X7     X7  7 -6.194 -5.794 43.595 43.995
X8     X8  8 -5.794 -5.394 43.595 43.995
X9     X9  9 -5.394 -4.994 43.595 43.995

Is this the way it has to be? If it is, then it's kind of inconvenient
as I would like to join the new table "delme" to q1km at data.
It seems I just have to subtract 1 to the numeric part of
row.names(delme), but would like to make sure.

Agus
#
Agus, sp::overlay will be deprecated at some stage in favour of
sp::over, which is a more consistent and complete approach to the same
problem. For instance, overlay(x,y) would do the same as overlay(y,x),
which is not good, if you think about it a bit longer (my own mistake,
long time ago).

Could you please check if sp::over has the same problems? See also
http://cran.r-project.org/web/packages/sp/vignettes/over.pdf
On 07/06/2011 05:28 PM, Agustin Lobo wrote:

  
    
#
Yes!

I'm doing:
And now not only the row.names are correct and the order of the 2
arguments makes more sense, but the dimensions of the result are also
the same
that that of the first argument
(which implies rows of NA for those polygons with no points: the user
can get rid of
these rows with na.omit() later, for me having the NA is a lot better):
ID      val
0 356.3333 760.5662
1 454.3333 541.5580
2 305.0000 467.0864
ID   XMIN   XMAX   YMIN   YMAX
0  0 -8.994 -8.594 43.595 43.995
1  1 -8.594 -8.194 43.595 43.995
2  2 -8.194 -7.794 43.595 43.995
[1] 299   3
[1] 299   6

I can just join this table to the one of q1km:
idname       ID      val
0      0 356.3333 760.5662
1      1 454.3333 541.5580
2      2 305.0000 467.0864
ID   XMIN   XMAX   YMIN   YMAX idname      val
0  0 -8.994 -8.594 43.595 43.995      0 760.5662
1  1 -8.594 -8.194 43.595 43.995      1 541.5580
2  2 -8.194 -7.794 43.595 43.995      2 467.0864
3  3 -7.794 -7.394 43.595 43.995      3 487.6461

Thanks!
Agus

2011/7/6 Edzer Pebesma <edzer.pebesma at uni-muenster.de>:
#
I'm not too familiar with GIS terminology, but would you agree that
sp::over does (or allows for) a spatial table join?
On 07/06/2011 06:10 PM, Agustin Lobo wrote: