-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeo.py
100 lines (72 loc) · 2.93 KB
/
geo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Load various geographic boundaries in Philadelphia."""
import esri2gpd
import geopandas as gpd
from . import DATA_DIR, EPSG
def number_to_string(value):
return str(int(value))
def get_city_limits():
"""Load the city limits."""
path = DATA_DIR / "raw" / "City_Limits.geojson"
return gpd.read_file(path).to_crs(epsg=EPSG)
def get_pa_house_districts():
"""PA House districts in in Philadelphia."""
return (
esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_PA_House_Districts/FeatureServer/0",
fields=["house_district"],
)
.assign(house_district=lambda df: df.house_district.apply(number_to_string))
.to_crs(epsg=EPSG)
)
def get_pa_senate_districts():
"""PA Senate districts in in Philadelphia."""
return (
esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_PA_Senate_Districts/FeatureServer/0",
fields=["senate_district"],
)
.assign(senate_district=lambda df: df.senate_district.apply(number_to_string))
.to_crs(epsg=EPSG)
)
def get_school_catchments():
"""Elementary school catchments in in Philadelphia."""
return esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_School_Catchments/FeatureServer/0",
fields=["school_name"],
).to_crs(epsg=EPSG)
def get_police_districts():
"""Police Districts in Philadelphia."""
return (
esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_Police_Districts/FeatureServer/0",
fields=["police_district"],
)
.to_crs(epsg=EPSG)
.assign(police_district=lambda df: df.police_district.apply(number_to_string))
)
def get_zip_codes():
"""ZIP Codes in Philadelphia."""
return (
esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_ZIP_Codes/FeatureServer/0",
fields=["zip_code"],
)
.to_crs(epsg=EPSG)
.assign(zip_code=lambda df: df.zip_code.apply(number_to_string))
)
def get_council_districts():
"""Council Districts in Philadelphia."""
return (
esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_Council_Districts/FeatureServer/0/",
fields=["council_district"],
)
.assign(council_district=lambda df: df.council_district.apply(number_to_string))
.to_crs(epsg=EPSG)
)
def get_neighborhoods():
"""Neighborhoods in Philadelphia."""
return esri2gpd.get(
"https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Gun_Violence_Dashboard_Neighborhoods/FeatureServer/0",
fields=["neighborhood"],
).to_crs(epsg=EPSG)