TransWikia.com

Calculating population within a circle excluding intersects with shapely

Geographic Information Systems Asked by Feyzi Bagirov on January 17, 2021

I have a data of a centroid and a count:

    centroid               population id
0   POINT(38.9081 77.0349)  9004.0     0
1   POINT(38.8521,77.0377)  517.0      1
2   POINT(38.9081 77.0377)  10369.0    2
...

The count is a count of the population within a 15km radius from the centroid.

I need to:

  1. take each centroid, buffer it with a 15000 m radius and find out which other circles (radiuses around centroids) in the dataset it intersects.
  2. If it does intersect with one, or more, then calculate the total count of the population within the intersects(one or more) and then subtract those population counts from the count of the circle. In other words, for each buffered centroid, I need to get a shape of the circles without the intersects and count the population within that shape.

Here is my code:

import geopandas as gpd
import geopy
import geopy.distance
from shapely import wkt
from shapely.geometry import Point, LineString, Polygon
import pyproj

df['centroid'] = df['centroid'].apply(wkt.loads)

for i, r in df.iterrows():
a = gpd.GeoSeries(r.centroid, crs = 4326).to_crs(crs = 3857).buffer(15000)
df_dropped = df.drop(i, axis = 0)
l1 = [] # an empty list to collect intersections
for j, s in df_dropped.iterrows():
    b = gpd.GeoSeries(s.centroid, crs = 4326).to_crs(crs = 3857).buffer(15000)
    tf = a.intersects(b)
    l1.append(tf)
    print(l1)

My idea is to get the list populated with intersections with the other circles (True) and then use their indexes to subtract those buffered centroids from the initial buffered centroid to get the semi-moon for the original buffered centroid. If there are more than 1 intersect, then I would subtract it from the previous result, etc., until there are no more intersects. I would then calculate the population for that shape.

What would be the code to achieve that?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP