我在.csv文件中有一组经度/纬度坐标,需要将它们与人口普查区块相匹配。我一直在尝试使用UScensus2010软件包在R中找出如何做到这一点,其中包括每个状态的SpacialPolygonDataFrames和每个块组的多边形。如何将这些坐标与其块组匹配?
这是多边形列表中的第一项(来自UScensus2010 @polygons):
StringBuilder sb =new StringBuilder();
int[] sort = {1,2,3,4,5,7,89,4,9,6,11,23,178,29};
for(int i : sort) sb.append(i+", ");
if(sb.length()>2) sb.delete(sb.length()-2, sb.length());
System.out.println(sb.toString());
我认为over()或point.in.SpatialPolygon函数最有意义,但我无法弄清楚如何使用它们。我用测试坐标创建了一个SpatialPoints对象:
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] -75.88144 42.18167
Slot "area":
[1] 0.0006202178
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] -75.87509 42.17416
[2,] -75.87541 42.17414
[3,] -75.87557 42.17413
[4,] -75.87571 42.17411
[5,] -75.87599 42.17410
[6,] -75.87901 42.17396
[7,] -75.87904 42.17396
[8,] -75.87908 42.17396
[9,] -75.87931 42.17393
[10,] -75.87936 42.17391
[11,] -75.87943 42.17385
[12,] -75.87967 42.17345
[13,] -75.87982 42.17323
[14,] -75.87992 42.17311
[15,] -75.88004 42.17301
[16,] -75.88055 42.17269
[17,] -75.88072 42.17257
[18,] -75.88076 42.17253
[19,] -75.88080 42.17244
[20,] -75.88080 42.17229
[21,] -75.88068 42.17182
[22,] -75.88067 42.17166
[23,] -75.88069 42.17054
[24,] -75.88070 42.17043
[25,] -75.88074 42.16901
[26,] -75.88191 42.16884
[27,] -75.88257 42.16875
[28,] -75.88325 42.16864
[29,] -75.88486 42.16844
[30,] -75.88521 42.16840
[31,] -75.88658 42.16828
[32,] -75.88702 42.16825
[33,] -75.88735 42.16826
[34,] -75.88771 42.16829
[35,] -75.88820 42.16770
[36,] -75.88829 42.16759
[37,] -75.88836 42.16751
[38,] -75.88851 42.16734
[39,] -75.88938 42.16631
[40,] -75.89001 42.16561
[41,] -75.89125 42.16422
[42,] -75.89165 42.16374
[43,] -75.89213 42.16320
[44,] -75.89258 42.16272
[45,] -75.89341 42.16183
[46,] -75.89346 42.16187
[47,] -75.89359 42.16200
[48,] -75.89417 42.16270
[49,] -75.89444 42.16301
[50,] -75.89500 42.16362
[51,] -75.89553 42.16421
[52,] -75.89596 42.16467
[53,] -75.89563 42.16609
[54,] -75.89556 42.16651
[55,] -75.89554 42.16687
[56,] -75.89554 42.16712
[57,] -75.89557 42.16749
[58,] -75.89565 42.16790
[59,] -75.89575 42.16825
[60,] -75.89589 42.16870
[61,] -75.89668 42.17135
[62,] -75.89760 42.17439
[63,] -75.89804 42.17560
[64,] -75.89829 42.17622
[65,] -75.89876 42.17728
[66,] -75.89920 42.17815
[67,] -75.89054 42.18697
[68,] -75.88629 42.19130
[69,] -75.88553 42.19212
[70,] -75.88494 42.19192
[71,] -75.88338 42.19143
[72,] -75.88261 42.19109
[73,] -75.88189 42.19073
[74,] -75.88129 42.19045
[75,] -75.88115 42.19065
[76,] -75.88096 42.19090
[77,] -75.88072 42.19114
[78,] -75.88047 42.19138
[79,] -75.88008 42.19170
[80,] -75.87972 42.19196
[81,] -75.87933 42.19220
[82,] -75.87908 42.19234
[83,] -75.87851 42.19260
[84,] -75.87817 42.19274
[85,] -75.87760 42.19294
[86,] -75.87643 42.19337
[87,] -75.87628 42.19342
[88,] -75.87543 42.19373
[89,] -75.87508 42.19385
[90,] -75.87479 42.19393
[91,] -75.87369 42.19421
[92,] -75.87233 42.19446
[93,] -75.87187 42.19455
[94,] -75.87097 42.19469
[95,] -75.87037 42.19479
[96,] -75.86948 42.19496
[97,] -75.86923 42.19501
[98,] -75.86776 42.19532
[99,] -75.86678 42.19553
[100,] -75.86646 42.19560
[101,] -75.86503 42.19596
[102,] -75.86470 42.19606
[103,] -75.86430 42.19622
[104,] -75.86394 42.19638
[105,] -75.86367 42.19651
[106,] -75.86304 42.19687
[107,] -75.86249 42.19724
[108,] -75.86233 42.19736
[109,] -75.86212 42.19750
[110,] -75.86158 42.19798
[111,] -75.86113 42.19841
[112,] -75.86102 42.19834
[113,] -75.86071 42.19819
[114,] -75.86050 42.19810
[115,] -75.86027 42.19803
[116,] -75.85999 42.19798
[117,] -75.85977 42.19795
[118,] -75.85943 42.19794
[119,] -75.85929 42.19795
[120,] -75.85930 42.19778
[121,] -75.85937 42.19716
[122,] -75.85944 42.19657
[123,] -75.85947 42.19627
[124,] -75.85949 42.19608
[125,] -75.85948 42.19553
[126,] -75.85940 42.19456
[127,] -75.85940 42.19450
[128,] -75.85919 42.19215
[129,] -75.85919 42.19182
[130,] -75.85924 42.19156
[131,] -75.85935 42.19128
[132,] -75.85946 42.19107
[133,] -75.85966 42.19081
[134,] -75.86037 42.19004
[135,] -75.86068 42.18970
[136,] -75.86084 42.18952
[137,] -75.86113 42.18923
[138,] -75.86124 42.18913
[139,] -75.86276 42.18880
[140,] -75.86330 42.18865
[141,] -75.86357 42.18856
[142,] -75.86388 42.18846
[143,] -75.86459 42.18819
[144,] -75.86523 42.18789
[145,] -75.86569 42.18765
[146,] -75.86641 42.18722
[147,] -75.86680 42.18696
[148,] -75.86705 42.18677
[149,] -75.86738 42.18649
[150,] -75.86861 42.18532
[151,] -75.86902 42.18492
[152,] -75.86918 42.18475
[153,] -75.86982 42.18409
[154,] -75.87090 42.18285
[155,] -75.87295 42.18047
[156,] -75.87327 42.18006
[157,] -75.87352 42.17969
[158,] -75.87357 42.17961
[159,] -75.87372 42.17937
[160,] -75.87398 42.17887
[161,] -75.87414 42.17847
[162,] -75.87419 42.17836
[163,] -75.87433 42.17795
[164,] -75.87444 42.17752
[165,] -75.87453 42.17703
[166,] -75.87484 42.17417
[167,] -75.87504 42.17416
[168,] -75.87509 42.17416
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] -75.88144 42.18167
Slot "ID":
[1] "new_york.blkgrp10_1"
Slot "area":
[1] 0.0006202178
然后,我尝试使用over()来挑选人口普查区块组:
dat <- data.frame(Longitude = -73.92642301, Latitude = 40.63296731)
coordinates(dat) <- ~ Longitude + Latitude
提供错误消息:
over(dat, new_york.blkgrp10@polygons)
如何解决此问题和/或是否有更简单的方法将人口普查区块组分配给经度/纬度坐标?