Example #1
0
def compute_toc_tiers_from_metrolink_stations(
    stations: geopandas.GeoDataFrame,
    clip: geopandas.GeoDataFrame,
    cushion: float = DEFAULT_CUSHION,
) -> geopandas.GeoDataFrame:
    """
    Compute TOC Tiers from Metrolink stations, clipped to a boundary.

    Parameters
    ==========

    stations: geopandas.GeoDataFrame
        The Metrolink stations data frame.

    clip: geopandas.GeoDataFrame
        The boundary to clip the toc tiers to (probably the City of Los Angeles)
    """
    stations = stations.to_crs(f"EPSG:{SOCAL_FEET}")
    stations = stations.assign(
        tier_4=geopandas.GeoSeries([shapely.geometry.GeometryCollection()] *
                                   len(stations),
                                   crs=f"EPSG:{SOCAL_FEET}"),
        tier_3=stations.geometry.buffer(750.0 * cushion),
        tier_2=stations.geometry.buffer(1500.0 * cushion),
        tier_1=stations.geometry.buffer(2640.0 * cushion),
    )
    stations = stations.assign(
        tier_1=stations.set_geometry("tier_1").to_crs(f"EPSG:{WGS84}").tier_1,
        tier_2=stations.set_geometry("tier_2").to_crs(f"EPSG:{WGS84}").tier_2,
        tier_3=stations.set_geometry("tier_3").to_crs(f"EPSG:{WGS84}").tier_3,
        tier_4=stations.set_geometry("tier_4").to_crs(f"EPSG:{WGS84}").tier_4,
    ).to_crs(f"EPSG:{WGS84}")
    stations = stations[stations.set_geometry("tier_1").intersects(
        clip.iloc[0].geometry)]

    stations["mode"] = "metrolink"

    return stations[[
        "Name",
        "ext_id",
        "description",
        "geometry",
        "tier_1",
        "tier_2",
        "tier_3",
        "tier_4",
        "mode",
    ]].rename(columns={
        "ext_id": "station_id",
        "Name": "name"
    })
Example #2
0
def extract_dublin_local_authorities(
        geometries: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
    """Extract Dublin Local Authorities from Ireland Small Area Geometries Data.

    Args:
        geometries (gpd.GeoDataFrame): Ireland Small Area Geometries

    Returns:
        gpd.GeoDataFrame: Dublin Small Area Geometries
    """
    return geometries.assign(
        COUNTYNAME=lambda x: x["COUNTYNAME"].apply(unidecode)
    )[lambda x: np.isin(
        x["COUNTYNAME"],
        ["Dun Laoghaire-Rathdown", "Fingal", "South Dublin", "Dublin City"],
    )]
Example #3
0
isf_wo = isf_wo.drop(['srchAssetID', 'gpscoordinateX', 'gpscoordinateY', 'initialproblemID', \
       'resolveddatetime', 'entereddate', 'finalresolutionID'], axis = 1)
isf_wo_inv = pd.merge(isf_wo, inv, how='left', on = 'inventoryID')
isf_wo_inv = isf_wo_inv.drop(['gpscoordinateX', 'gpscoordinateY'], axis = 1)

# Setting up data into geopandas
geometry = [Point(xy) for xy in zip(isf_wo_inv['gpsX'], isf_wo_inv['gpsY'])]
gLights2 = GeoDataFrame(isf_wo_inv, geometry=geometry)
gLights2 = gLights2.drop_duplicates(subset = ['WoID'])
geometry = [Point(xy) for xy in zip(NCR2['X'], NCR2['Y'])]
gNCR2 = GeoDataFrame(NCR2, geometry=geometry)

BUFFER = .000625 # 1/4th of a city block in radius of Maryland coordinates.
#BUFFER = .00125 # 1/2 of a city block in radius of Maryland coordinates.

gLights_Buff2 = gLights2.assign(geometry = lambda x: x.geometry.buffer(BUFFER)) 
# Overwrites geometry variable with a buffer centered at the point of interest. A.k.a. applies the function geometry(x) to gNCR and saves it as geometry.

Matched_NLights = gpd.sjoin(gLights_Buff2, gNCR2, 'left')

Matched_NLights['Crime_LO_intime'] = [0]*len(Matched_NLights) # Counter to be used

Matched_NLights = Matched_NLights.dropna(subset = ['WoCompleted'])
Matched_NLights = Matched_NLights.dropna(subset = ['REPORT_DAT'])
Matched_NLights = Matched_NLights.reset_index(drop=True)

# Flagging possible lights that influenced crime:
def flag(z):
    bar = progressbar.ProgressBar(maxval=len(z), widgets=[progressbar.ETA(), ' ', progressbar.Percentage()])
    bar.start()
    for i in range(len(z)):