1

I have a shapefile that is the outline of a lake that I will be mapping with in R. I load in the shapefile with:

Lake <- readOGR("File directory", "Lake")

I need this shapefile to be a Polygon, not a SpatialPolygon or SpatialPolygonDataFrame.

str(Lake)
Formal class 'SpatialPolygons' [package "sp"] with 4 slots
..@ polygons   :List of 1
.. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
.. .. .. ..@ Polygons :List of 3
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.7 39.6
.. .. .. .. .. .. ..@ area   : num 0.000255
.. .. .. .. .. .. ..@ hole   : logi FALSE
.. .. .. .. .. .. ..@ ringDir: int 1
.. .. .. .. .. .. ..@ coords : num [1:1333, 1:2] -84.8 -84.8 -84.8 -84.8 
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.8 39.6
.. .. .. .. .. .. ..@ area   : num 7.39e-07
.. .. .. .. .. .. ..@ hole   : logi TRUE
.. .. .. .. .. .. ..@ ringDir: int -1
.. .. .. .. .. .. ..@ coords : num [1:40, 1:2] -84.8 -84.8 -84.8 -84.8 
.. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
.. .. .. .. .. .. ..@ labpt  : num [1:2] -84.8 39.6
.. .. .. .. .. .. ..@ area   : num 3.21e-06
.. .. .. .. .. .. ..@ hole   : logi TRUE
.. .. .. .. .. .. ..@ ringDir: int -1
.. .. .. .. .. .. ..@ coords : num [1:65, 1:2] -84.8 -84.8 -84.8 -84.8  
.. .. .. ..@ plotOrder: int [1:3] 1 3 2
.. .. .. ..@ labpt    : num [1:2] -84.7 39.6
.. .. .. ..@ ID       : chr "0"
.. .. .. ..@ area     : num 0.000255
..@ plotOrder  : int 1
..@ bbox       : num [1:2, 1:2] -84.8 39.6 -84.7 39.6
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84   
+towgs84=0,0,0"

Using RGeostats package, to perform geostatistical analyses, I have to be working with a polygon, not any other object type. This is because I have to select the area encompassing the entire lake to run further analysis on. Object db.data stores fish densities at specific lat/lon points.

db.data=db.polygon(db.data, Lake)
The input object is of type ' SpatialPolygons '. It should be of type '   
polygon '
The function is interrupted
Error: Invalid object type

How do I get my shapefile to be read as a polygon?

1 Answer 1

0

Try assigning the @polygons object to a new object.

Like so:

LakePolygons<-Lake@polygons
Sign up to request clarification or add additional context in comments.

2 Comments

That turns it into a list db.data=db.polygon(db.data, LakePolygons) The input object is of type ' list '. It should be of type ' polygon ' The function is interrupted Error: Invalid object type
Can you try either of these: Lake$polygons Lake@polygons$polygons

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.