Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:07:36+00:00 2026-05-27T20:07:36+00:00

So I have a spatialpolygons object in R; but I am not sure why

  • 0

So I have a spatialpolygons object in R; but I am not sure why I am unable to retrieve the “area” slot from it.

Here’s my R session:

> spatialpolygons
An object of class "SpatialPolygons"
Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 20.50516 57.72918

Slot "area":
[1] 36.85484

Slot "hole":
[1] FALSE

Slot "ringDir":
[1] 1

Slot "coords":
         [,1]     [,2]
[1,] 16.48438 59.73633
[2,] 22.59277 61.14258
[3,] 24.74609 55.03418
[4,] 17.49512 55.12207
[5,] 16.48438 59.73633



Slot "plotOrder":
[1] 1

Slot "labpt":
[1] 20.50516 57.72918

Slot "ID":
[1] "myMultiPolygons"

Slot "area":
[1] 36.85484



Slot "plotOrder":
[1] 1

Slot "bbox":
       min      max
x 16.48438 24.74609
y 55.03418 61.14258

Slot "proj4string":
CRS arguments:
 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 

> spatialpolygons@bbox
       min      max
x 16.48438 24.74609
y 55.03418 61.14258
> spatialpolygons@area
Error: no slot of name "area" for this object of class "SpatialPolygons"
> slotNames(spatialpolygons)
[1] "polygons"    "plotOrder"   "bbox"        "proj4string"
> names(spatialpolygons)
[1] "myMultiPolygons"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:07:36+00:00Added an answer on May 27, 2026 at 8:07 pm

    First off, you should be aware that the @area slot is not a reliable source of information about a SpatialPolygons* object’s actual area. As noted in ?"Polygons-class", the @area slot is just used as an adjunct to plotting (preventing smaller polygons from getting painted over by larger ones) and does not respect projection or properly account for holes in polygons.

    To get accurate areas, you should instead use rgeos::gArea() for layers with projected coordinate reference systems or geosphere::areaPolygon() for those in lat-long coordinate reference systems (i.e. CRS(+proj=longlat)).

    With those caveats out of the way, the following shows how you can get the contents of the @area slots if you do in fact want them.


    The main complication is that the area slot belongs to the Polygon object, not to the SpatialPolygons object (of which the Polygon object is one element). You thus need to first dig down into the SpatialPolygons object to extract to the individual Polygon object(s).

    One you have done that, you can just use the @ operator to extract the contents of the area slot.

    The following example uses the SpatialPolygons object created in Section 7 of the sp package vignette (warning, pdf):

    require(sp)
    # Example pasted in from Section 7 of the sp vignette
    Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
    Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
    Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
    Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)
    Srs1 = Polygons(list(Sr1), "s1")
    Srs2 = Polygons(list(Sr2), "s2")
    Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
    SpP = SpatialPolygons(list(Srs1,Srs2,Srs3), 1:3)
    
    # To extract the area of the first (or in your case only) Polygon
    SpP@polygons[[1]]@area
    # [1] 5.5
    
    # Extract the areas of all three component Polygons
    sapply(SpP@polygons, function(x) x@area)
    # [1]  5.5  1.5 10.0
    
    ## For areas, rgeos::gArea() or geosphere::areaPolygons() are generally more appropriate
    ## (Note, for instance, that it properly accounts for the hole in the 3rd polygon.)
    rgeos::gArea(SpP, byid=TRUE)
    #  s1   s2 s3/4 
    # 5.5  1.5  9.0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have converted devise new session from erb to Haml but doens't work, this is
I have several polygons & I like to extract mean values from several raster
Have a website project in MVC3 C # where I retrieve information from the
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
Have searched the database but need to specifically sum(of hours flown or days off)in
I have a SpatialPolygonsDataFrame with 120 Polygons and some associated data. Now I’d like
Have a really weird one here. The app has two targets, just to be
Have such a problem, hope you'll help me.. Can't find anywhere. Here is the
Have a bunch of classes which I need to do serialize and deserialize from/to
Have you written custom balancers for sharding to balance chunks not using the balancer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.