[R-sig-Geo] Changing coords in SpatialPolgyon

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Sep 12 08:56:58 CEST 2012


Nick, posting a small, reproducible example will help us to help you.

On 09/12/2012 02:24 AM, Nick Matzke wrote:
> Hi -- I am trying to change the coordinates of the points in a polygon
> (after shrinking the polygon towards the centroid.
> 
> However, any way I try it (direct assignment, slot(), attr()), I get
> this error:
> 
> =================
> object of type 'S4' is not subsettable
> =================
> 
> 
> Here's an example of the error, showing the objects I'm using.  Any help
> **much** appreciated.
> 
> ===========================
> 
> 
>>                 class(all_emerged_islands_at_this_height_break)
> [1] "SpatialPolygons"
> attr(,"package")
> [1] "sp"
>>                 all_emerged_islands_at_this_height_break
> An object of class "SpatialPolygons"
> Slot "polygons":
> [[1]]
> An object of class "Polygons"
> Slot "Polygons":
> [[1]]
> An object of class "Polygon"
> Slot "labpt":
> [1] 91.44457 25.55424
> 
> Slot "area":
> [1] 0.25305
> 
> Slot "hole":
> [1] FALSE
> 
> Slot "ringDir":
> [1] 1
> 
> Slot "coords":
>            x      y
>  [1,] 91.273 25.804
>  [2,] 91.348 25.817
>  [3,] 91.408 25.844
>  [4,] 91.498 25.831
>  [5,] 91.528 25.763
>  [6,] 91.573 25.694
>  [7,] 91.633 25.681
>  [8,] 91.723 25.681
>  [9,] 91.768 25.626
> [10,] 91.768 25.544
> [11,] 91.768 25.448
> [12,] 91.708 25.380
> [13,] 91.648 25.312
> [14,] 91.558 25.298
> [15,] 91.468 25.298
> [16,] 91.378 25.325
> [17,] 91.318 25.380
> [18,] 91.228 25.421
> [19,] 91.123 25.435
> [20,] 91.108 25.558
> [21,] 91.123 25.640
> [22,] 91.198 25.708
> [23,] 91.258 25.776
> [24,] 91.273 25.804
> 
> 
> 
> Slot "plotOrder":
> [1] 1
> 
> Slot "labpt":
> [1] 91.44457 25.55424
> 
> Slot "ID":
> [1] "89"
> 
> Slot "area":
> [1] 0.25305
> 
> 
> [[2]]
> An object of class "Polygons"
> Slot "Polygons":
> [[1]]
> An object of class "Polygon"
> Slot "labpt":
> [1] 92.00535 25.12364
> 
> [...etc...]
> 
> 
>>                
>>                 class(tmppoly_shrunken)
> [1] "Polygon"
> attr(,"package")
> [1] "sp"
>>                 tmppoly_shrunken
> An object of class "Polygon"
> Slot "labpt":
> [1] 91.44457 25.55424
> 
> Slot "area":
> [1] 25.29848
> 
> Slot "hole":
> [1] FALSE
> 
> Slot "ringDir":
> [1] 1
> 
> Slot "coords":
>              x        y
>  [1,] 89.72883  3.00000
>  [2,] 90.47883 28.18185
>  [3,] 91.07883 28.45185
>  [4,] 91.97883 28.32185
>  [5,] 92.27883 27.64185
>  [6,] 92.72883 26.95185
>  [7,] 93.32883 26.82185
>  [8,] 94.22883 26.82185
>  [9,] 94.67883 26.27185
> [10,] 94.67883 25.45185
> [11,] 94.67883 24.49185
> [12,] 94.07883 23.81185
> [13,] 93.47883 23.13185
> [14,] 92.57883 22.99185
> [15,] 91.67883 22.99185
> [16,] 90.77883 23.26185
> [17,] 90.17883 23.81185
> [18,] 89.27883 24.22185
> [19,] 88.22883 24.36185
> [20,] 88.07883 25.59185
> [21,] 88.22883 26.41185
> [22,] 88.97883 27.09185
> [23,] 89.57883 27.77185
> [24,] 89.72883 28.05185
> 
>>                
>>             
> slot(all_emerged_islands_at_this_height_break[j]@polygons[[1]]@Polygons[[1]],
> "coords", check=FALSE) = slot(tmppoly_shrunken, "coords")
> Error in
> slot(all_emerged_islands_at_this_height_break[j]@polygons[[1]]@Polygons[[1]],
>  :
>   object of type 'S4' is not subsettable
>>
>>
> ===========================
> 
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list