def tracks_map_gen(cls, records): """Render the tracks map""" Tracks = Pool().get('forest.track') CadPlot = Pool().get('cadastre.parcelle') Plot = Pool().get('forest.plot') for record in records: cad_plots = [plot.geom for plot in record.cad_plots] cad_plots, envelope, cad_area = get_as_epsg4326(cad_plots) plots = [plot.geom for plot in record.plots] plots, plot_bbox, _plots_area = get_as_epsg4326(plots) tracks = [track.geom for track in record.tracks] tracks, _tracks_bbox, _tracks_area = get_as_epsg4326(tracks) if envelope is None: continue # Compute the envelope if plot_bbox is not None: envelope = envelope_union(envelope, plot_bbox) # Map title title = u'Carte de la desserte\n' title += u'Propriétaire: %s\n' % record.owner.name if record.address is not None \ and record.address.city is not None \ and record.address.my_city is not None: city = record.address.city dep = record.address.my_city.subdivision.parent.code.split('-')[1] title += u'Commune: %s (%s)\n' % (city, dep) title += u'Surface: %02i ha %02i a %02i ca\n\nLe ' % cls._area_to_a(cad_area) title += date.today().strftime('%02d/%02m/%Y') # Cadastral plots m = MapRender(1024, 768, envelope, True) for plot, rec in zip(cad_plots, record.cad_plots): m.plot_geom(plot, None, None, color=CadPlot.COLOR) cls._plot_misc_areas(m, record) # Forest plots for plot, rec in zip(plots, record.plots): m.plot_geom(plot, rec.short_name, u'Parcelle forestière', linestyle='--', color=Plot.COLOR, bgcolor=Plot.BGCOLOR) # Track plots # Legend Track #gris colgris = (0, 0, 0, 0.3) #rouge colred = (1, 0, 0, 1) #jaune colyel = (1, 1, 0, 1) #blanc colwhi = (0, 0, 0, 1) m.add_legend(str('Piste'), '-', color=colwhi, bgstyle='-', bgcolor=colwhi) m.add_legend(str('Route en terrain naturel'), '-', color=colyel, bgstyle='-', bgcolor=colyel) m.add_legend(str('Route empierrée'), '-', color=colred, bgstyle='-', bgcolor=colred) m.add_legend(str('Route goudronnée'), '-', color=colgris, bgstyle='-', bgcolor=colgris) # Track for track, rec in zip(tracks, record.tracks): if rec.typo == 'rgou': m.plot_geom(track, rec.name, None, color=colgris, bgcolor=colgris) elif rec.typo == 'remp': m.plot_geom(track, rec.name, None, color=colred, bgcolor=colred) elif rec.typo == 'rternat': m.plot_geom(track, rec.name, None, color=colyel, bgcolor=colyel) else: m.plot_geom(track, rec.name, None, color=colwhi, bgcolor=colwhi) cls._plot_misc_points(m, record) m.plot_legend() m.plot_compass() m.plot_scaling() cls._plot_logo(m) m.plot_title(title) data = m.render() cls.write([record], {'tracks_map': buffer(data)})
def varieties_map_gen(cls, records): """Render the varieties map""" Varieties = Pool().get('forest.variety') CadPlot = Pool().get('cadastre.parcelle') Plot = Pool().get('forest.plot') for record in records: cad_plots = [plot.geom for plot in record.cad_plots] cad_plots, envelope, cad_area = get_as_epsg4326(cad_plots) plots = [plot.geom for plot in record.plots] plots, plot_bbox, _plots_area = get_as_epsg4326(plots) varieties = [variety.geom for variety in record.varieties] varieties, _varieties_bbox, _varieties_area = get_as_epsg4326(varieties) if envelope is None: continue # Compute the envelope if plot_bbox is not None: envelope = envelope_union(envelope, plot_bbox) # Map title title = u'Carte des peuplements\n' title += u'Propriétaire: %s\n' % record.owner.name if record.address is not None \ and record.address.city is not None \ and record.address.my_city is not None: city = record.address.city dep = record.address.my_city.subdivision.parent.code.split('-')[1] title += u'Commune: %s (%s)\n' % (city, dep) title += u'Surface: %02i ha %02i a %02i ca\n\nLe ' % cls._area_to_a(cad_area) title += date.today().strftime('%02d/%02m/%Y') # Cadastral plots m = MapRender(1024, 768, envelope, True) for plot, rec in zip(cad_plots, record.cad_plots): m.plot_geom(plot, None, None, color=CadPlot.COLOR) cls._plot_misc_areas(m, record) # Stand plots # Legend Stand for stand, rec in zip(varieties, record.varieties): if rec.stand is None: bgcolor = (0, 0, 0, 0) else: r = float(rec.stand.r)/float(255) g = float(rec.stand.g)/float(255) b = float(rec.stand.b)/float(255) bgcolor = (r, g, b, 1) m.add_legend(rec.stand.name, '-', color=(0, 0, 0, 1), bgstyle='-', bgcolor=bgcolor) # Stand for stand, rec in zip(varieties, record.varieties): if rec.stand is None: bgcolor = (0, 0, 0, 0) else: r = float(rec.stand.r)/float(255) g = float(rec.stand.g)/float(255) b = float(rec.stand.b)/float(255) bgcolor = (r, g, b, 1) m.plot_geom(stand, None, None, color=(0, 0, 0, 1), bgcolor=bgcolor) # Legend Dom Species 1 for stand, rec in zip(varieties, record.varieties): if rec.domspecies1 is None: bgcolor = (0, 0, 0, 0) else: r = float(rec.domspecies1.r)/float(255) g = float(rec.domspecies1.g)/float(255) b = float(rec.domspecies1.b)/float(255) bgcolor = (r, g, b, 1) m.add_legend(rec.domspecies1.name, '-', color=(0, 0, 0, 1), bgstyle = None, bgcolor=bgcolor) # Dom Species 1 for stand, rec in zip(varieties, record.varieties): if rec.domspecies1 is None: bgcolor = (0, 0, 0, 0) bgstyle = '.' else: r = float(rec.domspecies1.r)/float(255) g = float(rec.domspecies1.g)/float(255) b = float(rec.domspecies1.b)/float(255) bgcolor = (r, g, b, 1) bgstyle = rec.domspecies1.form m.plot_geom(stand, None, None, color=(0, 0, 0, 1), bgstyle=bgstyle, bgcolor=bgcolor) # Forest plots for plot, rec in zip(plots, record.plots): m.plot_geom(plot, rec.short_name, u'Parcelle forestière', linestyle='--', color=Plot.COLOR, bgcolor=Plot.BGCOLOR) cls._plot_misc_points(m, record) m.plot_legend() m.plot_compass() m.plot_scaling() cls._plot_logo(m) m.plot_title(title) data = m.render() cls.write([record], {'varieties_map': buffer(data)})