[R-sig-Geo] Identifying adjacent polygons within larger polygon groupings

Sean Trende @trende @end|ng |rom re@|c|e@rpo||t|c@@com
Thu Apr 1 21:59:37 CEST 2021


Thank you so much!

-----Original Message-----
From: R-sig-Geo <r-sig-geo-bounces using r-project.org> On Behalf Of Edzer Pebesma
Sent: Thursday, April 1, 2021 3:27 PM
To: r-sig-geo using r-project.org
Subject: Re: [R-sig-Geo] Identifying adjacent polygons within larger polygon groupings



On 01/04/2021 17:01, Sean Trende wrote:
> Hello,
> 
> I am using sf for the project below, but am open to non-sf solutions.
> 
> Given an sf data.frame of polygons sorted into n contiguous groups (e.g., a column in the df identifies each polygon as a member of group (1, . . ., n), where within each group all polygons are neighbors), is there a simple way to identify all polygons in, say, Group 5 that are neighbors to polygons in, say, Group 8 (assuming groups 5 and 8 are neighbors)?
> 
> E.g., if I have an sf data.frame of U.S. counties with a column that identifies the state in which each county is located, is there a way to identify all counties on the border between, say, Kansas and Nebraska?

Yes, look into using st_intersects (or st_touches) with x the counties of Kansas and y the counties of Nebraska.

What you get back is a list of length length(x), with integer vectors, the i-th vector containing the indexes of Nebraska counties touching/intersecting county i of Kansas.

> 
> Thank you so much,
> 
> Sean
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo using r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list