Esempio n. 1
0
    def create_feature_line_fill_symbol(i_symbol):
        """ This collects all properties of a line fill symbol and returns a dictionary of them

        :param i_symbol: the symbol to investigate
        :return: symbol_properties as dictionary
        """
        fill_dict = copy.deepcopy(SingleSymbol.propDict)
        symbol_properties = {
            'simpleSymbolClass': "LinePatternFill",
            'dict_symbols': fill_dict,
        }

        symbol_properties['dict_symbols']['angle'] = i_symbol.Angle
        layer_color = convert_int_to_rgb_string(i_symbol.LineSymbol.Color.RGB)
        symbol_properties['dict_symbols']['color'] = layer_color
        symbol_properties['dict_symbols']['offset'] = i_symbol.Offset
        symbol_properties['dict_symbols']['distance'] = str(i_symbol.Separation)

        symbol_properties['dict_symbols']['outline_color'] = convert_int_to_rgb_string(i_symbol.Outline.Color.RGB)
        symbol_properties['dict_symbols']['outline_width'] = i_symbol.Outline.Width

        SubSymbolProvider.create_sub_symbol(symbol_properties, 'line')

        from renderer.feature.symbols.symbolPropertiesProvider import SymbolPropertiesProvider
        SymbolPropertiesProvider.get_line_properties(
            symbol_properties['subSymbol'],
            i_symbol.LineSymbol
        )

        return symbol_properties
Esempio n. 2
0
    def create_line_element_content(self, line_element_layout):
        """
        This function creats the Line-item specific content
        :param line_element_layout: the layout element in the DOM
        """
        arcpy_item = LayoutItem.get_arcpy_layout_element(self, self.line_object)
        LineElement.set_size_and_position(self, line_element_layout, arcpy_item)

        element_geometry = change_interface(self.line_object, ArcGisModules.module_carto.IElement).Geometry
        poly_ine_symbol = change_interface(element_geometry, ArcGisModules.module_geometry.IPolyline5)
        point_collection = change_interface(poly_ine_symbol, ArcGisModules.module_geometry.IPointCollection)

        line_element_layout.setAttribute('type', '65645')
        line_element_layout.setAttribute("frame", "false")
        line_element_layout.setAttribute("background", "false")

        LineElement.set_uuid_attributes(arcpy_item.name, line_element_layout)

        symbol = self.line_object.Symbol
        symbol_properties = {}

        SymbolPropertiesProvider.get_line_properties(symbol_properties, symbol)

        SimpleSymbol.create_simple_symbol(self.dom, line_element_layout, symbol_properties, 1, '1')

        LineElement.create_nodes(self, line_element_layout, point_collection, arcpy_item)
Esempio n. 3
0
    def create_geometry_element_content(self, geometry_element_layout,
                                        geometry_type):
        """
        This function creates the geometry specific content
        :param geometry_element_layout: the geometry layout element in the DOM
        :param geometry_type: the shape type as string
        """

        arcpy_item = LayoutItem.get_arcpy_layout_element(
            self, self.layout_item_object)

        GeometryElement.set_size_and_position(self, geometry_element_layout,
                                              arcpy_item)

        geometry_element_layout.setAttribute("frame", "false")
        geometry_element_layout.setAttribute("background", "false")

        geometry_element_layout.setAttribute('shapeType',
                                             dict_geometry[geometry_type])
        geometry_element_layout.setAttribute('type', "65643")

        GeometryElement.set_uuid_attributes(arcpy_item.name,
                                            geometry_element_layout)

        symbol = change_interface(
            self.geometry_object,
            ArcGisModules.module_carto.IFillShapeElement).Symbol
        symbol_properties = {}

        SymbolPropertiesProvider.get_polygon_properties(
            symbol_properties, symbol)

        SimpleSymbol.create_simple_symbol(self.dom, geometry_element_layout,
                                          symbol_properties, 1, '1')
    def create_feature_marker_fill_symbol(i_symbol):
        """ This collects all properties of a marker fill symbol and returns a dictionary of them

        :param i_symbol: the symbol to investigate
        :return: symbol_properties as dictionary
        """
        fill_dict = copy.deepcopy(SingleSymbol.propDict)
        symbol_properties = {
            'simpleSymbolClass': "RandomMarkerFill",
            'dict_symbols': fill_dict,
        }
        layer_color = convert_int_to_rgb_string(
            i_symbol.MarkerSymbol.Color.RGB)
        symbol_properties['dict_symbols']['color'] = layer_color
        symbol_properties['dict_symbols']['clip_points'] = '1'
        symbol_properties['dict_symbols']['count_method'] = '1'
        symbol_properties['dict_symbols']['density_area'] = '250'
        symbol_properties['dict_symbols']['density_area_unit'] = 'MM'
        symbol_properties['dict_symbols'][
            'density_area_scale'] = '3x:0,0,0,0,0,0'
        symbol_properties['dict_symbols']['point_count'] = '10'
        symbol_properties['dict_symbols']['seed'] = '48648189'

        SubSymbolProvider.create_sub_symbol(symbol_properties, 'marker')

        from renderer.feature.symbols.symbolPropertiesProvider import SymbolPropertiesProvider
        SymbolPropertiesProvider.get_point_properties(
            symbol_properties['subSymbol'], i_symbol.MarkerSymbol)

        return symbol_properties
Esempio n. 5
0
    def create_symbol_marker_line(symbol_marker_line, symbol_properties):
        """ This collects all properties of a marker-line symbol and writes it in the symbol properties

        :param symbol_marker_line: the marker-line symbol
        :param symbol_properties: the belonging properties dictionary
        """
        symbol_properties['simpleSymbolClass'] = "MarkerLine"
        SubSymbolProvider.create_sub_symbol(symbol_properties, 'marker')

        SymbolPropertiesProvider.get_point_properties(
            symbol_properties['subSymbol'], symbol_marker_line.MarkerSymbol)
Esempio n. 6
0
    def create_hash_line(symbol_hash_line, symbol_properties):
        """ This collects all properties of a hash-line symbol and writes it in the symbol properties

        :param symbol_hash_line: the hash symbol
        :param symbol_properties: the belonging properties dictionary
        """
        symbol_properties['simpleSymbolClass'] = "HashLine"
        hash_angle = symbol_hash_line.Angle + 90
        if hash_angle > 360:
            hash_angle = hash_angle - 360
        symbol_properties['dict_symbols']['hash_angle'] = str(hash_angle * -1)
        symbol_properties['dict_symbols']['hash_length'] = str(
            symbol_hash_line.Width)
        symbol_properties['dict_symbols']['hash_length_unit'] = "Point"
        SubSymbolProvider.create_sub_symbol(symbol_properties, 'line')

        SymbolPropertiesProvider.get_line_properties(
            symbol_properties['subSymbol'], symbol_hash_line.HashSymbol)
Esempio n. 7
0
    def create_feature_marker_fill_symbol(i_symbol):
        """ This collects all properties of a marker fill symbol and returns a dictionary of them

        :param i_symbol: the symbol to investigate
        :return: symbol_properties as dictionary
        """
        fill_dict = copy.deepcopy(SingleSymbol.propDict)
        symbol_properties = {
            'simpleSymbolClass': "PointPatternFill",
            'dict_symbols': fill_dict,
        }
        layer_color = convert_int_to_rgb_string(
            i_symbol.MarkerSymbol.Color.RGB)
        symbol_properties['dict_symbols']['color'] = layer_color

        fill_properties = change_interface(
            i_symbol, ArcGisModules.module_display.IFillProperties)

        symbol_properties['dict_symbols']['offset_x'] = str(
            fill_properties.XOffset)
        symbol_properties['dict_symbols']['offset_y'] = str(
            fill_properties.YOffset)
        symbol_properties['dict_symbols']['offset_x_unit'] = "Pixel"
        symbol_properties['dict_symbols']['offset_y_unit'] = "Pixel"

        symbol_properties['dict_symbols']['distance_x'] = str(
            fill_properties.XSeparation)
        symbol_properties['dict_symbols']['distance_y'] = str(
            fill_properties.YSeparation)
        symbol_properties['dict_symbols']['distance_x_unit'] = "Pixel"
        symbol_properties['dict_symbols']['distance_y_unit'] = "Pixel"

        symbol_properties['dict_symbols']['outline_color'] = str(
            convert_int_to_rgb_string(i_symbol.Outline.Color.RGB))
        symbol_properties['dict_symbols']['outline_width'] = str(
            i_symbol.Outline.Width)

        SubSymbolProvider.create_sub_symbol(symbol_properties, 'marker')

        from renderer.feature.symbols.symbolPropertiesProvider import SymbolPropertiesProvider
        SymbolPropertiesProvider.get_point_properties(
            symbol_properties['subSymbol'], i_symbol.MarkerSymbol)

        return symbol_properties
Esempio n. 8
0
    def create_symbols(self, style_gallery, style_gallery_name,
                       class_to_export):
        """ This creates the symbols out of a style-gallery

        :param style_gallery: the main style gallery
        :param style_gallery_name: the gallery to read from
        :param class_to_export: The name of the class to export
        """

        try:
            symbols_element = self.xml_document.getElementsByTagName(
                "symbols")[0]
        except IndexError:
            symbols_element = self.xml_document.createElement("symbols")
        root_element = self.xml_document.getElementsByTagName("qgis_style")[0]
        root_element.appendChild(symbols_element)

        style_gallery_items = StyleGalleryItemProvider.get_style_gallery_items(
            style_gallery, class_to_export, style_gallery_name)
        if len(style_gallery_items) > 0:
            arcpy.AddMessage("Export {}".format(class_to_export))
        for item in style_gallery_items:
            try:
                i_symbol = change_interface(
                    item.Item, ArcGisModules.module_display.ISymbol)

                symbol_properties = {}
                SymbolPropertiesProvider.get_symbol_properties_by_symbol_class(
                    symbol_properties, i_symbol, class_to_export)
                tags = change_interface(item, ArcGisModules.module_display.IStyleGalleryItem2)\
                    .Tags\
                    .replace(";", " ,")

                SimpleSymbol.create_simple_symbol(self.xml_document,
                                                  symbols_element,
                                                  symbol_properties, item.Name,
                                                  "1", tags)
            except (ValueError, Exception):
                arcpy.AddMessage("Error while Exporting {}".format(item.name))
                continue
Esempio n. 9
0
    def create_scale_bar_content(self, layout_item_base_element):
        """
        This function creats the ScaleBar-item specific content
        :param layout_item_base_element: the layout element in the DOM
        """

        border = self.scale_bar_object.Border
        background = self.scale_bar_object.Background

        ScaleBarElement.create_background_and_frame(self, border, background,
                                                    layout_item_base_element)

        arcpy_item = LayoutItem.get_arcpy_layout_element(
            self, self.layout_item_object)
        ScaleBarElement.set_size_and_position(self, layout_item_base_element,
                                              arcpy_item)

        scale_bar = change_interface(self.scale_bar_object.MapSurround,
                                     ArcGisModules.module_carto.IScaleBar)
        scale_marks = change_interface(self.scale_bar_object.MapSurround,
                                       ArcGisModules.module_carto.IScaleMarks)

        layout_item_base_element.setAttribute('unitType',
                                              dict_units[scale_bar.Units])
        layout_item_base_element.setAttribute('unitLabel', scale_bar.UnitLabel)

        ScaleBarElement.set_uuid_attributes(
            self.layout_item_object.MapSurround.Name, layout_item_base_element)

        try:
            layout_item_base_element.setAttribute(
                'mapUuid',
                unicode(LayoutUuidProvider.uuid_dict[
                    self.layout_item_object.MapSurround.Map.Name]))
        except KeyError:
            LayoutUuidProvider.create_uuid(
                self.layout_item_object.MapSurround.Map.Name)
            layout_item_base_element.setAttribute(
                'mapUuid',
                unicode(LayoutUuidProvider.uuid_dict[
                    self.layout_item_object.MapSurround.Map.Name]))

        layout_item_base_element.setAttribute('type', "65646")
        layout_item_base_element.setAttribute(
            'numSegments',
            unicode(scale_bar.Divisions - scale_bar.DivisionsBeforeZero))
        if scale_bar.DivisionsBeforeZero > 0:
            layout_item_base_element.setAttribute(
                'numSegmentsLeft', unicode(scale_bar.Subdivisions))
        else:
            layout_item_base_element.setAttribute('numSegmentsLeft', '0')
        layout_item_base_element.setAttribute('numUnitsPerSegment',
                                              unicode(scale_bar.Division))
        layout_item_base_element.setAttribute(
            'labelVerticalPlacement',
            dict_vertical_position[scale_bar.LabelPosition])
        layout_item_base_element.setAttribute('labelBarSpace',
                                              unicode(scale_bar.LabelGap))
        if str(scale_bar.Name).startswith('Double'):
            layout_item_base_element.setAttribute('style', "Double Box")
        else:
            layout_item_base_element.setAttribute('style', "Single Box")

        scale_line = change_interface(scale_bar,
                                      ArcGisModules.module_carto.IScaleLine)
        if scale_line:
            num_segments = unicode(
                (scale_bar.Divisions - scale_bar.DivisionsBeforeZero) *
                scale_bar.Subdivisions
            ) if scale_bar.Subdivisions > 0 else unicode(
                scale_bar.Divisions - scale_bar.DivisionsBeforeZero)
            layout_item_base_element.setAttribute('numSegments', num_segments)
            num_units_per_segment = unicode(scale_bar.Division / scale_bar.Subdivisions) \
                if not scale_bar.Subdivisions == 0 else unicode(scale_bar.Division)
            layout_item_base_element.setAttribute(
                'numUnitsPerSegment', unicode(num_units_per_segment))
            layout_item_base_element.setAttribute(
                'style', dict_line_style[scale_marks.MarkPosition])

        double_fill_scale_bar = change_interface(
            scale_bar, ArcGisModules.module_carto.IDoubleFillScaleBar)

        if double_fill_scale_bar:
            fill_color_1 = convert_int_to_rgb_string(
                double_fill_scale_bar.FillSymbol1.Color.RGB).split(",")
            fill_color_2 = convert_int_to_rgb_string(
                double_fill_scale_bar.FillSymbol2.Color.RGB).split(",")
            if double_fill_scale_bar.FillSymbol1.Color.NullColor and double_fill_scale_bar.FillSymbol2.Color.NullColor:
                layout_item_base_element.setAttribute('style', 'hollow')

            symbol_properties_1 = {}
            fill_symbol_1_element = self.dom.createElement('fillSymbol1')
            SymbolPropertiesProvider.get_polygon_properties(
                symbol_properties_1, double_fill_scale_bar.FillSymbol1)
            SimpleSymbol.create_simple_symbol(self.dom, fill_symbol_1_element,
                                              symbol_properties_1, '', '1')
            layout_item_base_element.appendChild(fill_symbol_1_element)

            symbol_properties_2 = {}
            fill_symbol_2_element = self.dom.createElement('fillSymbol2')
            SymbolPropertiesProvider.get_polygon_properties(
                symbol_properties_2, double_fill_scale_bar.FillSymbol2)
            SimpleSymbol.create_simple_symbol(self.dom, fill_symbol_2_element,
                                              symbol_properties_2, '', '1')
            layout_item_base_element.appendChild(fill_symbol_2_element)
        else:
            fill_color_1 = convert_int_to_rgb_string(
                scale_bar.BarColor.RGB).split(',')
            fill_color_2 = "255,255,255,255"

        fill_color_1_element = self.dom.createElement('fillColor')
        fill_color_1_element.setAttribute('red', fill_color_1[0])
        fill_color_1_element.setAttribute('green', fill_color_1[1])
        fill_color_1_element.setAttribute('blue', fill_color_1[2])
        fill_color_1_element.setAttribute('alpha', fill_color_1[3])
        layout_item_base_element.appendChild(fill_color_1_element)

        fill_color_2_element = self.dom.createElement('fillColor2')
        fill_color_2_element.setAttribute('red', fill_color_2[0])
        fill_color_2_element.setAttribute('green', fill_color_2[1])
        fill_color_2_element.setAttribute('blue', fill_color_2[2])
        fill_color_2_element.setAttribute('alpha', fill_color_2[3])
        layout_item_base_element.appendChild(fill_color_2_element)
Esempio n. 10
0
    def create_feature_renderer(base):
        """This creates the feature-renderer-element in the DOM

        :param base: is the self of the renderer object containing:
            base.xml_document = xml_document
            base.map_layer_element = map_layer_element
            base.arcLayer = arc_layer
            base.layer = layer
            base.rendererType = renderer_type
        """
        renderer = base.xml_document.createElement("renderer-v2")
        renderer.setAttribute("forceraster", "0")
        renderer.setAttribute("enableorderby", "0")
        renderer.setAttribute("symbollevels", "0")
        base.map_layer_element.appendChild(renderer)

        symbols_element = base.xml_document.createElement("symbols")
        renderer.appendChild(symbols_element)

        symbols = []

        arc_feature_layer = change_interface(
            base.arcLayer, ArcGisModules.module_carto.IFeatureLayer)
        arc_geo_feature_layer = change_interface(
            arc_feature_layer, ArcGisModules.module_carto.IGeoFeatureLayer)
        simple_renderer = arc_geo_feature_layer.Renderer
        unique_value_renderer = change_interface(
            simple_renderer, ArcGisModules.module_carto.IUniqueValueRenderer)

        # get a feature, mostly 0 , but can be higher, if using objects from a db -> than takes the id
        feature = None
        try:
            for i in range(0, 1000):
                try:
                    feature = arc_feature_layer.FeatureClass.GetFeature(i)
                    break
                except COMError:
                    i += 1
        except AttributeError:
            arcpy.AddWarning("\t\tFinding a Feature to render failed.")
            print "Something went wrong. Are you using a DB where the IDs start at 1001?"
            pass

        if base.layer.symbologyType == "OTHER" and not unique_value_renderer:
            renderer.setAttribute("type", "singleSymbol")
            symbols.append(simple_renderer.SymbolByFeature(feature))

        elif base.layer.symbologyType == "UNIQUE_VALUES" or unique_value_renderer:
            UniqueValueRenderer.create_unique_values_element(
                base, renderer, symbols)

        elif base.layer.symbologyType == "GRADUATED_COLORS" or "GRADUATED_SYMBOLS":
            GraduatedColorsRenderer.create_graduated_colors_element(
                base, renderer, symbols)

        try:
            arc_feature_layer = change_interface(
                base.arcLayer, ArcGisModules.module_carto.IFeatureLayer)
            layer_effects = change_interface(
                arc_feature_layer, ArcGisModules.module_carto.ILayerEffects)
            alpha = str(1 - layer_effects.Transparency * 0.01)
        except AttributeError:
            alpha = "1"

        # create the symbol element, one for single symbol, more for graduated or unique values
        for count, iSymbol in enumerate(symbols):
            symbol_properties = {}
            if arc_geo_feature_layer.DisplayFeatureClass.ShapeType == 4:
                SymbolPropertiesProvider.get_polygon_properties(
                    symbol_properties, iSymbol)

            elif arc_geo_feature_layer.DisplayFeatureClass.ShapeType == 3:
                SymbolPropertiesProvider.get_line_properties(
                    symbol_properties, iSymbol)

            elif (arc_geo_feature_layer.DisplayFeatureClass.ShapeType == 2) | \
                    (arc_geo_feature_layer.DisplayFeatureClass.ShapeType == 1):
                SymbolPropertiesProvider.get_point_properties(
                    symbol_properties, iSymbol)

            SimpleSymbol.create_simple_symbol(base.xml_document,
                                              symbols_element,
                                              symbol_properties, count, alpha)