How to calculate area of polygons within distance of other polygons - r

I have two sf polygon objects - one of land parcels and the other of parks. All parcels are within 2 miles of at least one park, but some parcels are within that distance to multiple parks. Parks and parcels are not of uniform size or shape.
For each land parcel, I want to calculate the area of park polygons within a half mile. Other posts answer how to calculate the area of each park and the distance between polygons, but not how I can calculate the area of parks within a half mile of each parcel. Any advice would be appreciated. Thank you!

Figured I should post the steps I took to solve this:
Create a buffer sf object for the parcels (dist = 1/2 mile)
Create an intersection sf object for the buffer and the parks (this will still have the parcel IDs, since it's based on each parcel's buffer)
Use st_area the calculate the area of those intersections
convert the intersection sf object to a data.table
merge that data.table with the original parcel sf object based on PID
That results in the parcel sf object having the area of the parks within a half mile of them.

Related

Determining landcover %'s (polygon layer) that is not within burned areas (raster layer)

I am trying to extract information on the % of different vegetation cover types within areas that have not been burned. However, the data I was given for the park includes areas that have been burned as a raster file in NAD_83 projection, and the vegetation cover as a polygon layer in WGS_84 projection. Essentially, I'm trying to erase the overlap between areas that have been burned and the vegetation layer to only look at vegetation cover types in areas that have not been burned. The vegetation is broken into 12 class labels based on understory/shrub cover type, and I want a percentage of how much each cover type occurs in unburned area. Can anyone help with this transformation?
I have access to ArcGIS Desktop v 10.8.2 with an Advanced licence.
I have tried converting the raster to points which worked, but I don't know how to make the points into polygons that perfectly match the size/shape of the original raster. I don't know another way to "erase" the two layers other than by trying to convert the raster to a polygon with the same coordinate system.
ArcMap is probably reprojecting the data on the fly, but you could start by transforming the raster and vector layers to a common datum.
If I understand correct, you want to know the area of veg types represented as polygons that are within unburned areas which are represented as pixels in a raster.
If that is correct, I would convert the unburned areas to a polygon layer. It might help to convert the burn raster such that unburned = 1 all else = 0 or NA, then convert unburned to a polygon.
With the unburned areas represented as polygons, intersect this layer with the veg layer. Doing so will cut the veg layer by the unburn polygon layer. The result should allow you to only select polygons that intersected with the unburned layer once it is vectorized. Get the area of these polygons grouped by veg type.

R: Species distribution modeling for a riverine species - all coordinates not falling in raster cells

I am running Species Distribution Modeling in R in biomod2 package for an riverine species in the Ganges River basin so I clipped the bioclim layer with the river network that I obtained from hydrosheds. Resolution of bioclim layer and river network at 1km*1km. But the problem arose as not all coordinates fell on the raster cells (probable causes - coordinates taken at banks, river networks not correctly delineated etc.)
So how do I overcome this problem? Do I pull the coordinates to the nearest raster cell (nearest in terms of vertices? - If this is the correct method than an easier way to do this too) or do I just leave the coordinates - more than half occurrence points would be deleted.
enter image description here

How to estimate density of Polygon intersections in R?

I have many polygons that represent search areas of different people. By intersecting all that areas I want to get density map - 1 person searched in this area, two in that area and so on.
My trouble is that I have >5k geoJSON polygons and I need to intersect all of them. Is there a way to do it R's sf package or (less preferably) in ArcGIS?

Calculate minimum distance between multiple polygons with R

I'm still somewhat new to R and the sf package...
I have two sets of multipolygon data that I am trying to analyze. My first set of polygons (fires) contains hundreds of wildfire perimeters. The second set (towns) contains hundreds of urban areas boundaries.
For each fire, I would like to calculate the distance to the closest town (fire polygon edge to closest town polygon edge), and add that as a field to each fire.
So far I have mostly been using the sf package for spatial data. In my searches, I can only find minimum distance methods for polygons to points, points to points, lines to points, etc. but cannot seem to find polygon to polygon examples. Any help to send me in the right direction would be much appreciated! Thank you.
#TimSalabim Thank you for sending me in the right direction. I was able to accomplish what I was after. Maybe not the most elegant solution, but it worked.
# create an index of the nearest feature
index <- st_nearest_feature(x = poly1, y = poly2)
# slice based on the index
poly2 <- poly2 %>% slice(index)
# calculate distance between polygons
poly_dist <- st_distance(x = poly1, y= poly2, by_element = TRUE)
# add the distance calculations to the fire polygons
poly1$distance <- poly_dist

How to calculate geo-distance from a polygon?

I have a shapefile with 50+ different polygonal shapes (representing 50+ different regions) and 10,000+ data points that are supposed to be present in one of the regions. The thing is, the 10,000+ points are already coded with a region they are supposed to be in, and I want to figure out how far they are from this coded region in geo-spatial distance.
My current approach (code below), which involves converting shapefiles to owin objects from the sp library and using distfun gets me distances in lat,long euclidean space. But I would like to get geo-spatial distances (eventually to convert to km). Where should I go next?
#basically cribbed from http://cran.r-project.org/web/packages/spatstat/vignettes/shapefiles.pdf (page 9)
shp <- readShapeSpatial("myShapeFile.shp", proj4string=CRS("+proj=longlat +datum=WGS84"))
regions <- lapply(slot(shp, "polygons"), function(x) SpatialPolygons(list(x)))
windows <- lapply(regions, as.owin)
# need to convert this to geo distance
distance_from_region <- function(regionData, regionName) {
w <- windows[[regionName]]
regionData$dists <- distfun(w)(regionData$lat, regionData$long)
regionData
}
I'd project the data to a euclidean (or near euclidean) coordinate system - unless you are spanning a large chunk of the globe then this is feasible. Use spTransform from maptools or sp or rgdal (I forget which) and convert to a UTM zone near your data.
You also might do better with package rgeos and the gDistance function:
gDistance by default returns the cartesian minimum distance
between the two geometries in the units of the current projection.
If your data is over a large chunk of globe then... tricky... 42...
Barry

Resources