Example #1
0
def encode_report(rpt, rpt_path):

    rpt_dict = {}

    #write parcel json files
    parcels = spatial.read_shapefile(sg.config.parcels_shapefile)
    parcels = parcels[['PARCELID', 'coords']]  #omit 'ADDRESS', 'OWNER1'
    flooded = rpt.alt_report.parcel_flooding  #proposed flooding condition
    flooded = pd.merge(flooded, parcels, right_on='PARCELID', left_index=True)
    rpt_dict['parcels'] = spatial.write_geojson(flooded, geomtype='polygon')

    #non null delta category parcels
    delta_parcels = rpt.flood_comparison.loc[pd.notnull(
        rpt.flood_comparison.Category)]
    delta_parcels = pd.merge(delta_parcels,
                             parcels,
                             right_on='PARCELID',
                             left_index=True)
    rpt_dict['delta_parcels'] = spatial.write_geojson(delta_parcels,
                                                      geomtype='polygon')

    #encode conduit and nodes data into geojson
    # rpt_dict['conduits'] = spatial.write_geojson(rpt.alt_report.model.conduits())
    rpt_dict['new_conduits'] = spatial.write_geojson(rpt.newconduits)
    # rpt_dict['nodes'] = spatial.write_geojson(rpt.model.nodes(), geomtype='point')

    #write summary stats
    rpt_dict.update(rpt.summary_dict)

    with open(rpt_path, 'w') as f:
        f.write(json.dumps(rpt_dict))
Example #2
0
def encode_report(rpt, rpt_path):

    rpt_dict = {}

    #write parcel json files
    parcels = spatial.read_shapefile(sg.config.parcels_shapefile)
    parcels = parcels[['PARCELID', 'coords']] #omit 'ADDRESS', 'OWNER1'
    flooded = rpt.alt_report.parcel_flooding #proposed flooding condition
    flooded = pd.merge(flooded, parcels, right_on='PARCELID', left_index=True)
    rpt_dict['parcels'] = spatial.write_geojson(flooded, geomtype='polygon')

    #non null delta category parcels
    delta_parcels = rpt.flood_comparison.loc[pd.notnull(rpt.flood_comparison.Category)]
    delta_parcels = pd.merge(delta_parcels, parcels, right_on='PARCELID', left_index=True)
    rpt_dict['delta_parcels'] = spatial.write_geojson(delta_parcels, geomtype='polygon')

    #encode conduit and nodes data into geojson
    # rpt_dict['conduits'] = spatial.write_geojson(rpt.alt_report.model.conduits())
    rpt_dict['new_conduits'] = spatial.write_geojson(rpt.newconduits)
    # rpt_dict['nodes'] = spatial.write_geojson(rpt.model.nodes(), geomtype='point')

    #write summary stats
    rpt_dict.update(rpt.summary_dict)

    with open(rpt_path, 'w') as f:
        f.write(json.dumps(rpt_dict))
Example #3
0
    def write(self, rpt_dir):
        #write cost per sewer segment spreadsheet
        self.newconduits.to_csv(os.path.join(rpt_dir,'cost_estimate.csv'))
        self.flood_comparison.to_csv(os.path.join(rpt_dir,'parcel_flood_comparison.csv'))

        #write parcel json files
        parcels = spatial.read_shapefile(sg.config.parcels_shapefile)
        parcels = parcels[['PARCELID', 'ADDRESS', 'OWNER1', 'coords']]
        flooded = self.flood_comparison
        flooded = flooded.loc[flooded.Category.notnull()] #parcels with significant flood delta
        flooded = pd.merge(flooded, parcels, right_on='PARCELID', left_index=True)
        colors = flooded.apply(lambda row:'#%02x%02x%02x' % drawing.parcel_draw_color(row, style='delta'), axis=1)
        flooded = flooded.assign(fill=colors)
        geoparcelpath = os.path.join(rpt_dir,'delta_parcels.json')
        spatial.write_geojson(flooded, filename=geoparcelpath, geomtype='polygon')

        #write new conduit json, shapefiles
        shpdir = os.path.join(os.path.dirname(rpt_dir), 'shapefiles')
        if not os.path.exists(shpdir):os.mkdir(shpdir)
        geocondpath = os.path.join(rpt_dir,'new_conduits.json')
        shpcondpath = os.path.join(shpdir, self.alt_report.model.inp.name + '_new_conduits.shp')
        spatial.write_geojson(self.newconduits, filename=geocondpath)
        spatial.write_shapefile(self.newconduits, filename=shpcondpath)

        #write node and conduit report csvs
        self.alt_report.model.nodes().to_csv(os.path.join(rpt_dir,'nodes.csv'))
        self.alt_report.model.conduits().to_csv(os.path.join(rpt_dir,'conduits.csv'))

        #write a html map
        with open (geocondpath, 'r') as f:
            geo_conduits = geojson.loads(f.read())


        proposed_flooded = self.alt_report.parcel_flooding
        proposed_flooded = pd.merge(proposed_flooded, parcels, right_on='PARCELID', left_index=True)
        geo_parcels = spatial.write_geojson(proposed_flooded)
        # with open (geoparcelpath, 'r') as f:
        #     geo_parcels = geojson.loads(f.read())

        with open(BETTER_BASEMAP_PATH, 'r') as bm:
            filename = os.path.join(os.path.dirname(geocondpath), self.alt_report.model.name + '.html')
            with open(filename, 'wb') as newmap:
                for line in bm:
                    if '//INSERT GEOJSON HERE ~~~~~' in line:
                        newmap.write('conduits = {};\n'.format(geojson.dumps(geo_conduits)))
                        newmap.write('nodes = {};\n'.format(0))
                        newmap.write('parcels = {};\n'.format(geojson.dumps(geo_parcels)))
                    else:
                        newmap.write(line)
Example #4
0
    def write(self, rpt_dir):
        #write cost per sewer segment spreadsheet
        self.newconduits.to_csv(os.path.join(rpt_dir,'cost_estimate.csv'))
        self.flood_comparison.to_csv(os.path.join(rpt_dir,'parcel_flood_comparison.csv'))

        #write parcel json files
        parcels = spatial.read_shapefile(sg.config.parcels_shapefile)
        parcels = parcels[['PARCELID', 'ADDRESS', 'OWNER1', 'coords']]
        flooded = self.flood_comparison
        flooded = flooded.loc[flooded.Category.notnull()] #parcels with significant flood delta
        flooded = pd.merge(flooded, parcels, right_on='PARCELID', left_index=True)
        colors = flooded.apply(lambda row:'#%02x%02x%02x' % drawing.parcel_draw_color(row, style='delta'), axis=1)
        flooded = flooded.assign(fill=colors)
        geoparcelpath = os.path.join(rpt_dir,'delta_parcels.json')
        spatial.write_geojson(flooded, filename=geoparcelpath, geomtype='polygon')

        #write new conduit json, shapefiles
        shpdir = os.path.join(os.path.dirname(rpt_dir), 'shapefiles')
        if not os.path.exists(shpdir):os.mkdir(shpdir)
        geocondpath = os.path.join(rpt_dir,'new_conduits.json')
        shpcondpath = os.path.join(shpdir, self.alt_report.model.inp.name + '_new_conduits.shp')
        spatial.write_geojson(self.newconduits, filename=geocondpath)
        spatial.write_shapefile(self.newconduits, filename=shpcondpath)

        #write node and conduit report csvs
        self.alt_report.model.nodes().to_csv(os.path.join(rpt_dir,'nodes.csv'))
        self.alt_report.model.conduits().to_csv(os.path.join(rpt_dir,'conduits.csv'))

        #write a html map
        with open (geocondpath, 'r') as f:
            geo_conduits = geojson.loads(f.read())


        proposed_flooded = self.alt_report.parcel_flooding
        proposed_flooded = pd.merge(proposed_flooded, parcels, right_on='PARCELID', left_index=True)
        geo_parcels = spatial.write_geojson(proposed_flooded)
        # with open (geoparcelpath, 'r') as f:
        #     geo_parcels = geojson.loads(f.read())

        with open(BETTER_BASEMAP_PATH, 'r') as bm:
            filename = os.path.join(os.path.dirname(geocondpath), self.alt_report.model.name + '.html')
            with open(filename, 'wb') as newmap:
                for line in bm:
                    if '//INSERT GEOJSON HERE ~~~~~' in line:
                        newmap.write('conduits = {};\n'.format(geojson.dumps(geo_conduits)))
                        newmap.write('nodes = {};\n'.format(0))
                        newmap.write('parcels = {};\n'.format(geojson.dumps(geo_parcels)))
                    else:
                        newmap.write(line)
Example #5
0
    def geojson(self):
        """
        Return a GeoJSON representation of the group

        :return: GeoJSON string
        """
        return write_geojson(self.dataframe, geomtype=self.geomtype)