当前位置: 首页>>代码示例>>Python>>正文


Python Tree.plot方法代码示例

本文整理汇总了Python中treemap.models.Tree.plot方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.plot方法的具体用法?Python Tree.plot怎么用?Python Tree.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treemap.models.Tree的用法示例。


在下文中一共展示了Tree.plot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _commit_tree_data

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
    def _commit_tree_data(self, data, plot, tree, tree_edited):
        for tree_attr, field_name in TreeImportRow.TREE_MAP.iteritems():
            value = data.get(field_name, None)
            if value:
                tree_edited = True
                if tree is None:
                    tree = Tree(instance=plot.instance)
                setattr(tree, tree_attr, value)

        ie = self.import_event
        tree_udf_defs = udf_defs(ie.instance, 'Tree')
        for udf_def in tree_udf_defs:
            udf_column_name = ie.get_udf_column_name(udf_def)
            value = data.get(udf_column_name, None)
            # Legitimate values could be falsey
            if value is not None:
                tree_edited = True
                if tree is None:
                    tree = Tree(instance=plot.instance)
                tree.udfs[udf_def.name] = \
                    self._import_value_to_udf_value(udf_def, value)

        if tree_edited:
            tree.plot = plot
            tree.save_with_system_user_bypass_auth()
            tree.plot.update_updated_fields(ie.owner)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:28,代码来源:trees.py

示例2: add_tree_photo

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
def add_tree_photo(request, plot_id):
    uploaded_image = ContentFile(request.raw_post_data)
    uploaded_image.name = "plot_%s.png" % plot_id

    plot = Plot.objects.get(pk=plot_id)
    tree = plot.current_tree()

    if tree is None:
        import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
        tree = Tree(plot=plot, last_updated_by=request.user, import_event=import_event)
        tree.plot = plot
        tree.last_updated_by = request.user
        tree.save()

    treephoto = TreePhoto(tree=tree,title=uploaded_image.name,reported_by=request.user)
    treephoto.photo.save("plot_%s.png" % plot_id, uploaded_image)

    treephoto.save()

    return { "status": "success", "title": treephoto.title, "id": treephoto.pk }
开发者ID:alanhumphrey,项目名称:OpenTreeMap,代码行数:22,代码来源:views.py

示例3: update_plot_and_tree

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
def update_plot_and_tree(request, instance, plot_id):

    def set_attr_with_choice_correction(request, model, attr, value):
        if _attribute_requires_conversion(request, attr):
            conversions = settings.CHOICE_CONVERSIONS[attr]['forward']
            for (old, new) in conversions:
                if str(value) == str(old):
                    value = new
                    break
        setattr(model, attr, value)

    def get_attr_with_choice_correction(request, model, attr):
        value = getattr(model, attr)
        if _attribute_requires_conversion(request, attr):
            conversions = settings.CHOICE_CONVERSIONS[attr]['reverse']
            for (new, old) in conversions:
                if str(value) == str(new):
                    value = old
                    break
        return value

    response = HttpResponse()
    try:
        plot = Plot.objects.get(pk=plot_id)
    except Plot.DoesNotExist:
        response.status_code = 400
        response.content = json.dumps({
            "error": "No plot with id %s" % plot_id})
        return response

    request_dict = json_from_request(request)

    flatten_plot_dict_with_tree_and_geometry(request_dict)

    plot_field_whitelist = ['plot_width', 'plot_length', 'type',
                            'geocoded_address', 'edit_address_street',
                            'address_city', 'address_street', 'address_zip',
                            'power_lines', 'sidewalk_damage']

    # The Django form that creates new plots expects a 'plot_width'
    # parameter but the Plot model has a 'width' parameter so this
    # dict acts as a translator between request keys and model field names
    plot_field_property_name_dict = {
        'plot_width': 'width',
        'plot_length': 'length',
        'power_lines': 'powerline_conflict_potential'}

    plot_was_edited = False
    for plot_field_name in request_dict.keys():
        if plot_field_name in plot_field_whitelist:
            if plot_field_name in plot_field_property_name_dict:
                new_name = plot_field_property_name_dict[plot_field_name]
            else:
                new_name = plot_field_name
            new_value = request_dict[plot_field_name]
            if not compare_fields(get_attr_with_choice_correction(
                    request, plot, new_name), new_value):
                set_attr_with_choice_correction(
                    request, plot, new_name, new_value)
                plot_was_edited = True

    # TODO: Standardize on lon or lng
    if 'lat' in request_dict or 'lon' in request_dict or 'lng' in request_dict:
        new_geometry = Point(x=plot.geom.x, y=plot.geom.y)
        if 'lat' in request_dict:
            new_geometry.y = request_dict['lat']
        if 'lng' in request_dict:
            new_geometry.x = request_dict['lng']
        if 'lon' in request_dict:
            new_geometry.x = request_dict['lon']

        if plot.geom.x != new_geometry.x or plot.geom.y != new_geometry.y:
            plot.geom = new_geometry
            plot_was_edited = True

    if plot_was_edited:
        plot.save_with_user(request.user)

    tree_was_edited = False
    tree_was_added = False
    tree = plot.current_tree()
    tree_field_whitelist = ['species', 'diameter', 'height', 'canopy_height',
                            'canopy_condition', 'condition', 'pests']

    for tree_field in Tree._meta.fields:
        if ((tree_field.name in request_dict and
             tree_field.name in tree_field_whitelist)):
            if tree is None:
                tree = Tree(plot=plot, instance=instance)

                tree.plot = plot
                tree.last_updated_by = request.user
                tree.save_with_user(request.user)
                tree_was_added = True
            if tree_field.name == 'species':
                try:
                    if (((tree.species and
                          tree.species.pk != request_dict[tree_field.name])
                         or
                         (not tree.species
#.........这里部分代码省略.........
开发者ID:mmcfarland,项目名称:OTM2,代码行数:103,代码来源:views.py

示例4: commit_row

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
    def commit_row(self):
        # If this row was already commit... abort
        if self.plot:
            self.status = TreeImportRow.SUCCESS
            self.save()

        # First validate
        if not self.validate_row():
            return False

        # Get our data
        data = self.cleaned

        self.convert_units(data, {
            fields.trees.PLOT_WIDTH:
            self.import_event.plot_width_conversion_factor,

            fields.trees.PLOT_LENGTH:
            self.import_event.plot_length_conversion_factor,

            fields.trees.DIAMETER:
            self.import_event.diameter_conversion_factor,

            fields.trees.TREE_HEIGHT:
            self.import_event.tree_height_conversion_factor,

            fields.trees.CANOPY_HEIGHT:
            self.import_event.canopy_height_conversion_factor
        })

        # We need the import event from treemap.models
        # the names of things are a bit odd here but
        # self.import_event ->
        #   TreeImportEvent (importer) ->
        #     ImportEvent (treemap)
        #
        base_treemap_import_event = self.import_event.base_import_event

        plot_edited = False
        tree_edited = False

        # Initially grab plot from row if it exists
        plot = self.plot
        if plot is None:
            plot = Plot(present=True)

        # Event if TREE_PRESENT is None, a tree
        # can still be spawned here if there is
        # any tree data later
        tree = plot.current_tree()

        # Check for an existing tree:
        if self.model_fields.OPENTREEMAP_ID_NUMBER in data:
            plot = Plot.objects.get(
                pk=data[self.model_fields.OPENTREEMAP_ID_NUMBER])
            tree = plot.current_tree()
        else:
            if data.get(self.model_fields.TREE_PRESENT, False):
                tree_edited = True
                if tree is None:
                    tree = Tree(present=True)

        data_owner = self.import_event.owner

        for modelkey, importdatakey in TreeImportRow.PLOT_MAP.iteritems():
            importdata = data.get(importdatakey, None)

            if importdata:
                plot_edited = True
                setattr(plot, modelkey, importdata)

        if plot_edited:
            plot.last_updated_by = data_owner
            plot.import_event = base_treemap_import_event
            plot.save()

        for modelkey, importdatakey in TreeImportRow.TREE_MAP.iteritems():
            importdata = data.get(importdatakey, None)

            if importdata:
                tree_edited = True
                if tree is None:
                    tree = Tree(present=True)
                setattr(tree, modelkey, importdata)

        if tree_edited:
            tree.last_updated_by = data_owner
            tree.import_event = base_treemap_import_event
            tree.plot = plot
            tree.save()

        self.plot = plot
        self.status = TreeImportRow.SUCCESS
        self.save()

        return True
开发者ID:OpenTreeMap,项目名称:otm-legacy,代码行数:98,代码来源:models.py

示例5: handle_row

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok: return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok: return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]


        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok: return


        if row.get('ADDRESS') and not plot.address_street:
            plot.address_street = str(row['ADDRESS']).title()
            plot.geocoded_address = str(row['ADDRESS']).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = 'CA'
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get('PLOTTYPE'):
            for k, v in choices['plot_types']:
                if v == row['PLOTTYPE']:
                    plot.type = k
                    break;

        if row.get('PLOTLENGTH'):
            plot.length = row['PLOTLENGTH']

        if row.get('PLOTWIDTH'):
            plot.width = row['PLOTWIDTH']

        if row.get('ID'):
            plot.owner_orig_id = row['ID']

        if row.get('ORIGID'):
            plot.owner_additional_properties = "ORIGID=" + str(row['ORIGID'])

        if row.get('OWNER_ADDITIONAL_PROPERTIES'):
            plot.owner_additional_properties = str(plot.owner_additional_properties) + " " + str(row['OWNER_ADDITIONAL_PROPERTIES'])

        if row.get('OWNER_ADDITIONAL_ID'):
            plot.owner_additional_id = str(row['OWNER_ADDITIONAL_ID'])

        if row.get('POWERLINE'):
            for k, v in choices['powerlines']:
                if v == row['POWERLINE']:
                    plot.powerline_conflict_potential = k
                    break;

        sidewalk_damage = row.get('SIDEWALK')
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower() == "true" or sidewalk_damage.lower() == 'yes':
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)

#.........这里部分代码省略.........
开发者ID:OpenTreeMap,项目名称:otm-legacy,代码行数:103,代码来源:uimport.py

示例6: update_plot_and_tree

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
def update_plot_and_tree(request, plot_id):
    response = HttpResponse()
    try:
        plot = Plot.objects.get(pk=plot_id)
    except Plot.DoesNotExist:
        response.status_code = 400
        response.content = simplejson.dumps({"error": "No plot with id %s" % plot_id})
        return response

    request_dict = json_from_request(request)
    flatten_plot_dict_with_tree_and_geometry(request_dict)

    plot_field_whitelist = ['plot_width','plot_length','type','geocoded_address','edit_address_street', 'address_city', 'address_street', 'address_zip', 'power_lines', 'sidewalk_damage']

    # The Django form that creates new plots expects a 'plot_width' parameter but the
    # Plot model has a 'width' parameter so this dict acts as a translator between request
    # keys and model field names
    plot_field_property_name_dict = {'plot_width': 'width', 'plot_length': 'length', 'power_lines': 'powerline_conflict_potential'}

    # The 'auth.change_user' permission is a proxy for 'is the user a manager'
    user_is_not_a_manager = not request.user.has_perm('auth.change_user')
    should_create_plot_pends = settings.PENDING_ON and plot.was_created_by_a_manager and user_is_not_a_manager

    plot_was_edited = False
    for plot_field_name in request_dict.keys():
        if plot_field_name in plot_field_whitelist:
            if plot_field_name in plot_field_property_name_dict:
                new_name = plot_field_property_name_dict[plot_field_name]
            else:
                new_name = plot_field_name
            new_value = request_dict[plot_field_name]
            if not compare_fields(getattr(plot, new_name), new_value):
                if should_create_plot_pends:
                    plot_pend = PlotPending(plot=plot)
                    plot_pend.set_create_attributes(request.user, new_name, new_value)
                    plot_pend.save()
                else:
                    setattr(plot, new_name, new_value)
                    plot_was_edited = True

    # TODO: Standardize on lon or lng
    if 'lat' in request_dict or 'lon' in request_dict or 'lng' in request_dict:
        new_geometry = Point(x=plot.geometry.x, y=plot.geometry.y)
        if 'lat' in request_dict:
            new_geometry.y = request_dict['lat']
        if 'lng' in request_dict:
            new_geometry.x = request_dict['lng']
        if 'lon' in request_dict:
            new_geometry.x = request_dict['lon']

        if plot.geometry.x != new_geometry.x or plot.geometry.y != new_geometry.y:
            if should_create_plot_pends:
                plot_pend = PlotPending(plot=plot)
                plot_pend.set_create_attributes(request.user, 'geometry', new_geometry)
                plot_pend.save()
            else:
                plot.geometry = new_geometry
                plot_was_edited = True

    if plot_was_edited:
        plot.last_updated = datetime.datetime.now()
        plot.last_updated_by = request.user
        plot.save()
        change_reputation_for_user(request.user, 'edit plot', plot)

    tree_was_edited = False
    tree_was_added = False
    tree = plot.current_tree()
    tree_field_whitelist = ['species','dbh','height','canopy_height', 'canopy_condition', 'condition']

    if tree is None:
        should_create_tree_pends = False
    else:
        should_create_tree_pends = settings.PENDING_ON and tree.was_created_by_a_manager and user_is_not_a_manager

    for tree_field in Tree._meta.fields:
        if tree_field.name in request_dict and tree_field.name in tree_field_whitelist:
            if tree is None:
                import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
                tree = Tree(plot=plot, last_updated_by=request.user, import_event=import_event)
                tree.plot = plot
                tree.last_updated_by = request.user
                tree.save()
                tree_was_added = True
            if tree_field.name == 'species':
                try:
                    if (tree.species and tree.species.pk != request_dict[tree_field.name]) \
                    or (not tree.species and request_dict[tree_field.name]):
                        if should_create_tree_pends:
                            tree_pend = TreePending(tree=tree)
                            tree_pend.set_create_attributes(request.user, 'species_id', request_dict[tree_field.name])
                            tree_pend.save()
                        else:
                            tree.species = Species.objects.get(pk=request_dict[tree_field.name])
                            tree_was_edited = True
                except Exception:
                    response.status_code = 400
                    response.content = simplejson.dumps({"error": "No species with id %s" % request_dict[tree_field.name]})
                    return response
            else: # tree_field.name != 'species'
#.........这里部分代码省略.........
开发者ID:alanhumphrey,项目名称:OpenTreeMap,代码行数:103,代码来源:views.py

示例7: handle_row

# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import plot [as 别名]
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok:
            return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok:
            return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]

        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok:
            return

        if row.get("ADDRESS") and not plot.address_street:
            plot.address_street = str(row["ADDRESS"]).title()
            plot.geocoded_address = str(row["ADDRESS"]).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = "CA"
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get("PLOTTYPE"):
            for k, v in choices["plot_types"]:
                if v == row["PLOTTYPE"]:
                    plot.type = k
                    break

        if row.get("PLOTLENGTH"):
            plot.length = row["PLOTLENGTH"]

        if row.get("PLOTWIDTH"):
            plot.width = row["PLOTWIDTH"]

        if row.get("ID"):
            plot.owner_orig_id = row["ID"]

        if row.get("ORIGID"):
            plot.owner_additional_properties = "ORIGID=" + str(row["ORIGID"])

        if row.get("OWNER_ADDITIONAL_PROPERTIES"):
            plot.owner_additional_properties = (
                str(plot.owner_additional_properties) + " " + str(row["OWNER_ADDITIONAL_PROPERTIES"])
            )

        if row.get("OWNER_ADDITIONAL_ID"):
            plot.owner_additional_id = str(row["OWNER_ADDITIONAL_ID"])

        if row.get("POWERLINE"):
            for k, v in choices["powerlines"]:
                if v == row["POWERLINE"]:
                    plot.powerline = k
                    break

        sidewalk_damage = row.get("SIDEWALK")
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower() == "true" or sidewalk_damage.lower() == "yes":
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
#.........这里部分代码省略.........
开发者ID:rcheetham,项目名称:treemapindia.in,代码行数:103,代码来源:uimport.py


注:本文中的treemap.models.Tree.plot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。