Extracting GPS Coordinates from SpatVector Object


I am trying to extract/access the GPS coordinates from a SpatVector object returned by getting data for a country using gadm for a country.

I couldn't find a function that does this exactly. What are functions out there that could get only the coordinates?

Here's my code and what I am trying to do:


info <- geodata::gadm("USA", level = 1, version = "latest", path = myGeoPath)

This returns a SpatVector object as follows:

> Poly
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 51, 11  (geometries, attributes)
 extent      : -179.1506, 179.7734, 18.90986, 72.6875  (xmin, xmax, ymin, ymax)
 coord. ref. : lon/lat WGS 84 (EPSG:4326) 
 names       :   GID_1 GID_0       COUNTRY  NAME_1 VARNAME_1 NL_NAME_1 TYPE_1 ENGTYPE_1  CC_1 HASC_1 ISO_1
 type        :   <chr> <chr>         <chr>   <chr>     <chr>     <chr>  <chr>     <chr> <chr>  <chr> <chr>
 values      : USA.1_1   USA United States Alabama   AL|Ala.        NA  State     State    NA  US.AL US-AL
               USA.2_1   USA United States  Alaska AK|Alaska        NA  State     State    NA  US.AK US-AK
               USA.3_1   USA United States Arizona  AZ|Ariz.        NA  State     State    NA  US.AZ US-AZ

All I care to get from this result is the GPS coordinates -179.1506, 179.7734, 18.90986, 72.6875 from the extent object, but I couldn't find functions that get the coordinates. I tried 'vect' and ext from the terra package but they weren't helpful.


Looks like you might be looking for:

# S4 method for SpatVector

# S4 method for SpatVector

# S4 method for SpatVector

# S4 method for SpatVector


1 Like

That's exactly it! Thank you very much!!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.