Here is an example of calculating the distance to nearest, from one set of polygons to another set of polygons (or multi-polygons). Is there an interative way to do this for all the other DISTx shapefiles?ĭISCLAIMER: I'm new to cartography, GIS and more or less to RStudio. Should I worry about the multiple polygons generated by st_cast? (I think not because they are labeled).
St_nearest_feature(DISTAgsc, ANPsc) #nearest feature` # repeating attributes for all sub-geometries for which they may not be constantĪNPsc=st_centroid(ANPs) #calculating centroids. #disbanding ANPs results in the following error message. St_crs(DISTAgs) #returns, "WGS 84 / UTM zone 13N"ĪNPs_84=st_transform(ANPs, 32613) #transforms to WGS 84 to UTM zone 13 N.ĪNPs= st_cast(ANPs_84, "POLYGON") #disbanding to polygons.
I haven't been able to come up with an iterative/loop function to do this code automatically, but here is what I have came up with for: `st_crs(ANPs) #returns, "MEXICO_ITRF_2008" For each district, I want to generate the minimal distance for the closest blue dot. In the picture, you can see some of the 31 polygon shapefiles and the centroids of the "ANPs" shapefile. I have had to modify the crs of the "ANPs" shapefile and disband the multipolygons in order to obtain individual polygons and then finding the closest neighbor and calculate minimal distance for it. I'm currently working on 31 different multipolygon shapefiles for which I need to generate a minimal distance to the nearest polygon "ANPs" (which is a multipolygon itself).