[R-sig-Geo] question about accessing geometry from an sf object

Erin Hodgess er|nm@hodge@@ @end|ng |rom gm@||@com
Sun Aug 1 17:38:05 CEST 2021


Thanks so much!

That’s perfect.

Sincerely,
Erin

On Sun, Aug 1, 2021 at 8:20 AM Roger Bivand <Roger.Bivand using nhh.no> wrote:

> Hi Erin,
>
> Maybe consider st_coordinates() to get a matrix of coordinates,
> preferably from st_geometry() of the "sf" object, as hard-coding the name
> of the column containing the "sfc" object might be affected in some cases
> by a different name. Then subset the matrix as you wish.
>
> Hope this helps,
>
> Roger
>
> On Sun, 1 Aug 2021, Erin Hodgess wrote:
>
> > Hello!
> >
> > I have the following sf object:
> >
> >> bt.cent
> > Simple feature collection with 8 features and 1 field
> > Geometry type: POINT
> > Dimension:     XY
> > Bounding box:  xmin: -105.0746 ymin: 38.97641 xmax: -104.7917 ymax:
> 39.82494
> > CRS:           +proj=longlat +datum=WGS84 +no_defs
> >   rnorm.10.                   geometry
> > 1  0.3297790 POINT (-105.0746 38.97641)
> > 2         NA POINT (-104.7917 38.97641)
> > 3 -1.0734667 POINT (-105.0746 39.25925)
> > 4         NA POINT (-104.7917 39.25925)
> > 5 -0.1284898  POINT (-105.0746 39.5421)
> > 6 -0.4071287  POINT (-104.7917 39.5421)
> > 7         NA POINT (-105.0746 39.82494)
> > 8  1.4171128 POINT (-104.7917 39.82494)
> >
> > And I am accessing the geometry (to build covariances) as:
> >> bt.cent$geometry[[1]][1]
> > [1] -105.0746
> >> bt.cent$geometry[[1]][2]
> > [1] 38.97641
> >>
> >
> > Is that the best way to handle the geometry items, please?
> >
> > Thanks in advance,
> > Sincerely,
> > Erin
> >
> >
> > Erin Hodgess, PhD
> > mailto: erinm.hodgess using gmail.com
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> --
> Roger Bivand
> Emeritus Professor
> Department of Economics, Norwegian School of Economics,
> Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway.
> e-mail: Roger.Bivand using nhh.no
> https://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>
-- 
Erin Hodgess, PhD
mailto: erinm.hodgess using gmail.com

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list