使用point.in.poly

时间:2017-06-08 17:55:21

标签: r spatial

我在spatialEco包中使用point.in.poly来识别某些多边形中的哪些点。我已经使用相同的代码与不同的点和spatialpolygonsDataFrames几年,但今天第一次遇到一个错误信息,我不明白如何纠正它或解释它除了看起来像多边形数据框架没有足够的行。

data.frame中的错误(z @ data,stats :: na.omit(sp :: over(pts,polys))):   参数意味着不同的行数:100,0

我不确定为什么这不适用于我最近的数据集。

点数据集

 s.final2<-
    new("SpatialPointsDataFrame"
        , data = structure(list(long = c(-67.1389857883734, -67.2580227534533, 
    -67.1611857489308, -67.2860090651541, -67.2774425603487, -66.7022063423027, 
    -66.5555034299758, -66.6899614072855, -66.5967801705225, -66.6831837421357, 
    -66.6430840521439, -66.7335112949705, -66.7196256890974, -66.5474247882389, 
    -66.6644375552553, -66.7269946200207, -67.0129382360605, -66.460446230048, 
    -66.574234742749, -66.6280268115943, -66.823247465878, -66.6083954259802, 
    -66.6456660477099, -66.5632382889163, -66.6925414205453, -66.6227952983014, 
    -66.7859704412692, -66.6316728860264, -66.4200108494346, -66.4523465734399, 
    -66.3636296803473, -66.4155488001832, -66.7353122856324, -66.8503519940184, 
    -66.4765874314935, -66.5472698461072, -66.5388818486556, -66.8983644993688, 
    -66.7764144819058, -66.7055099812224, -66.7873740230503, -66.7655013887512, 
    -66.5653525241612, -66.5020221549889, -66.6174479092923, -66.8578154294896, 
    -66.6379017691123, -66.6353925007975, -66.5526066576671, -66.9528638266422, 
    -66.7111203203133, -66.5017155868612, -66.4863526859519, -66.9016686170054, 
    -66.7845834627562, -66.725610087083, -66.7318104715684, -66.7491017554668, 
    -66.6558970539386, -66.5868197004262, -66.7728214807582, -66.4974392121323, 
    -66.5804168534405, -66.5067136062725, -66.51086140434, -66.5980598076676, 
    -67.0588647258535, -67.0433065585277, -67.0455001750199, -66.9202740696382, 
    -67.0691974497089, -66.7893123410778, -67.2095333523268, -66.9158803490609, 
    -66.8028810007714, -67.0998908270866, -66.8176629850103, -66.9949559168541, 
    -66.8686065265752, -66.8743015088145, -66.7732087719059, -67.1420435593673, 
    -66.9401215682184, -66.8269296382148, -67.2811486181201, -67.1787459721092, 
    -67.2382093990631, -67.3224987428913, -67.1658570156273, -66.9986955696494, 
    -67.1466853665795, -67.0709555246256, -67.2185531829118, -67.297550266152, 
    -66.9204885496582, -67.0703500069367, -67.0106709343034, -67.1623044063957, 
    -67.0557926850603, -66.9721499271987), lat = c(41.4586655975182, 
    41.2217539923966, 41.3085362266418, 41.3646669585516, 41.4596789198327, 
    40.9163447630413, 41.1515114987572, 41.3173277464467, 41.1926554537075, 
    41.4783420791874, 40.998848857625, 41.4486411885289, 41.2069316113968, 
    41.3892783894054, 41.4262066958746, 41.3730566084763, 40.9401742166048, 
    41.1542036279233, 41.0932565237523, 41.4742864045174, 40.9043361088211, 
    41.33751010445, 41.2359431500908, 41.2904573330878, 41.0922695588361, 
    40.9488427308388, 41.0292552714036, 41.3878075113122, 41.2429067436533, 
    41.3109232296235, 41.199849595397, 41.1877095284894, 41.2820016076612, 
    40.9589451361905, 41.2504062771105, 41.454932723051, 41.0530782495408, 
    40.8998991171889, 40.9628838088615, 41.0314903766529, 40.8392945925091, 
    40.9091247910856, 41.0084506010852, 41.0943528954344, 41.1422491785676, 
    40.8400748114881, 41.2901921700141, 41.0659189545949, 41.2226185580157, 
    40.9363402824946, 41.1505235198028, 41.3493601263387, 41.2011926654367, 
    40.9654127144879, 41.4034038013095, 40.9821028071505, 40.8616381478545, 
    41.0895617795108, 41.1781022397782, 41.423018760692, 41.3452075182435, 
    41.4026864101983, 41.4949718498974, 41.2926063199577, 41.0072222514177, 
    41.2525156659747, 41.3485150818933, 41.4158970930048, 41.1570784224194, 
    41.2246124129191, 41.0920479566598, 41.3197430764907, 41.2057517073017, 
    41.3416639159883, 41.4518682006059, 41.2650046955242, 41.0598568125233, 
    41.1907669938224, 41.3711897978078, 41.139022759943, 41.2447038944462, 
    41.1688198078266, 41.2961683097689, 41.212729039051, 41.081837057282, 
    41.0238983259361, 40.7089265508929, 40.9046448809266, 40.8643753301313, 
    40.8998107147246, 40.7938645827353, 40.8184009434862, 40.890886956024, 
    40.6353137934637, 40.8226859359571, 40.7096832355072, 40.7412888698525, 
    40.9525733692889, 40.8902392698754, 40.8245267116799)), .Names = c("long", 
    "lat"), row.names = c(NA, -100L), class = "data.frame")
        , coords.nrs = numeric(0)
        , coords = structure(c(-67.1389857883734, -67.2580227534533, -67.1611857489308, 
    -67.2860090651541, -67.2774425603487, -66.7022063423027, -66.5555034299758, 
    -66.6899614072855, -66.5967801705225, -66.6831837421357, -66.6430840521439, 
    -66.7335112949705, -66.7196256890974, -66.5474247882389, -66.6644375552553, 
    -66.7269946200207, -67.0129382360605, -66.460446230048, -66.574234742749, 
    -66.6280268115943, -66.823247465878, -66.6083954259802, -66.6456660477099, 
    -66.5632382889163, -66.6925414205453, -66.6227952983014, -66.7859704412692, 
    -66.6316728860264, -66.4200108494346, -66.4523465734399, -66.3636296803473, 
    -66.4155488001832, -66.7353122856324, -66.8503519940184, -66.4765874314935, 
    -66.5472698461072, -66.5388818486556, -66.8983644993688, -66.7764144819058, 
    -66.7055099812224, -66.7873740230503, -66.7655013887512, -66.5653525241612, 
    -66.5020221549889, -66.6174479092923, -66.8578154294896, -66.6379017691123, 
    -66.6353925007975, -66.5526066576671, -66.9528638266422, -66.7111203203133, 
    -66.5017155868612, -66.4863526859519, -66.9016686170054, -66.7845834627562, 
    -66.725610087083, -66.7318104715684, -66.7491017554668, -66.6558970539386, 
    -66.5868197004262, -66.7728214807582, -66.4974392121323, -66.5804168534405, 
    -66.5067136062725, -66.51086140434, -66.5980598076676, -67.0588647258535, 
    -67.0433065585277, -67.0455001750199, -66.9202740696382, -67.0691974497089, 
    -66.7893123410778, -67.2095333523268, -66.9158803490609, -66.8028810007714, 
    -67.0998908270866, -66.8176629850103, -66.9949559168541, -66.8686065265752, 
    -66.8743015088145, -66.7732087719059, -67.1420435593673, -66.9401215682184, 
    -66.8269296382148, -67.2811486181201, -67.1787459721092, -67.2382093990631, 
    -67.3224987428913, -67.1658570156273, -66.9986955696494, -67.1466853665795, 
    -67.0709555246256, -67.2185531829118, -67.297550266152, -66.9204885496582, 
    -67.0703500069367, -67.0106709343034, -67.1623044063957, -67.0557926850603, 
    -66.9721499271987, 41.4586655975182, 41.2217539923966, 41.3085362266418, 
    41.3646669585516, 41.4596789198327, 40.9163447630413, 41.1515114987572, 
    41.3173277464467, 41.1926554537075, 41.4783420791874, 40.998848857625, 
    41.4486411885289, 41.2069316113968, 41.3892783894054, 41.4262066958746, 
    41.3730566084763, 40.9401742166048, 41.1542036279233, 41.0932565237523, 
    41.4742864045174, 40.9043361088211, 41.33751010445, 41.2359431500908, 
    41.2904573330878, 41.0922695588361, 40.9488427308388, 41.0292552714036, 
    41.3878075113122, 41.2429067436533, 41.3109232296235, 41.199849595397, 
    41.1877095284894, 41.2820016076612, 40.9589451361905, 41.2504062771105, 
    41.454932723051, 41.0530782495408, 40.8998991171889, 40.9628838088615, 
    41.0314903766529, 40.8392945925091, 40.9091247910856, 41.0084506010852, 
    41.0943528954344, 41.1422491785676, 40.8400748114881, 41.2901921700141, 
    41.0659189545949, 41.2226185580157, 40.9363402824946, 41.1505235198028, 
    41.3493601263387, 41.2011926654367, 40.9654127144879, 41.4034038013095, 
    40.9821028071505, 40.8616381478545, 41.0895617795108, 41.1781022397782, 
    41.423018760692, 41.3452075182435, 41.4026864101983, 41.4949718498974, 
    41.2926063199577, 41.0072222514177, 41.2525156659747, 41.3485150818933, 
    41.4158970930048, 41.1570784224194, 41.2246124129191, 41.0920479566598, 
    41.3197430764907, 41.2057517073017, 41.3416639159883, 41.4518682006059, 
    41.2650046955242, 41.0598568125233, 41.1907669938224, 41.3711897978078, 
    41.139022759943, 41.2447038944462, 41.1688198078266, 41.2961683097689, 
    41.212729039051, 41.081837057282, 41.0238983259361, 40.7089265508929, 
    40.9046448809266, 40.8643753301313, 40.8998107147246, 40.7938645827353, 
    40.8184009434862, 40.890886956024, 40.6353137934637, 40.8226859359571, 
    40.7096832355072, 40.7412888698525, 40.9525733692889, 40.8902392698754, 
    40.8245267116799), .Dim = c(100L, 2L), .Dimnames = list(NULL, 
        c("long", "lat")))
        , bbox = structure(c(-67.3224987428913, 40.6353137934637, -66.3636296803473, 
    41.4949718498974), .Dim = c(2L, 2L), .Dimnames = list(c("long", 
    "lat"), c("min", "max")))
        , proj4string = new("CRS"
        , projargs = "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
    )
    )

SpatialPolygonDataFrame

  info2<-
new("SpatialPolygonsDataFrame"
    , data = structure(list(STRATA2 = c(74L, 73L, 62L, 61L, 59L, 60L), AREA = c(0.165, 
0.18, 0.212, 0.217, 0.188, 0.294), PERIMETER = c(3.043, 2.064, 
2.355, 2.006, 2.284, 2.782), SHSTR_G_ = c(9L, 18L, 23L, 25L, 
32L, 43L), SHSTR_G_ID = c(6740L, 6730L, 6621L, 6610L, 6590L, 
6600L), A2 = c(1647L, 1796L, 2105L, 2157L, 1861L, 2896L), STRATUM = c(6740L, 
6730L, 6621L, 6610L, 6590L, 6600L), DEPTH_CODE = c(0L, 0L, 0L, 
0L, 0L, 0L), Area2 = c(NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_), N = c(0, 0, 23, 0, 0, 1), Type = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), .Label = "Number", class = "factor"), N.1 = c(0, 
0, 22, 1, 0, 2), Type.1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "Biomass", class = "factor"), 
    N.2 = c(3, 1, 16, 17, 2, 10), Type.2 = structure(c(1L, 1L, 
    1L, 1L, 1L, 1L), .Label = "Proportional", class = "factor"), 
    Total_N = c(3, 1, 61, 18, 2, 13), revised_total_n = c(3, 
    2, 61, 18, 2, 14)), .Names = c("STRATA2", "AREA", "PERIMETER", 
"SHSTR_G_", "SHSTR_G_ID", "A2", "STRATUM", "DEPTH_CODE", "Area2", 
"N", "Type", "N.1", "Type.1", "N.2", "Type.2", "Total_N", "revised_total_n"
), row.names = c("74", "73", "62", "61", "59", "60"), class = "data.frame")
    , polygons = list(<S4 object of class structure("Polygons", package = "sp")>, 
    <S4 object of class structure("Polygons", package = "sp")>, 
    <S4 object of class structure("Polygons", package = "sp")>, 
    <S4 object of class structure("Polygons", package = "sp")>, 
    <S4 object of class structure("Polygons", package = "sp")>, 
    <S4 object of class structure("Polygons", package = "sp")>)
    , plotOrder = c(4L, 3L, 6L, 1L, 5L, 2L)
    , bbox = structure(c(-67.3333333333334, 40.5863403338222, -66.3373929257812, 
41.5000000000002), .Dim = c(2L, 2L), .Dimnames = list(c("x", 
"y"), c("min", "max")))
    , proj4string = new("CRS"
    , projargs = "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
)
)

    str(info2)
    str(s.final2)

proj4string(info2)
proj4string(s.final2)

#use over to get strata numbers for position data
strata_assign2<-point.in.poly(s.final2,info2)

 sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] grid      datasets  utils     stats     graphics  grDevices methods   base     

other attached packages:
 [1] calibrate_1.7.2     spatialEco_0.1-7    spatstat_1.50-0     rpart_4.1-10        nlme_3.1-131        rgdal_1.2-5        
 [7] maptools_0.9-1      mapdata_2.2-6       maps_3.1.1          sp_1.2-4            car_2.1-4           openxlsx_4.0.0     
[13] plyr_1.8.4          MASS_7.3-45         RODBC_1.3-14        latticeExtra_0.6-28 RColorBrewer_1.1-2  lattice_0.20-34    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9          tensor_1.5           spatstat.utils_1.4-1 splines_3.3.2        minqa_1.2.4         
 [6] tools_3.3.2          nnet_7.3-12          pbkrtest_0.4-6       parallel_3.3.2       mgcv_1.8-16         
[11] quantreg_5.29        deldir_0.1-14        MatrixModels_0.4-1   abind_1.4-5          goftest_1.1-1       
[16] lme4_1.1-12          Matrix_1.2-8         nloptr_1.0.4         polyclip_1.6-1       SparseM_1.74        
[21] foreign_0.8-67 

0 个答案:

没有答案