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


Python QgsWkbTypes.isSingleType方法代码示例

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


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

示例1: load_complex_gml

# 需要导入模块: from qgis.core import QgsWkbTypes [as 别名]
# 或者: from qgis.core.QgsWkbTypes import isSingleType [as 别名]
    def load_complex_gml(self, xml_uri, is_remote, attributes = {}, geometry_mapping = None, logger = None, swap_xy = False):
        """
        :param xml_uri: the XML URI
        :param is_remote: True if it has to be fetched by http
        :param attributes: { 'attr1' : ( '//xpath/expression', QVariant.Int ) }
        :param geometry_mapping: XPath expression to a gml geometry node
        :param swap_xy: True if X/Y coordinates must be swapped
        :returns: the created layer
        """
        try:
            if is_remote:
                xml_src = remote_open_from_qgis(xml_uri)
            else:
                # Open the file in binary mode, this means returning bytes
                # instead of a string whose encoding would have to be interpreted
                # it is up to the XML parser to determine which encoding it is
                xml_src = open(xml_uri, 'rb')
            src = ComplexFeatureSource(xml_src, attributes, geometry_mapping, logger)

            attr_list = [ (k, v[1]) for k, v in attributes.items() ]

            layers = {}
            features = {}
            layer_geom_type = {}
            for id, fid, qgsgeoms, xml, attrs in src.getFeatures(swap_xy):
                # layer creation
                if qgsgeoms == []:
                    if "" not in layers:
                        layer = self._create_layer('none', None, attr_list, src.title, "nogeom")
                        self._add_properties_to_layer(layer, xml_uri, is_remote, attributes, geometry_mapping)
                        layers["nogeom"] = layer
                else:
                    for (qgsgeom, srid), tag in qgsgeoms:
                        if tag in layers:
                            continue
                        type2d = QgsWkbTypes.flatType(qgsgeom.wkbType())
                        typemap = {QgsWkbTypes.Point: 'point',
                                   QgsWkbTypes.MultiPoint: 'multipoint',
                                   QgsWkbTypes.LineString: 'linestring',
                                   QgsWkbTypes.MultiLineString: 'multilinestring',
                                   QgsWkbTypes.Polygon: 'polygon',
                                   QgsWkbTypes.MultiPolygon: 'multipolygon',
                                   QgsWkbTypes.CompoundCurve: 'compoundcurve',
                                   QgsWkbTypes.CircularString: 'compoundcurve',
                                   QgsWkbTypes.MultiCurve: 'multicurve',
                                   QgsWkbTypes.CurvePolygon: 'curvepolygon',
                                   QgsWkbTypes.MultiSurface: 'multisurface'}
                        if qgsgeom and type2d in typemap:
                            title = "{} ({})".format(src.title, no_prefix(tag))
                            layer = self._create_layer(typemap[QgsWkbTypes.multiType(type2d)], srid, attr_list, title, no_prefix(tag))
                        else:
                            raise RuntimeError("Unsupported geometry type {}".format(qgsgeom.wkbType()))
                        self._add_properties_to_layer(layer, xml_uri, is_remote, attributes, geometry_mapping)                        
                        layers[tag] = layer

                # collect features
                f = QgsFeature(layer.dataProvider().fields(), id)
                f.setAttribute("id", str(id))
                f.setAttribute("fid", fid)
                for k, v in attrs.items():
                    r = f.setAttribute(k, v)
                for g, tag in qgsgeoms:
                    if tag not in features:
                        features[tag] = []
                    fcopy = QgsFeature(f)
                    fcopy.setAttribute("_xml_", ET.tostring(xml).decode('utf8'))
                    if g:
                        qgsgeom, _ = g
                        if QgsWkbTypes.isMultiType(layers[tag].wkbType()) and QgsWkbTypes.isSingleType(qgsgeom.wkbType()):
                            # force multi
                            qgsgeom.convertToMultiType()
                        fcopy.setGeometry(qgsgeom)
                    features[tag].append(fcopy)

            # write features
            for tag, f in features.items():
                if len(f) > 0:
                    layer = layers[tag]
                    layer.startEditing()
                    layer.addFeatures(f)
                    layer.commitChanges()
        finally:
            xml_src.close()

        # Set the styl for polygons coming from boundedBy
        for tag_name, layer in layers.items():
            if tag_name.endswith("boundedBy"):
                layer.loadNamedStyle(os.path.join(os.path.dirname(__file__), "..", "gui", "bounded_by_style.qml"))
        return layers
开发者ID:Oslandia,项目名称:gml_application_schema_toolbox,代码行数:91,代码来源:load_gml_as_xml.py


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