Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I just want to find the centroids of each parish from the period map.

period_map <- hist_boundaries(c(1900, 1920))

I've tried this code:

centroids <- 

  gCentroid(

    spgeom = methods::as( object = period_map, Class = 'Spatial' )

    , byid = TRUE

  )

But the above code gives the following error:

Error in methods::as(object = period_map, Class = "Spatial") : 

  no method or default for coercing “list” to “Spatial”

Any suggestions?

1 Answer

0 votes
by (107k points)

I think you can download the parish boundaries from the {sf} package format. After that you will be then able to apply the function 

sf::st_centroid()

The above function expects as an argument: a projected spatial object so you can use sf::st_transform() to project from one CRS to another.

If you are a beginner and want to know more about R then do check out the R programming course that will help you in understanding R from scratch.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...