I have two shapefiles of the quartiers of Paris, one before (available here) 1860 and one after (available here).
Neighborhood boundaries changed overtime, and I want to do an analysis with geography before 1860.
To do so, I need to compute how many new neighborhoods overlap the old ones by computing weights. There can be several new neighborhoods that overlap only one old neighborhood. At the end, I want to end up with a crosswalk matrix with all the weights of new neighborhoods to old neighborhoods.
Here is a figure to illustrate, (in orange the old, in red the new)
Related
I have blocks of census data (shapefile with the column of interest being pop20) and polygons of areas of interest (shapefile with the column of interest being site). I am trying to get a sum of the population within each of the areas of interest (see example of one area of interest and the census blocks below). I don't know how to join the population estimates (column: pop20) to the areas of interest and account for polygons that are only partially within the areas of interest.
Hence I am interested in the following:
what is the population within each census block within each area of interest, accounting for some blocks only being partial inside (so if 1/2 the block is within the area of interest, assume the population is 1/2 of the value in pop20).
Then what is the sum of all the blocks within the area of interest weighing the blocks that are only partially within the area of interest from part 1.
I have essentially imported by shapefiles using the sf package but then I don't know what to do (do I use st_intersection or st_join or something else)?
pop<-st_read("...\\pop_census2020_prj.shp")
buff<-st_read("...\\trap_mcpbuff_prj.shp")
Thank you for your help.
I have a dataset with cities in a French département (more or less a county) and the population in each of the cities. I have another dataset with geographic coordinates of nursing homes in this département.
I would like to compute the population around a radius of 20km of each of my nursing homes.
But the thing is, I do not know how to do that...
Here is the list of the problems I should resolve:
Which cities are inside the circle?
Which percentage of a city is there in the circle?
Under the assumption that the population is homogeneously evenly distributed, how many people are there in the part of city inside the circle?
Compute the sum of the population inside the circle
Here is a map of my département, the nursing homes are the points in black.
Here is my code (well, it does not work...):
library(sf)
# To know which cities are in the circle:
cities_in_circle <- st_intersects(departement, buffer_nh)
It gives a list and I do not know how to use it...
To know the area overlapped I should use st_intersection and st_area but it does not work with my list above.
Any help would be gladly welcomed!
I am using the sf_package to work around spatial data in r. At this stage, I want to make a spatial join so that the tax lots of my area of study inherit the attributes of the floodplain on which they are located. For example, taxlots may be located in a floodplain categorized as X, VE, A, A0, or V (these are codes that relate to the intensity of the flood in each area).
To do this, I tested the sf function st_join, which will by default rely on st_intersects to determine the spatial join for each entity of my tax lots.
However, I am trying to figure out the criteria used by the function when a tax lot intersects with two different floodplain areas (as in the photo below, in which several lots intersect both with an A floodplain and an AE floodplain). Does it take the value of the area that covers the largest area of the lot? or is it a matter of which area is located upper in the dataframe?
Note that I am not interested in partitioning the intersecting lots so that I divide them according to their areas intersecting one and other floodplain zones.
Photo of tax lots intesecting with more than one floodplain category
By default, st_join(x, y, join = st_intersects) duplicates all features in x,
that intersect with more than one features from y.
If you set the argument largest = TRUE, st_join() returns the x features augmented with the fields of y that have the largest overlap with each of the features of x.
See https://r-spatial.github.io/sf/reference/st_join.html and https://github.com/r-spatial/sf/issues/578 for more details.
I'm trying to extract the coordinates of 50m squares and the flooding factor associated with that square, from data provided by the Environment agency, here (https://data.gov.uk/dataset/risk-of-flooding-from-rivers-and-sea1). I've downloaded the shapefile format, when you click through from that page to this one (http://environment.data.gov.uk/ds/catalogue/#/8d57464f-d465-11e4-8790-f0def148f590).
The data claims to show the flooding factor for each 50m square. I'm completely new to Shapefiles and also new to R. From what I've read I expect the 50m squares to be represented by 'Polygons' and have viewed the Polygons using
polys <- slot(data,"polygons")
and then printing the coordinates of a few of them using
for (i in 1:length(polys)) {
print(paste("Polygon #",i))
print(slot(slot(polys[[i]],"Polygons")[[1]],"coords" ))
}
I'm confused by the output as I assumed a square would be specified by four points, however, the number of (pairs of) coordinates specifying the polygons varies greatly.
Is this assumption correct? Or does the data not consist of 50m squares as it claims?
If they are indeed 50m squares, is there an easy way to extract the coordinates of the centre of the polygons and their IDs?
I am looking to calculate the distance between points (about 47K) and the closest X countries (of all world countries). I have imported the lat/long of points as SpatialPoints, and loaded a world map as a SpatialPolygons. I think I could build off of the advice given here:
SpatialLinesDataFrame: how to calculate the min. distance between a point and a line
It looks like I have to calculate the distance between all countries and all points and then extract the X closest, which is a bit intense with so many points.
In short, is there a way to impose a polygon limit? If not, what would you suggest- my only thought is to import a smaller number of points and then loop through this code (I am a new R user).
Thanks!