Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am completely new to GIS but am quite familar with R. I was able to dissolve some zip codes into a larger sales territory.

For reference, my previous question is located here.

However, because I will be doing this for 304 sales markets across the US, I will need to be able to give each a name in order to merge on my sales data after the fact. I am assuming this can be done by accessing the ID slot in the object.

I am trying to access the ID slot. The following code does not work:

tmp2@polygons@Polygons@ID

Results in the following error:

Error: trying to get slot "Polygons" from an object of a basic class ("list") with no slots

Sorry for the long post, but here is my structure. Any help will be greatly appreciated!

An object of class "SpatialPolygons"
Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] -71.57027  41.85902

Slot "area":
[1] 0.1317919

Slot "hole":
[1] FALSE

Slot "ringDir":
[1] 1

Slot "coords":
               x        y
  [1,] -71.50031 41.68146
  [2,] -71.49977 41.67378
  [3,] -71.49942 41.66667
  [4,] -71.51520 41.66557
  [5,] -71.52351 41.66233
  [6,] -71.52396 41.66257
  [7,] -71.52686 41.66166
  [8,] -71.52693 41.66192
  [9,] -71.53344 41.66194
 [10,] -71.53336 41.66227
 [11,] -71.53302 41.66798
 [12,] -71.53346 41.66943
 [13,] -71.53425 41.66901
 [14,] -71.53506 41.66911
 [15,] -71.53519 41.66959
 [16,] -71.53382 41.67065
 [17,] -71.53287 41.67143
 [18,] -71.53369 41.67211
 [19,] -71.53256 41.67314
 [20,] -71.53284 41.67978
 [21,] -71.53262 41.68029
 [22,] -71.53201 41.68061
 [23,] -71.53342 41.68218
 [24,] -71.53287 41.68275
 [25,] -71.53351 41.68434
 [26,] -71.53293 41.68442
 [27,] -71.53246 41.68836
 [28,] -71.53329 41.68855
 [29,] -71.53262 41.69093
 [30,] -71.53384 41.69152
 [31,] -71.53514 41.69312
 [32,] -71.53530 41.69482
 [33,] -71.53604 41.69489
 [34,] -71.53604 41.69548
 [35,] -71.53312 41.69562
 [36,] -71.53327 41.69661
 [37,] -71.53295 41.69729
 [38,] -71.53399 41.69721
 [39,] -71.53412 41.69808
 [40,] -71.53219 41.69826
 [41,] -71.53242 41.70002
 [42,] -71.53274 41.69999
 [43,] -71.53303 41.70017
 [44,] -71.53316 41.70017
 [45,] -71.53319 41.70034
 [46,] -71.53441 41.70025
 [47,] -71.53450 41.70089
 [48,] -71.53282 41.70103
 [49,] -71.53254 41.70104
 [50,] -71.53379 41.70845
 [51,] -71.53292 41.70870
 [52,] -71.53302 41.71069
 [53,] -71.53403 41.71306
 [54,] -71.53391 41.71592
 [55,] -71.53257 41.71872
 [56,] -71.53371 41.71888
 [57,] -71.53384 41.72104
 [58,] -71.53265 41.72037
 [59,] -71.53230 41.72094
 [60,] -71.53395 41.72201
 [61,] -71.53420 41.72399
 [62,] -71.53371 41.72489
 [63,] -71.53299 41.72506
 [64,] -71.53340 41.72669
 [65,] -71.53340 41.72692
 [66,] -71.53418 41.72709
 [67,] -71.53365 41.72785
 [68,] -71.53420 41.72894
 [69,] -71.53442 41.72861
 [70,] -71.53443 41.73016
 [71,] -71.54507 41.73000
 [72,] -71.54674 41.73019
 [73,] -71.54692 41.73026
 [74,] -71.54747 41.73033
 [75,] -71.54880 41.72993
 [76,] -71.54987 41.72994
 [77,] -71.56294 41.72983
 [78,] -71.56864 41.72962
 [79,] -71.57651 41.72934
 [80,] -71.58756 41.71670
 [81,] -71.59122 41.71699
 [82,] -71.59468 41.72292
 [83,] -71.60350 41.72682
 [84,] -71.60391 41.72656
 [85,] -71.61265 41.72805
 [86,] -71.61665 41.72743
 [87,] -71.61792 41.72816
 [88,] -71.64093 41.72759
 [89,] -71.67188 41.72730
 [90,] -71.70062 41.72677
 [91,] -71.72039 41.72619
 [92,] -71.75311 41.72583
 [93,] -71.75460 41.72573
 [94,] -71.76842 41.72530
 [95,] -71.78968 41.72473
 [96,] -71.79125 41.77450
 [97,] -71.79208 41.79509
 [98,] -71.79274 41.80401
 [99,] -71.79435 41.84168
[100,] -71.79448 41.84917
[101,] -71.79448 41.84930
[102,] -71.79493 41.85936
[103,] -71.79529 41.86575
[104,] -71.79652 41.89525
[105,] -71.79683 41.90445
[106,] -71.79773 41.92745
[107,] -71.79778 41.92855
[108,] -71.79830 41.95875
[109,] -71.79876 41.98509
[110,] -71.79924 42.00807
[111,] -71.75028 42.00995
[112,] -71.71357 42.01080
[113,] -71.71001 42.01095
[114,] -71.69858 42.01111
[115,] -71.68098 42.01147
[116,] -71.67803 42.01150
[117,] -71.60625 42.01336
[118,] -71.59078 42.01373
[119,] -71.57686 42.01396
[120,] -71.57342 42.01401
[121,] -71.56548 42.01418
[122,] -71.56365 42.01422
[123,] -71.53801 42.01480
[124,] -71.53751 42.01485
[125,] -71.52909 42.01500
[126,] -71.52871 42.01500
[127,] -71.52861 42.01500
[128,] -71.52774 42.01515
[129,] -71.52063 42.01540
[130,] -71.51777 42.01555
[131,] -71.51171 42.01610
[132,] -71.50618 42.01669
[133,] -71.50207 42.01699
[134,] -71.49876 42.01737
[135,] -71.49820 42.01727
[136,] -71.49100 42.01730
[137,] -71.48386 42.01750
[138,] -71.45816 42.01781
[139,] -71.41567 42.01849
[140,] -71.38140 42.01880
[141,] -71.38143 41.99999
[142,] -71.38130 41.98500
[143,] -71.38150 41.96670
[144,] -71.38150 41.95316
[145,] -71.38150 41.95200
[146,] -71.38173 41.92955
[147,] -71.38160 41.91630
[148,] -71.38150 41.91518
[149,] -71.38153 41.91046
[150,] -71.38170 41.89320
[151,] -71.37380 41.89440
[152,] -71.37122 41.89450
[153,] -71.36543 41.89545
[154,] -71.36166 41.89614
[155,] -71.35965 41.89645
[156,] -71.35690 41.89693
[157,] -71.35494 41.89724
[158,] -71.35451 41.89650
[159,] -71.34901 41.89716
[160,] -71.34674 41.89748
[161,] -71.33870 41.89840
[162,] -71.33907 41.89437
[163,] -71.33948 41.89268
[164,] -71.33978 41.89007
[165,] -71.34073 41.88242
[166,] -71.33412 41.86226
[167,] -71.33440 41.86130
[168,] -71.33490 41.86060
[169,] -71.34210 41.84520
[170,] -71.34193 41.84369
[171,] -71.34110 41.84290
[172,] -71.34080 41.84240
[173,] -71.34050 41.84210
[174,] -71.33522 41.83568
[175,] -71.33930 41.83230
[176,] -71.33960 41.83200
[177,] -71.34490 41.82800
[178,] -71.34715 41.82321
[179,] -71.33920 41.80900
[180,] -71.33924 41.80675
[181,] -71.33930 41.80440
[182,] -71.34098 41.79834
[183,] -71.33930 41.79630
[184,] -71.33395 41.79442
[185,] -71.33239 41.79232
[186,] -71.33274 41.79154
[187,] -71.33181 41.78972
[188,] -71.32939 41.78829
[189,] -71.32958 41.78264
[190,] -71.32782 41.78054
[191,] -71.32257 41.77823
[192,] -71.32301 41.77775
[193,] -71.32338 41.77794
[194,] -71.32412 41.77803
[195,] -71.32282 41.77701
[196,] -71.32225 41.77557
[197,] -71.32046 41.77384
[198,] -71.32251 41.77238
[199,] -71.32282 41.77379
[200,] -71.32263 41.77238
[201,] -71.32833 41.76831
[202,] -71.33153 41.76598
[203,] -71.33166 41.76595
[204,] -71.33233 41.76548
[205,] -71.33295 41.76597
[206,] -71.33706 41.76310
[207,] -71.33677 41.76284
[208,] -71.33621 41.76261
[209,] -71.33333 41.76235
[210,] -71.33280 41.76244
[211,] -71.33318 41.76175
[212,] -71.33771 41.76224
[213,] -71.34218 41.75909
[214,] -71.34223 41.75896
[215,] -71.34237 41.75897
[216,] -71.34385 41.75821
[217,] -71.34514 41.75671
[218,] -71.34727 41.75556
[219,] -71.34643 41.75547
[220,] -71.34683 41.75380
[221,] -71.34773 41.75395
[222,] -71.34768 41.75404
[223,] -71.34901 41.75451
[224,] -71.35177 41.75274
[225,] -71.35289 41.75403
[226,] -71.35071 41.75532
[227,] -71.35120 41.75546
[228,] -71.35249 41.75511
[229,] -71.35381 41.75628
[230,] -71.35257 41.75714
[231,] -71.35265 41.75784
[232,] -71.35377 41.75860
[233,] -71.35562 41.75771
[234,] -71.35509 41.75670
[235,] -71.35503 41.75385
[236,] -71.35618 41.75350
[237,] -71.35686 41.75331
[238,] -71.35782 41.75410
[239,] -71.35820 41.75474
[240,] -71.35860 41.75502
[241,] -71.35926 41.75284
[242,] -71.35560 41.75011
[243,] -71.35666 41.74854
[244,] -71.35576 41.74644
[245,] -71.35569 41.74633
[246,] -71.35542 41.74628
[247,] -71.35555 41.74625
[248,] -71.35557 41.74616
[249,] -71.35486 41.74605
[250,] -71.35433 41.74582
[251,] -71.35420 41.74530
[252,] -71.35431 41.74512
[253,] -71.35453 41.74518
[254,] -71.35541 41.74529
[255,] -71.35616 41.74520
[256,] -71.35855 41.74467
[257,] -71.35987 41.74518
[258,] -71.35964 41.74708
[259,] -71.36036 41.74972
[260,] -71.36233 41.75056
[261,] -71.36184 41.75296
[262,] -71.36168 41.75569
[263,] -71.36155 41.75972
[264,] -71.36249 41.76205
[265,] -71.36497 41.76461
[266,] -71.36779 41.76523
[267,] -71.37029 41.76480
[268,] -71.36843 41.76685
[269,] -71.36770 41.76846
[270,] -71.36709 41.76976
[271,] -71.36635 41.77085
[272,] -71.36575 41.77298
[273,] -71.36629 41.77338
[274,] -71.36632 41.77487
[275,] -71.36545 41.77723
[276,] -71.36647 41.77940
[277,] -71.36868 41.78141
[278,] -71.37053 41.78076
[279,] -71.37211 41.78340
[280,] -71.37067 41.78526
[281,] -71.37060 41.78710
[282,] -71.37238 41.79000
[283,] -71.37279 41.78833
[284,] -71.37362 41.79015
[285,] -71.37347 41.79043
[286,] -71.37411 41.79181
[287,] -71.37450 41.79098
[288,] -71.37439 41.79190
[289,] -71.37505 41.79218
[290,] -71.37690 41.79465
[291,] -71.37978 41.79584
[292,] -71.37881 41.79705
[293,] -71.38173 41.80067
[294,] -71.38625 41.80501
[295,] -71.38801 41.80415
[296,] -71.38785 41.80375
[297,] -71.38806 41.80418
[298,] -71.38635 41.80521
[299,] -71.38793 41.80817
[300,] -71.38824 41.80811
[301,] -71.39032 41.80715
[302,] -71.39373 41.81056
[303,] -71.39199 41.81158
[304,] -71.39437 41.81115
[305,] -71.39249 41.81202
[306,] -71.39136 41.81304
[307,] -71.39161 41.81510
[308,] -71.39197 41.81564
[309,] -71.39193 41.81584
[310,] -71.39172 41.81592
[311,] -71.39128 41.81589
[312,] -71.39114 41.81578
[313,] -71.39108 41.81551
[314,] -71.39051 41.81553
[315,] -71.38938 41.81579
[316,] -71.38782 41.81594
[317,] -71.38686 41.81676
[318,] -71.38644 41.81776
[319,] -71.38578 41.81830
[320,] -71.38602 41.81888
[321,] -71.38596 41.81902
[322,] -71.38563 41.81920
[323,] -71.38438 41.82070
[324,] -71.38336 41.82079
[325,] -71.38281 41.82142
[326,] -71.38314 41.82295
[327,] -71.38131 41.82416
[328,] -71.37913 41.82690
[329,] -71.37620 41.82912
[330,] -71.37624 41.82919
[331,] -71.37597 41.82938
[332,] -71.37346 41.83149
[333,] -71.37397 41.83219
[334,] -71.36973 41.83545
[335,] -71.36927 41.83608
[336,] -71.36911 41.83633
[337,] -71.36894 41.83668
[338,] -71.36875 41.83862
[339,] -71.37272 41.83905
[340,] -71.36992 41.84590
[341,] -71.36879 41.84648
[342,] -71.36839 41.84780
[343,] -71.36917 41.84856
[344,] -71.36773 41.84962
[345,] -71.37012 41.84935
[346,] -71.37180 41.85070
[347,] -71.37124 41.85179
[348,] -71.37129 41.85262
[349,] -71.36857 41.85271
[350,] -71.37282 41.85616
[351,] -71.37303 41.85699
[352,] -71.37487 41.85728
[353,] -71.37501 41.85743
[354,] -71.37565 41.86048
[355,] -71.37682 41.86144
[356,] -71.37867 41.86639
[357,] -71.38082 41.87020
[358,] -71.38281 41.87131
[359,] -71.38459 41.87264
[360,] -71.38188 41.86939
[361,] -71.38089 41.86874
[362,] -71.37994 41.86464
[363,] -71.37913 41.86291
[364,] -71.37925 41.86285
[365,] -71.38084 41.86106
[366,] -71.38036 41.85871
[367,] -71.37900 41.85739
[368,] -71.37891 41.85002
[369,] -71.37675 41.84877
[370,] -71.37908 41.84599
[371,] -71.37844 41.84464
[372,] -71.37726 41.84380
[373,] -71.37832 41.84328
[374,] -71.37776 41.84138
[375,] -71.37891 41.84095
[376,] -71.37974 41.83888
[377,] -71.37997 41.83893
[378,] -71.37986 41.83855
[379,] -71.37958 41.83820
[380,] -71.37955 41.83797
[381,] -71.37960 41.83657
[382,] -71.37917 41.83606
[383,] -71.37762 41.83332
[384,] -71.37945 41.83015
[385,] -71.37959 41.82936
[386,] -71.37955 41.82915
[387,] -71.38044 41.82776
[388,] -71.38062 41.82702
[389,] -71.38167 41.82629
[390,] -71.38292 41.82606
[391,] -71.38303 41.82594
[392,] -71.38429 41.82515
[393,] -71.38547 41.82470
[394,] -71.38585 41.82466
[395,] -71.38618 41.82423
[396,] -71.38752 41.82361
[397,] -71.38883 41.82145
[398,] -71.38895 41.82125
[399,] -71.38874 41.82108
[400,] -71.38854 41.81953
[401,] -71.38875 41.81925
[402,] -71.38865 41.81892
[403,] -71.38860 41.81877
[404,] -71.38817 41.81847
[405,] -71.38816 41.81702
[406,] -71.38976 41.81656
[407,] -71.39041 41.81698
[408,] -71.39137 41.81734
[409,] -71.39183 41.81778
[410,] -71.39262 41.81768
[411,] -71.39549 41.81764
[412,] -71.39725 41.81676
[413,] -71.39943 41.81453
[414,] -71.40280 41.81837
[415,] -71.40416 41.81985
[416,] -71.40446 41.82011
[417,] -71.40503 41.82100
[418,] -71.40599 41.82190
[419,] -71.40768 41.82401
[420,] -71.40783 41.82396
[421,] -71.40801 41.82390
[422,] -71.40581 41.82012
[423,] -71.40638 41.81980
[424,] -71.40587 41.81955
[425,] -71.40610 41.81920
[426,] -71.40549 41.81918
[427,] -71.40506 41.81851
[428,] -71.40491 41.81841
[429,] -71.40345 41.81571
[430,] -71.40304 41.81527
[431,] -71.40132 41.81215
[432,] -71.40258 41.81166
[433,] -71.40296 41.81127
[434,] -71.40248 41.81120
[435,] -71.40273 41.81045
[436,] -71.40057 41.81128
[437,] -71.40089 41.81072
[438,] -71.40248 41.81022
[439,] -71.40188 41.80936
[440,] -71.40008 41.80984
[441,] -71.40241 41.80896
[442,] -71.40121 41.80843
[443,] -71.40114 41.80812
[444,] -71.39988 41.80826
[445,] -71.40103 41.80769
[446,] -71.40060 41.80756
[447,] -71.39865 41.80786
[448,] -71.39865 41.80765
[449,] -71.40063 41.80700
[450,] -71.39951 41.80499
[451,] -71.39909 41.80491
[452,] -71.39831 41.80248
[453,] -71.39742 41.80240
[454,] -71.39709 41.80092
[455,] -71.39480 41.80241
[456,] -71.39746 41.80039
[457,] -71.39615 41.79976
[458,] -71.39514 41.79989
[459,] -71.39548 41.79885
[460,] -71.39257 41.80038
[461,] -71.38282 41.79296
[462,] -71.37879 41.78708
[463,] -71.38006 41.78697
[464,] -71.37967 41.78611
[465,] -71.38141 41.78497
[466,] -71.38408 41.78555
[467,] -71.38812 41.78451
[468,] -71.38759 41.78350
[469,] -71.38824 41.78429
[470,] -71.39054 41.78357
[471,] -71.39055 41.78338
[472,] -71.39084 41.78307
[473,] -71.39162 41.78288
[474,] -71.39151 41.78204
[475,] -71.39007 41.78200
[476,] -71.38965 41.78218
[477,] -71.38954 41.78203
[478,] -71.39135 41.78186
[479,] -71.39186 41.78168
[480,] -71.39154 41.78037
[481,] -71.39109 41.77983
[482,] -71.39093 41.77885
[483,] -71.39101 41.77751
[484,] -71.39024 41.77643
[485,] -71.38984 41.77627
[486,] -71.38990 41.77563
[487,] -71.38902 41.77515
[488,] -71.38871 41.77416
[489,] -71.38834 41.77377
[490,] -71.38916 41.76963
[491,] -71.38946 41.76893
[492,] -71.38885 41.76839
[493,] -71.38789 41.76788
[494,] -71.38724 41.76789
[495,] -71.38696 41.76758
[496,] -71.38621 41.76765
[497,] -71.38587 41.76819
[498,] -71.38610 41.76905
[499,] -71.38571 41.76832
[500,] -71.38577 41.76747
[501,] -71.38587 41.76445
[502,] -71.38518 41.76327
[503,] -71.38565 41.76288
[504,] -71.38585 41.76042
[505,] -71.38642 41.76025
[506,] -71.38685 41.76200
[507,] -71.38750 41.76332
[508,] -71.38801 41.76567
[509,] -71.38891 41.76570
[510,] -71.38915 41.76483
[511,] -71.39026 41.76465
[512,] -71.39053 41.76447
[513,] -71.38908 41.76368
[514,] -71.38907 41.76306
[515,] -71.38850 41.76260
[516,] -71.38793 41.76035
[517,] -71.38750 41.75915
[518,] -71.38708 41.75888
[519,] -71.38689 41.75771
[520,] -71.38721 41.75748
[521,] -71.38670 41.75592
[522,] -71.38622 41.75591
[523,] -71.38590 41.75524
[524,] -71.38392 41.75369
[525,] -71.38308 41.75374
[526,] -71.38108 41.75422
[527,] -71.38195 41.75390
[528,] -71.38259 41.75118
[529,] -71.38159 41.74968
[530,] -71.38356 41.74770
[531,] -71.38501 41.74788
[532,] -71.38481 41.74744
[533,] -71.38589 41.74675
[534,] -71.38789 41.74525
[535,] -71.39059 41.74565
[536,] -71.38988 41.74458
[537,] -71.38641 41.74456
[538,] -71.38558 41.74516
[539,] -71.38365 41.74623
[540,] -71.38317 41.74685
[541,] -71.38164 41.74585
[542,] -71.37792 41.74498
[543,] -71.37597 41.74409
[544,] -71.37709 41.74388
[545,] -71.38077 41.73938
[546,] -71.38144 41.73772
[547,] -71.38145 41.73684
[548,] -71.38074 41.73656
[549,] -71.38093 41.73612
[550,] -71.38093 41.73553
[551,] -71.38122 41.73530
[552,] -71.38195 41.73556
[553,] -71.38328 41.73636
[554,] -71.38285 41.73769
[555,] -71.38329 41.73911
[556,] -71.38455 41.73969
[557,] -71.38422 41.73872
[558,] -71.38831 41.73691
[559,] -71.38865 41.73745
[560,] -71.38996 41.73737
[561,] -71.38911 41.73379
[562,] -71.39294 41.73369
[563,] -71.39362 41.73320
[564,] -71.39014 41.73235
[565,] -71.38900 41.73179
[566,] -71.38640 41.73356
[567,] -71.38550 41.73269
[568,] -71.38548 41.73155
[569,] -71.38579 41.73078
[570,] -71.38292 41.72877
[571,] -71.38266 41.72853
[572,] -71.38255 41.72839
[573,] -71.38046 41.72669
[574,] -71.37939 41.72437
[575,] -71.37694 41.72224
[576,] -71.37064 41.71869
[577,] -71.36481 41.71744
[578,] -71.35555 41.71801
[579,] -71.35452 41.71765
[580,] -71.35688 41.71773
[581,] -71.35864 41.71611
[582,] -71.36326 41.71371
[583,] -71.36357 41.71342
[584,] -71.36449 41.71379
[585,] -71.36401 41.71438
[586,] -71.36459 41.71508
[587,] -71.36459 41.71546
[588,] -71.36474 41.71562
[589,] -71.36487 41.71559
[590,] -71.36471 41.71589
[591,] -71.36486 41.71602
[592,] -71.36526 41.71602
[593,] -71.36523 41.71632
[594,] -71.36559 41.71627
[595,] -71.36551 41.71614
[596,] -71.36480 41.71576
[597,] -71.36486 41.71571
[598,] -71.36500 41.71561
[599,] -71.36473 41.71557
[600,] -71.36470 41.71491
[601,] -71.36418 41.71459
[602,] -71.36453 41.71379
[603,] -71.36591 41.71282
[604,] -71.36644 41.71349
[605,] -71.36731 41.71365
[606,] -71.36856 41.71475
[607,] -71.36878 41.71476
[608,] -71.37066 41.71560
[609,] -71.37209 41.71534
[610,] -71.37044 41.71515
[611,] -71.37050 41.71399
[612,] -71.36974 41.71413
[613,] -71.36997 41.71354
[614,] -71.37128 41.71290
[615,] -71.37410 41.71267
[616,] -71.37490 41.71225
[617,] -71.37510 41.71218
[618,] -71.37254 41.71245
[619,] -71.37085 41.71212
[620,] -71.36919 41.71366
[621,] -71.36672 41.71159
[622,] -71.36559 41.70783
[623,] -71.36564 41.70781
[624,] -71.36551 41.70671
[625,] -71.36527 41.70647
[626,] -71.36531 41.70615
[627,] -71.36458 41.70351
[628,] -71.36509 41.70128
[629,] -71.36526 41.70081
[630,] -71.36509 41.70056
[631,] -71.36596 41.69876
[632,] -71.36598 41.69847
[633,] -71.36605 41.69777
[634,] -71.36552 41.69313
[635,] -71.36301 41.69221
[636,] -71.36492 41.68876
[637,] -71.37123 41.68595
[638,] -71.37379 41.67847
[639,] -71.37296 41.67245
[640,] -71.37819 41.66647
[641,] -71.38443 41.66870
[642,] -71.38618 41.67093
[643,] -71.39039 41.67217
[644,] -71.39054 41.68272
[645,] -71.38891 41.68354
[646,] -71.38965 41.68533
[647,] -71.38941 41.68609
[648,] -71.39173 41.68668
[649,] -71.38912 41.68776
[650,] -71.39043 41.68830
[651,] -71.39154 41.68862
[652,] -71.39105 41.69023
[653,] -71.38940 41.69110
[654,] -71.38851 41.69451
[655,] -71.38911 41.69538
[656,] -71.38687 41.69575
[657,] -71.38612 41.69452
[658,] -71.38539 41.69550
[659,] -71.38596 41.69664
[660,] -71.38266 41.69788
[661,] -71.38141 41.69780
[662,] -71.38165 41.69912
[663,] -71.38353 41.69960
[664,] -71.38497 41.69916
[665,] -71.38530 41.69926
[666,] -71.38604 41.69818
[667,] -71.38723 41.69804
[668,] -71.39116 41.69647
[669,] -71.39209 41.69718
[670,] -71.39237 41.69701
[671,] -71.39074 41.69488
[672,] -71.39161 41.69278
[673,] -71.39331 41.69297
[674,] -71.39428 41.69518
[675,] -71.39756 41.69658
[676,] -71.39487 41.69450
[677,] -71.39426 41.69414
[678,] -71.39463 41.69364
[679,] -71.39331 41.69169
[680,] -71.39446 41.69017
[681,] -71.39383 41.68740
[682,] -71.39294 41.68683
[683,] -71.39354 41.68624
[684,] -71.39291 41.68563
[685,] -71.39325 41.68505
[686,] -71.39283 41.68401
[687,] -71.39666 41.68354
[688,] -71.39984 41.68389
[689,] -71.39977 41.68433
[690,] -71.40140 41.68503
[691,] -71.40144 41.68537
[692,] -71.40248 41.68641
[693,] -71.40237 41.68769
[694,] -71.40160 41.68740
[695,] -71.40090 41.68753
[696,] -71.40092 41.68915
[697,] -71.40120 41.68798
[698,] -71.40225 41.68782
[699,] -71.40289 41.68921
[700,] -71.40389 41.68996
[701,] -71.40342 41.69138
[702,] -71.40438 41.69195
[703,] -71.40420 41.69267
[704,] -71.40568 41.69359
[705,] -71.40652 41.69550
[706,] -71.40661 41.69595
[707,] -71.40806 41.69560
[708,] -71.41006 41.69623
[709,] -71.41139 41.69723
[710,] -71.41155 41.69722
[711,] -71.41205 41.69741
[712,] -71.41371 41.69775
[713,] -71.41632 41.69937
[714,] -71.41634 41.69942
[715,] -71.41770 41.70242
[716,] -71.41680 41.69903
[717,] -71.42089 41.69856
[718,] -71.42106 41.69844
[719,] -71.42041 41.69825
[720,] -71.41675 41.69815
[721,] -71.41556 41.69825
[722,] -71.41528 41.69749
[723,] -71.41421 41.69696
[724,] -71.41334 41.69686
[725,] -71.41203 41.69633
[726,] -71.41036 41.69506
[727,] -71.40848 41.69443
[728,] -71.40456 41.68915
[729,] -71.40814 41.68709
[730,] -71.41038 41.68861
[731,] -71.41230 41.68846
[732,] -71.41562 41.68966
[733,] -71.41872 41.68999
[734,] -71.41698 41.68963
[735,] -71.41481 41.68808
[736,] -71.40748 41.68544
[737,] -71.40509 41.68567
[738,] -71.40306 41.68559
[739,] -71.40580 41.68449
[740,] -71.41477 41.68412
[741,] -71.42322 41.68574
[742,] -71.42863 41.68605
[743,] -71.43070 41.68573
[744,] -71.43404 41.68681
[745,] -71.43573 41.68576
[746,] -71.43688 41.68698
[747,] -71.44195 41.68695
[748,] -71.44426 41.68872
[749,] -71.44338 41.68910
[750,] -71.44274 41.68898
[751,] -71.44305 41.69261
[752,] -71.44517 41.69300
[753,] -71.44536 41.69318
[754,] -71.44518 41.69284
[755,] -71.44639 41.69485
[756,] -71.44653 41.69535
[757,] -71.44720 41.69587
[758,] -71.44952 41.69582
[759,] -71.45125 41.69620
[760,] -71.45157 41.69733
[761,] -71.45329 41.69655
[762,] -71.45207 41.69504
[763,] -71.45183 41.69353
[764,] -71.45057 41.69236
[765,] -71.44731 41.69200
[766,] -71.44759 41.69124
[767,] -71.44639 41.69036
[768,] -71.44928 41.68818
[769,] -71.45003 41.68692
[770,] -71.44944 41.68653
[771,] -71.44924 41.68503
[772,] -71.45091 41.68471
[773,] -71.44938 41.68180
[774,] -71.44775 41.67693
[775,] -71.44855 41.67696
[776,] -71.44920 41.67844
[777,] -71.45041 41.67795
[778,] -71.45211 41.67831
[779,] -71.45270 41.67765
[780,] -71.45866 41.67751
[781,] -71.45771 41.67379
[782,] -71.45784 41.67243
[783,] -71.45784 41.67210
[784,] -71.45804 41.67023
[785,] -71.46689 41.66987
[786,] -71.46871 41.67024
[787,] -71.47862 41.67031
[788,] -71.47995 41.67029
[789,] -71.47718 41.67402
[790,] -71.47734 41.68254
[791,] -71.50031 41.68146



Slot "plotOrder":
[1] 1

Slot "labpt":
[1] -71.57027  41.85902

Slot "ID":
[1] "TRUE"

Slot "area":
[1] 0.1317919



Slot "plotOrder":
[1] 1

Slot "bbox":
        min       max
x -71.79924 -71.32046
y  41.66166  42.01880

Slot "proj4string":
CRS arguments: NA 
share|improve this question
    
The output of dput(tmp2) might be more useful - it would give us something to play around with. E.g., it would be helpful to be able to see the results of str(tmp2), class(tmp2@polygons), str(tmp2@polygons), and so on... –  Matt Parker Oct 24 '12 at 22:51
    
There is an expert, active R community on SO, so it might be a better place for this question. Let us know if you would like it migrated. –  whuber Oct 25 '12 at 10:23
add comment

2 Answers

up vote 3 down vote accepted

You are not accessing the slot correctly. You could try sapply to iterate through the polygon ID slot to apply a function.

sapply(slot(tmp2, "polygons"), function(i) slot(i, "ID"))

I would be very cautions in attempting to change only the polygon ID. This ID is occurs through all slots as a common link. For example, the rownames of the data slot share this ID. To effectively do what you explained in this post you would have to figure out all of the slot ID's that need to be changed. If you want to simply dissolve your features you can use the gUnionCascaded in the rgeos package.

I think that your problem may be that you are not retaining an ID link to crosswalk back to your data. Here is an example of dissolving on an attribute contained in your data. If you need to intersect with another sp dataset to retrieve the values that you can dissolve on you can use the over function in sp. In the below example I am using the maptools package for access to the built-in "wrld_simpl" dataset to use as an example. The id argument in the gUnionCascaded function retains the associated values in the resulting SpatialPolygons object. Once dissolved, this object needs to be coerced into a SpatialPolygonsDataFrame object so there is an associated dataframe. The ordering of the "id" vector is taken care of internally in the function which is why you extract these values from the SpatialPolygons object. This should provide you with an ID that you can join your data on. Please be aware that you cannot use merge on a sp object. The merge function resorts the dataframe in the data slot. In doing this it breaks the rownames. An alternative is to use match. I often use a syntax like this:

spdata@data=data.frame(spdata@data, newdata[match(rownames(spdata@data), newdata$ID),])

where; spdata is your sp object and newdata is the dataframe that you want to join to the data slot in spdata.

# ADD REQUIRED PACKAGES
require(sp)
require(rgeos)
require(maptools)

# USE DATA FROM maptools PACKAGE
data(wrld_simpl)
  str(wrld_simpl@data)

# DISSOLVE BASED ON "REGION" COLUMN USING rgeos::gUnionCascaded 
regions <- gUnionCascaded(wrld_simpl, id=wrld_simpl@data$REGION)

# CREATE A DATAFRAME OF VALUES RETAINED FROM "REGION" COLUMN
( sdf <- data.frame(ID=row.names(regions)) )

# ASSIGN "REGION" VALUES TO rownames SO DATA MATCHES slots CORRECTLY
row.names(sdf) <- row.names(regions)

# CREATE A SpatialPolygonsDataFrame OBJECT WITH A data slot HOLDING REGION IDS.  
regions <-  SpatialPolygonsDataFrame(regions, sdf) 

# PLOT RESULTS   
par(mfrow=c(2,1))
  plot(wrld_simpl)
  plot(regions)
share|improve this answer
    
I wasn't aware of the gUnionCascaded function. All I am looking to do is take a zip code map of the US, and slice that into 304 territories so I can merge/map sales data. Is there any easier way to do this? My brute force method was to build 304 territories and stitch them together. Thanks! –  Btibert3 Oct 25 '12 at 14:33
    
I do not think that you need to write code that modifies the slot IDS. In reading your two post, I am unclear on your data structure. Do you have multiple datasets that you want to intersect and then dissolve based on an added attribute or do you have an existing attribute in your zipcode shapefile that defines territories that you can dissolve on without intersecting with another dataset? How have you defined your territories? –  Jeffrey Evans Oct 25 '12 at 20:36
    
I have a shapefile that is the US at the zip code level. I have an excel file that identifies all zip codes within each of the 304 sales territories. My process was going to be: read in the US zip code shape file, read in the excel file, subset the US shapefile in R and create the polygon for each of the markets. Lastly, I was going to piece this back together. Obviously the end result is that I need one shapefile that has my sales territories, not zip codes, and a way to merge on my sales data to each territory so I can do choropleths, etc. –  Btibert3 Oct 26 '12 at 0:51
1  
Just use the match function on zip codes to add the territories column to your polygon data then run the above code, using the territories column as the id argument, and you will have a polygon dataset of your territories. –  Jeffrey Evans Oct 26 '12 at 2:02
add comment

To do what you're trying to do, you need something like this:

tmp2@polygons[[1]]@ID

However, you might want to describe the data setup in a little more depth - it appears there's only one polygon in the SpatialPolygons object, so giving it an id isn't really going to help much. And if you're importing from a shapefile, for instance, it might make more sense to use a SpatialPolygonsDataFrame.

share|improve this answer
    
Thanks for the help. I fiddled with accessing ID everywhere I could think of. I only kept 1 polygon for illustration. As referenced above, I am going to write code to create my markets (304 distinct polygons) and stitch them back together. Being able to change the ID is important, as this will be the common link between the map and my sales data by territory. –  Btibert3 Oct 25 '12 at 12:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.