Example #1
0
    touching_parks = list(
        filter(lambda p: loose_zip_bounds.intersects(shape(p['geometry'])),
               parks.shapefile()))

    # Update the geometry in the shapefile
    zip_area['geometry'] = mapping(loose_zip_bounds)
    # Write our variables
    zip_area['properties']['PARKCOUNT'] = len(touching_parks)
    zip_area['properties']['PARKNAMES'] = ', '.join(
        [p['properties']['TEXT_'] for p in touching_parks])

# Write out our final file
project.save_layer(name='nearby-park-counts',
                   using_data=wanted_zips,
                   variables={
                       'ZCTA5CE10': {
                           'type': 'str',
                           'from_data': 'ZCTA5CE10'
                       },
                       'PARKCOUNT': {
                           'type': 'int',
                           'from_data': 'PARKCOUNT'
                       },
                       'PARKNAMES': {
                           'type': 'str',
                           'from_data': 'PARKNAMES'
                       },
                   })

project.save_csv(name='zip_parks', using_data=wanted_zips)
Example #2
0
    print("Checking " + str(zip_area['properties']['CODE']))
    # TODO: Compact multiple into a single file? Can I?
    # raw_data = project.clipRaster(name='cover-for-' + zip_area['properties']['CODE'], raster=tree_cover.image(), bounds=zip_area)
    raw_data = project.clipRaster(raster=tree_cover.image(), bounds=zip_area)
    pixels_tree_covered = len(raw_data[raw_data == TREE_COVER_INDEX])
    area = zip_area['properties']['Shape__Are']
    zip_area['properties']['TREE_PERCENT'] = (
        (pixels_tree_covered * 1) / area) * 100
    zip_area['properties']['TREE_COUNT'] = pixels_tree_covered
    print(zip_area['properties'])

# TODO: Need to merge polys in disjoint files
project.save_layer(name='coverage-percents',
                   using_data=wanted_zips,
                   variables={
                       'ZIPCODE': {
                           'type': 'str',
                           'from_data': 'CODE'
                       },
                       'TREE_PERCENT': {
                           'type': 'float',
                           'from_data': 'TREE_PERCENT'
                       },
                       'TREE_COUNT': {
                           'type': 'float',
                           'from_data': 'TREE_COUNT'
                       },
                   })

project.save_csv(name='coverage-percents', using_data=wanted_zips)