Ejemplo n.º 1
0
def down_bos_wards(connection, load, message):
    """
    downloads the boston wards shape file 
    
    passes message dict to down_extract_zip function from downloading functions. 
    
    reads shape filepath and sends shape.
    -----------
    parameters :
        message: {url : , target_exenstion : , local_filename : } 
        
            url : a string passed to dlf.down_extract_zip, containing the url. if left empty, automatically passes
            
            default function dataset. 
            
            target_extension : desired filetype that needs to be extracted that is contained in the zip folder 
            
            (i.e. 'shp') 
            
            local_filename : A string. The desired filename you would like the file to be written to your directory as. 
            
    """
    down_shape_specs(message)
    import geopandas as gpd 
    import downloading_funcs as dlf 
    if 'url' not in message:
        message['url'] = 'http://bostonopendata-boston.opendata.arcgis.com/datasets/398ee443f4ac49e9a0b7facf80afc20f_8.zip'

    shape = dlf.down_extract_zip(message['url'], message['target_extension'], local_filename = message['local_filename'],)
    shape = gpd.read_file(shape)

    connection.send(shape)
Ejemplo n.º 2
0
def zoneConcentration(shp_gdf, raw, pntLst, bufr=None):
    from downloading_funcs import addr_shape, down_extract_zip
    import pandas as pd
    import geopandas as gpd

    pnt = pntLst[0]
    pnt_isCalled = pntLst[1]

    for url in pnt:
        if url[-3:] == 'zip':
            pnt = url
    assert isinstance(pnt, str)  #Must extract a zipfile from pnt!

    #Convenience assignment of projection type
    crs = 'EPSG:4326'

    #Extract and read points into memory
    pnt = down_extract_zip(pnt)
    ftr = gpd.read_file(pnt, crs=crs)

    #Flag properties within distance "bufr" of featured locations

    if not bufr:
        bufr = 1 / 250  #Hard to say what a good buffer is.

    assert isinstance(bufr, float)  #buffer must be float!

    #Frame up the buffer shapes
    ftr.geometry = ftr.geometry.buffer(bufr)
    ftr['flag'] = 1
    if 'NAME' in ftr:
        ftr.drop(['NAME'], axis=1, inplace=True)

    #Frame up the raw address points data
    pointy = raw[['NAME', 'Points', 'dummy_counter']]
    pointy = gpd.GeoDataFrame(pointy, crs=ftr.crs, geometry=pointy.Points)
    pointy = gpd.sjoin(pointy, ftr, how='left', op='intersects')

    denom = pointy.groupby('NAME').sum()
    denom = denom.dummy_counter

    numer = pointy.groupby('NAME').sum()
    numer = numer.flag

    pct_ftr_coverage = pd.DataFrame(numer / denom)

    pct_ftr_coverage.columns = [pnt_isCalled]

    pct_ftr_coverage.fillna(0, inplace=True)

    pct_ftr_coverage.crs = pointy.crs
    shp_gdf = shp_gdf.merge(pct_ftr_coverage,
                            how="left",
                            left_on='NAME',
                            right_index=True)
    del pct_ftr_coverage, raw, pointy, denom, numer
    return shp_gdf
    del shp_gdf
Ejemplo n.º 3
0
def pointInZone(shp_gdf, raw, zoneLst):
    from downloading_funcs import addr_shape, down_extract_zip
    import pandas as pd
    import geopandas as gpd

    zone = zoneLst[0]
    zone_isCalled = zoneLst[1]

    for url in zone:
        if url[-3:] == 'zip':
            zone = url
    assert isinstance(zone, str)  #Must extract a zipfile from pnt!

    #Convenience assignment of projection type
    crs = 'EPSG:4326'

    #Extract and read points into memory
    zone = down_extract_zip(zone)
    zone = gpd.read_file(zone, crs=crs)

    zone['flag'] = 1
    if 'NAME' in zone:
        zone.drop(['NAME'], axis=1, inplace=True)

    #Frame up the raw address points data
    pointy = raw[['NAME', 'Points', 'dummy_counter']]
    pointy = gpd.GeoDataFrame(pointy, crs=zone.crs, geometry=pointy.Points)
    pointy = gpd.sjoin(pointy, zone, how='left', op='intersects')

    numer = pointy.groupby('NAME').sum()
    numer = numer.flag

    inzone = pointy.groupby('NAME').sum()
    inzone = inzone.dummy_counter  #This was calling denom.dummy_counter which is undeclared

    flaginzone = pd.DataFrame(inzone)

    flaginzone.columns = [zone_isCalled]

    flaginzone.fillna(0, inplace=True)

    flaginzone.crs = pointy.crs
    shp_gdf = shp_gdf.merge(flaginzone,
                            how="left",
                            left_on='NAME',
                            right_index=True)
    del flaginzone, pointy, inzone, numer, raw
    return shp_gdf
    del shp_gdf
Ejemplo n.º 4
0
def metro_prox(shp_gdf, raw, bufr=None):
    #Flag properties within distance "bufr" of metro stations

    from downloading_funcs import addr_shape, down_extract_zip
    import pandas as pd
    import geopandas as gpd

    if not bufr:
        bufr = 1 / 250  #Hard to say what a good buffer is.

    assert isinstance(bufr, float)  #buffer must be float!

    #Frame up the metro buffer shapes
    metro = down_extract_zip(
        'https://opendata.arcgis.com/datasets/54018b7f06b943f2af278bbe415df1de_52.zip'
    )
    metro = gpd.read_file(metro, crs=shp_gdf.crs)
    metro.geometry = metro.geometry.buffer(bufr)
    metro['bymet'] = 1
    metro.drop(['NAME'], axis=1, inplace=True)

    #Frame up the raw address points data
    pointy = raw[['NAME', 'Points', 'dummy_counter']]
    pointy = gpd.GeoDataFrame(pointy, crs=metro.crs, geometry=pointy.Points)
    pointy = gpd.sjoin(pointy, metro, how='left', op='intersects')

    denom = pointy.groupby('NAME').sum()
    denom = denom.dummy_counter

    numer = pointy.groupby('NAME').sum()
    numer = numer.bymet

    pct_metro_coverage = pd.DataFrame(numer / denom)

    pct_metro_coverage.columns = ['pct_metro_coverage']

    pct_metro_coverage.fillna(0, inplace=True)

    pct_metro_coverage.crs = pointy.crs
    shp_gdf = shp_gdf.merge(pct_metro_coverage,
                            how="left",
                            left_on='NAME',
                            right_index=True)
    return shp_gdf
Ejemplo n.º 5
0
def down_la_census_council(
        connection, load,
        message):  #city council districts joined with census tracts 2010
    """
    downloads the la city council and census polygons shape file  
    
    passes message dict to down_extract_zip function from downloading functions. 
    
    reads shape filepath and sends shape.
    -----------
    parameters :
        message: {url : , target_exenstion : , local_filename : } 
        
            url : a string passed to dlf.down_extract_zip, containing the url. if left empty, automatically passes
            
            default function dataset. 
            
            target_extension : desired filetype that needs to be extracted that is contained in the zip folder 
            
            (i.e. 'shp') 
            
            local_filename : A string. The desired filename you would like the file to be written to your directory as. 
            
    """
    down_shape_specs(message)
    import geopandas as gpd
    import downloading_funcs as dlf
    if 'url' not in message:
        message[
            'url'] = 'http://geohub.lacity.org/datasets/3d41239eaa564ca699b17dbefd5d2981_0.zip'

    shape = dlf.down_extract_zip(
        message['url'],
        message['target_extension'],
        local_filename=message['local_filename'],
    )
    shape = gpd.read_file(shape)

    connection.send(shape)
Ejemplo n.º 6
0
def down_dc_anc(connection, load, message):
    """
    downloads the dc anc shape file 
    
    passes message dict to down_extract_zip function from downloading functions. 
    
    reads shape filepath and sends shape.
    -----------
    parameters :
        message: {url : , target_exenstion : , local_filename : } 
        
            url : a string passed to dlf.down_extract_zip, containing the url. if left empty, automatically passes
            
            default function dataset. 
            
            target_extension : desired filetype that needs to be extracted that is contained in the zip folder 
            
            (i.e. 'shp') 
            
            local_filename : A string. The desired filename you would like the file to be written to your directory as. 
            
    """
    down_shape_specs(message)
    import geopandas as gpd
    import downloading_funcs as dlf
    if 'url' not in message:
        message[
            'url'] = 'https://opendata.arcgis.com/datasets/fcfbf29074e549d8aff9b9c708179291_1.zip'

    shape = dlf.down_extract_zip(
        message['url'],
        message['target_extension'],
        local_filename=message['local_filename'],
    )
    shape = gpd.read_file(shape)

    connection.send(shape)
Ejemplo n.º 7
0
def down_la_congress(connection, load, message):  #congressional districts
    """
    downloads the la congressional districts shape file  
    
    passes message dict to down_extract_zip function from downloading functions. 
    
    reads shape filepath and sends shape.
    -----------
    parameters :
        message: {url : , target_exenstion : , local_filename : } 
        
            url : a string passed to dlf.down_extract_zip, containing the url. if left empty, automatically passes
            
            default function dataset. 
            
            target_extension : desired filetype that needs to be extracted that is contained in the zip folder 
            
            (i.e. 'shp') 
            
            local_filename : A string. The desired filename you would like the file to be written to your directory as. 
            
    """
    down_shape_specs(message)
    import geopandas as gpd
    import downloading_funcs as dlf
    if 'url' not in message:
        message[
            'url'] = 'http://geohub.lacity.org/datasets/ab63122b097641d28d70ef434ebdf852_10'

    shape = dlf.down_extract_zip(
        message['url'],
        message['target_extension'],
        local_filename=message['local_filename'],
    )
    shape = gpd.read_file(shape)

    connection.send(shape)
Ejemplo n.º 8
0
def down_sf_zipcodes(connection, load, message):
    """
    downloads the sf zipcodes shape file  
    
    passes message dict to down_extract_zip function from downloading functions. 
    
    reads shape filepath and sends shape.
    -----------
    parameters :
        message: {url : , target_exenstion : , local_filename : } 
        
            url : a string passed to dlf.down_extract_zip, containing the url. if left empty, automatically passes
            
            default function dataset. 
            
            target_extension : desired filetype that needs to be extracted that is contained in the zip folder 
            
            (i.e. 'shp') 
            
            local_filename : A string. The desired filename you would like the file to be written to your directory as.   
    """

    down_shape_specs(message)
    import geopandas as gpd
    import downloading_funcs as dlf
    if 'url' not in message:
        message[
            'url'] = 'https://data.sfgov.org/api/geospatial/u5j3-svi6?method=export&format=Shapefile'

    shape = dlf.down_extract_zip(
        message['url'],
        message['target_extension'],
        local_filename=message['local_filename'],
    )
    shape = gpd.read_file(shape)

    connection.send(shape)