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


Python WebFeatureService.getOperationByName方法代码示例

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


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

示例1: HandleWFS

# 需要导入模块: from owslib.wfs import WebFeatureService [as 别名]
# 或者: from owslib.wfs.WebFeatureService import getOperationByName [as 别名]
class HandleWFS():

    def __init__(self, url, version="1.0.0"):
        self.wfs = WebFeatureService(url, version=version)
        self.type = self.wfs.identification.type
        self.version = self.wfs.identification.version
        self.title = self.wfs.identification.title
        self.abstract = self.wfs.identification.abstract

    def do_layer_check(self, data_dict):
        layer_list = list(self.wfs.contents)
        resource = data_dict.get("resource", {})
        this_layer = resource.get("layer")
        try:
            first_layer = layer_list[0]
            if this_layer in layer_list:
                return this_layer
            elif this_layer.lower() in layer_list:
                return this_layer.lower()
            else:
                return first_layer
        except Exception:
            pass

    def build_url(self, typename=None, method='{http://www.opengis.net/wfs}Get',
                  operation='{http://www.opengis.net/wfs}GetFeature', maxFeatures=None):
        service_url = self.wfs.getOperationByName(operation).methods[method]['url']
        request = {'service': 'WFS', 'version': self.version}
        try:
            assert len(typename) > 0
            request['typename'] = ','.join([typename])
        except Exception:
            request['typename'] = ','.join('ERROR_HERE')
            pass

        if maxFeatures: request['maxfeatures'] = str(maxFeatures)

        encoded_request = "&".join("%s=%s" % (key,value) for (key,value) in request.items())
        url = service_url + "&" + encoded_request
        return url

    def make_geojson(self, data_dict):
        geojson = []
        type_name = self.do_layer_check(data_dict)
        wfs_url = self.build_url(type_name, maxFeatures=100)
        source = ogr.Open(wfs_url)
        layer = source.GetLayerByIndex(0)
        for feature in layer:
            geojson.append(feature.ExportToJson(as_object=True))
        return geojson

    def make_recline_json(self, data_dict):
        recline_json = []
        geojson = self.make_geojson(data_dict)
        for i in geojson:
            properties = i['properties']
            properties.update(dict(geometry=i['geometry']))
            recline_json.append(properties)
        return recline_json
开发者ID:okfn,项目名称:ckanext-ngds,代码行数:61,代码来源:OGCServices.py

示例2: print

# 需要导入模块: from owslib.wfs import WebFeatureService [as 别名]
# 或者: from owslib.wfs.WebFeatureService import getOperationByName [as 别名]
    
    print("\n\tProvider: ", dir(wfs.provider))
    print(wfs.provider.name)
    print(wfs.provider.url)
    print(wfs.provider.contact.email)
    print(wfs.provider.contact.phone)
    print(wfs.provider.contact.name)
    print(wfs.provider.contact.organization)
    print(wfs.provider.contact.city)
    print(wfs.provider.contact.region)
    print(wfs.provider.contact.postcode)
    print(wfs.provider.contact.country)

    print("\n\tOperations: ", [op.name for op in wfs.operations])
    
    op_describe = wfs.getOperationByName('DescribeFeatureType')
    help(op_describe)

    get_cap = wfs.getOperationByName('GetCapabilities')
    # help(get_cap)
    
    print(wfs.getGETGetFeatureRequest())

    get_feat = wfs.getOperationByName('GetFeature')
    # help(get_feat)
    

    for layer in list(wfs.contents):
        try:
            print(u'Layer: %s, Features: %s, SR: %s...' % (wfs[layer].title, wfs[layer].abstract, wfs[layer].crsOptions))
            print(wfs[layer].boundingBox)
开发者ID:bobo-romania,项目名称:DicoGIS,代码行数:33,代码来源:test_GDAL_WFS.py

示例3: HandleWFS

# 需要导入模块: from owslib.wfs import WebFeatureService [as 别名]
# 或者: from owslib.wfs.WebFeatureService import getOperationByName [as 别名]
class HandleWFS():
    """
    Processor for WFS resources.  Requires a getCapabilities URL for the WFS and a WFS version passed in as a string.
    Default version is '1.1.0'; other supported versions are '1.0.0' and '2.0.0'
    """

    def __init__(self, url, version="1.1.0"):
        self.wfs = WebFeatureService(url, version=version)
        self.type = self.wfs.identification.type
        self.version = self.wfs.identification.version
        self.title = self.wfs.identification.title
        self.abstract = self.wfs.identification.abstract

    # Return a specific service URL, getFeature is default
    def get_service_url(self, operation='{http://www.opengis.net/wfs}GetFeature', method='{http://www.opengis.net/wfs}Get'):
        if self.version == "1.1.0":
            operation = "GetFeature"
            method = "Get"

        return self.wfs.getOperationByName(operation).methods[method]['url']

    # Pass in a dictionary with the layer name bound to 'layer'.  If the 'layer' is not found, then just return the
    # first layer in the list of available layers
    def do_layer_check(self, data_dict):
        layer_list = list(self.wfs.contents)
        resource = data_dict.get("resource", {})
        this_layer = resource.get("layer")
        try:
            first_layer = layer_list[0]
            if this_layer in layer_list:
                return this_layer
            elif this_layer.lower() in layer_list:
                return this_layer.lower()
            else:
                return first_layer
        except Exception:
            pass

    # Build a URL for accessing service data, getFeature is default
    def build_url(self, typename=None, method='{http://www.opengis.net/wfs}Get', operation='{http://www.opengis.net/wfs}GetFeature', maxFeatures=None):

        if self.version == "1.1.0":
            operation = "GetFeature"
            method = "Get"

        service_url = self.wfs.getOperationByName(operation).methods[method]['url']
        request = {
            'service': 'WFS',
            'version': self.version
        }

        if self.version == "1.1.0":
            request = {
                'service': 'WFS',
                'version': self.version,
                'request': 'GetFeature'
            }

        try:
            assert len(typename) > 0
            request['typename'] = ','.join([typename])
        except Exception:
            request['typename'] = ','.join('ERROR_HERE')
            pass

        if maxFeatures:
            request['maxfeatures'] = str(maxFeatures)

        encoded_request = "&".join("%s=%s" % (key, value) for (key, value) in request.items())
        url = service_url + "&" + encoded_request

        if self.version == "1.1.0":
            url = service_url + "?" + encoded_request

        return url

    # Take a data_dict, use information to build a getFeature URL and get features as GML.  Then take that GML response
    # and turn it into GeoJSON.
    def make_geojson(self, data_dict):
        geojson = []
        type_name = self.do_layer_check(data_dict)
        wfs_url = self.build_url(type_name, maxFeatures=100)
        source = ogr.Open(wfs_url)
        layer = source.GetLayerByIndex(0)
        for feature in layer:
            geojson.append(feature.ExportToJson(as_object=True))
        return geojson

    # Recline.js doesn't support the GeoJSON specification and instead just wants it's own flavor of spatial-json.  So,
    # give this method the same data_dict you would give the 'make_geojson' method and we'll take the GeoJSON and turn
    # it into Recline JSON.
    def make_recline_json(self, data_dict):
        recline_json = []
        geojson = self.make_geojson(data_dict)
        for i in geojson:
            properties = i['properties']
            properties.update(dict(geometry=i['geometry']))
            recline_json.append(properties)
        return recline_json
开发者ID:GeoinformationSystems,项目名称:ckanext-geoserver,代码行数:101,代码来源:ProcessOGC.py

示例4: build_wfs_url

# 需要导入模块: from owslib.wfs import WebFeatureService [as 别名]
# 或者: from owslib.wfs.WebFeatureService import getOperationByName [as 别名]

#.........这里部分代码省略.........
            if "DescribeFeatureType" not in [op.name for op in wfs.operations]:
                self.cached_wfs["DescribeFeatureType"] = 0
                return 0, "Required DescribeFeatureType operation not available in: " + wfs_url_getcap
            else:
                self.cached_wfs["DescribeFeatureType"] = 1
                logger.info("DescribeFeatureType available")
                pass

            # check if required layer is present
            try:
                wfs_lyr = wfs[layer_name]
            except KeyError as e:
                logger.error("Layer {} not found in WFS service: {}"
                             .format(layer_name,
                                     wfs_url_getcap))
                if geoserver and layer_name in [l.split(":")[1] for l in list(wfs.contents)]:
                    layer_name = list(wfs.contents)[[l.split(":")[1]
                                                    for l in list(wfs.contents)].index(layer_name)]
                    try:
                        wfs_lyr = wfs[layer_name]
                    except KeyError as e:
                        return (0,
                                "Layer {} not found in WFS service: {}"
                                .format(layer_name,
                                        wfs_url_getcap),
                                e)

            # SRS definition
            srs_map = plg_tools.get_map_crs()
            srs_lyr_new = qsettings.value("/Projections/defaultBehaviour")
            srs_lyr_crs = qsettings.value("/Projections/layerDefaultCrs")
            srs_qgs_new = qsettings.value("/Projections/projectDefaultCrs")
            srs_qgs_otf_on = qsettings.value("/Projections/otfTransformEnabled")
            srs_qgs_otf_auto = qsettings.value("/Projections/otfTransformAutoEnable")

            # DEV
            # print("CRS: ", wms_lyr.crsOptions,
            #       "For new layers: " + srs_lyr_new + srs_lyr_crs,
            #       "For new projects: " + srs_qgs_new,
            #       "OTF enabled: " + srs_qgs_otf_on,
            #       "OTF smart enabled: " + srs_qgs_otf_auto,
            #       "Map canvas SRS:" + plg_tools.get_map_crs())

            wfs_lyr_crs_epsg = ["{}:{}".format(srs.authority, srs.code)
                                for srs in wfs_lyr.crsOptions]
            self.cached_wfs["CRS"] = wfs_lyr_crs_epsg
            if srs_map in wfs_lyr_crs_epsg:
                logger.debug("It's a SRS match! With map canvas: " + srs_map)
                srs = srs_map
            elif srs_qgs_new in wfs_lyr_crs_epsg\
                 and srs_qgs_otf_on == "false"\
                 and srs_qgs_otf_auto == "false":
                logger.debug("It's a SRS match! With default new project: " + srs_qgs_new)
                srs = srs_qgs_new
            elif srs_lyr_crs in wfs_lyr_crs_epsg and srs_lyr_new == "useGlobal":
                logger.debug("It's a SRS match! With default new layer: " + srs_lyr_crs)
                srs = srs_lyr_crs
            elif "EPSG:4326" in wfs_lyr_crs_epsg:
                logger.debug("It's a SRS match! With standard WGS 84 (EPSG:4326)")
                srs = "EPSG:4326"
            else:
                logger.debug("Map Canvas SRS not available within service CRS.")
                srs = wfs_lyr_crs_epsg[0]

            # Style definition
            # print("Styles: ", wms_lyr.styles, type(wms_lyr.styles))
            # lyr_style = wfs_lyr.styles.keys()[0]
            # print(lyr_style)

            # GetFeature URL
            wfs_lyr_url = wfs.getOperationByName('GetFeature').methods
            wfs_lyr_url = wfs_lyr_url[0].get("url")
            if wfs_lyr_url[-1] != "&":
                wfs_lyr_url = wfs_lyr_url + "&"
            else:
                pass
            self.cached_wfs["url"] = wfs_lyr_url

            # url construction
            try:
                wfs_url_params = {"SERVICE": "WFS",
                                  "VERSION": "1.0.0",
                                  "TYPENAME": layer_name,
                                  "SRSNAME": srs,
                                  }
                wfs_url_final = wfs_lyr_url + unquote(urlencode(wfs_url_params, "utf8"))
            except UnicodeEncodeError:
                wfs_url_params = {"SERVICE": "WFS",
                                  "VERSION": "1.0.0",
                                  "TYPENAME": layer_name.decode("latin1"),
                                  "SRSNAME": srs,
                                  }
                wfs_url_final = wfs_lyr_url + unquote(urlencode(wfs_url_params))
            # method ending
            logger.debug(wfs_url_final)
            # logger.debug(uri)
            return ["WFS", layer_title, wfs_url_final]
            # return ["WFS", layer_title, uri.uri()]
        else:
            return None
开发者ID:isogeo,项目名称:isogeo-plugin-qgis,代码行数:104,代码来源:url_builder.py


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