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


Python wfs.WebFeatureService类代码示例

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


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

示例1: test_ows_interfaces_wfs

def test_ows_interfaces_wfs():
    wfsxml = open(resource_file('mapserver-wfs-cap.xml'), 'rb').read()
    service = WebFeatureService('url', version='1.0', xml=wfsxml)
    # Check each service instance conforms to OWSLib interface
    service.alias = 'CSW'
    isinstance(service, owslib.feature.wfs100.WebFeatureService_1_0_0)
    # URL attribute
    assert service.url == 'url'
    # version attribute
    assert service.version == '1.0'
    # Identification object
    assert hasattr(service, 'identification')
    # Check all ServiceIdentification attributes
    assert service.identification.type == 'MapServer WFS'
    for attribute in ['type', 'version', 'title', 'abstract', 'keywords', 'accessconstraints', 'fees']:
        assert hasattr(service.identification, attribute)
    # Check all ServiceProvider attributes
    for attribute in ['name', 'url']:
        assert hasattr(service.provider, attribute)
    # Check all operations implement IOperationMetadata
    for op in service.operations:
        for attribute in ['name', 'formatOptions', 'methods']:
            assert hasattr(op, attribute)
    # Check all contents implement IContentMetadata as a dictionary
    isinstance(service.contents, dict)
    # Check any item (WCS coverage, WMS layer etc) from the contents of each service
    # Check it conforms to IContentMetadata interface
    # get random item from contents dictionary -has to be a nicer way to do this!
    content = service.contents[list(service.contents.keys())[0]]
    for attribute in ['id', 'title', 'boundingBox', 'boundingBoxWGS84', 'crsOptions', 'styles', 'timepositions']:
        assert hasattr(content, attribute)
开发者ID:PublicaMundi,项目名称:OWSLib,代码行数:31,代码来源:test_ows_interfaces.py

示例2: getAttributes

def getAttributes(shapefile, WFS_URL):
    """
    Given a valid shapefile(WFS Featuretype as returned by getShapefiles), this function will 
    make a request for one feature from the featureType and parse out the attributes that come from
    a namespace not associated with the normal GML schema. There may be a better way to determine 
    which are shapefile dbf attributes, but this should work pretty well.
    """
    wfs = WebFeatureService(WFS_URL, version='1.1.0')
    feature = wfs.getfeature(typename=shapefile, maxfeatures=1, propertyname=None)
    gml = etree.parse(feature)
    gml_root=gml.getroot()
    name_spaces = gml_root.nsmap
    
    attributes = []
    
    for namespace in name_spaces.values():
        if namespace not in ['http://www.opengis.net/wfs',
                             'http://www.w3.org/2001/XMLSchema-instance',
                             'http://www.w3.org/1999/xlink',
                             'http://www.opengis.net/gml',
                             'http://www.opengis.net/ogc',
                             'http://www.opengis.net/ows']:
            custom_namespace = namespace
            
            for element in gml.iter('{'+custom_namespace+'}*'):
                if etree.QName(element).localname not in ['the_geom', 'Shape', shapefile.split(':')[1]]:
                    attributes.append(etree.QName(element).localname)
    return attributes
开发者ID:ColinTalbert,项目名称:pyGDP,代码行数:28,代码来源:shapefile_value_handle.py

示例3: getWFSData

def getWFSData():
   from owslib.wfs import WebFeatureService   
   import string
   
   params = getWFSParams() # Get parameters     
   params = checkParams(params) # Check parameters
   
   wfs = WebFeatureService(params['baseURL'].value, version=params['version'].value)
   response = wfs.getfeature(typename=str(params['typeName'].value), featureid=[params['featureID'].value]) # Contact server
   
   if string.find(params['baseURL'].value, 'bodc', 0): 
      response = processBODCResponse(response.read(), params) # Get data from response
   else:
      pass
   
   current_app.logger.debug('Jsonifying response...') # DEBUG
   
   # Convert to json
   try:
      jsonData = jsonify(output = response)
   except TypeError as e:
      g.error = "Request aborted, exception encountered: %s" % e
      error_handler.setError('2-06', None, g.user.id, "views/wfs.py:getWFSData - Type error, returning 500 to user. Exception %s" % e, request)
      abort(500) # If we fail to jsonify the data return 500
      
   current_app.logger.debug('Request complete, Sending results') # DEBUG
   
   return jsonData # return json
开发者ID:OPEC-PML,项目名称:GISportal,代码行数:28,代码来源:wfs.py

示例4: test_wfs3_ldproxy

def test_wfs3_ldproxy():
    w = WebFeatureService(SERVICE_URL, version='3.0')

    assert w.url == 'https://www.ldproxy.nrw.de/rest/services/kataster/'
    assert w.version == '3.0'
    assert w.url_query_string == 'f=json'

    conformance = w.conformance()
    assert len(conformance['conformsTo']) == 5
开发者ID:PublicaMundi,项目名称:OWSLib,代码行数:9,代码来源:test_wfs3_ldproxy.py

示例5: getValues

def getValues(shapefile, attribute, getTuples, limitFeatures, wfs_url):
    """
    Similar to get attributes, given a shapefile and a valid attribute this function
    will make a call to the Web Feature Services returning a list of values associated
    with the shapefile and attribute.

    If getTuples = True, will also return the tuples of [feature:id]  along with values [feature]
    """

    wfs = WebFeatureService(wfs_url, version='1.1.0')

    feature = wfs.getfeature(typename=shapefile, maxfeatures=limitFeatures, propertyname=[attribute])
    content = BytesIO(feature.read().encode())
    gml = etree.parse(content)

    values = []

    for el in gml.iter():
        if attribute in el.tag:
            if el.text not in values:
                values.append(el.text)

    if getTuples == 'true' or getTuples == 'only':
        tuples = []
        att = False

        # If features are encoded as a list of featureMember elements.
        gmlid_found = False
        for featureMember in gml.iter('{' + GML_NAMESPACE + '}featureMember'):
            for el in featureMember.iter():
                if el.get('{' + GML_NAMESPACE + '}id'):
                    gmlid = el.get('{' + GML_NAMESPACE + '}id')
                    att = True
                    gmlid_found = True
                if attribute in el.tag and att is True:
                    value = el.text
                    tuples.append((value, gmlid))
                    att = False
            if not gmlid_found:
                raise Exception('No gml:id found in source feature service. This form of GML is not supported.')

        # If features are encoded as a featureMembers element.
        for featureMember in gml.iter('{' + GML_NAMESPACE + '}featureMembers'):
            for el in featureMember.iter():
                gmlid = el.get('{' + GML_NAMESPACE + '}id')
                for feat in el.getchildren():
                    if attribute in feat.tag:
                        value = feat.text
                        tuples.append((value, gmlid))

    if getTuples == 'true':
        return sorted(values), sorted(tuples)
    elif getTuples == 'only':
        return sorted(tuples)
    else:
        return sorted(values)
开发者ID:USGS-CIDA,项目名称:pyGDP,代码行数:56,代码来源:shapefile_value_handle.py

示例6: runTest

 def runTest(self):
     minX = -76.766960
     minY = 39.283611
     maxX = -76.684120
     maxY = 39.338394
     
     filter = "<Filter><BBOX><PropertyName>Geometry</PropertyName> <Box srsName='EPSG:4326'><coordinates>%f,%f %f,%f</coordinates> </Box></BBOX></Filter>" % (minX, minY, maxX, maxY)
     wfs = WebFeatureService('http://SDMDataAccess.nrcs.usda.gov/Spatial/SDMWGS84Geographic.wfs', version='1.0.0')
     response = wfs.getfeature(typename=('MapunitPolyExtended',), filter=filter, propertyname=None)
     self.assertTrue(response.read().find('<wfs:FeatureCollection') > 0,
                     'Unable to find feature dataset in WFS response')
开发者ID:CowanSM,项目名称:owslib,代码行数:11,代码来源:test_wfs_USDASSURGO.py

示例7: getValues

def getValues(shapefile, attribute, getTuples, limitFeatures, WFS_URL):
    """
    Similar to get attributes, given a shapefile and a valid attribute this function
    will make a call to the Web Feature Services returning a list of values associated
    with the shapefile and attribute.
    
    If getTuples = True, will also return the tuples of [feature:id]  along with values [feature]
    """

    wfs = WebFeatureService(WFS_URL, version="1.1.0")

    feature = wfs.getfeature(typename=shapefile, maxfeatures=limitFeatures, propertyname=[attribute])

    gml = etree.parse(feature)

    values = []

    for el in gml.iter():
        if attribute in el.tag:
            if el.text not in values:
                values.append(el.text)

    if getTuples == "true" or getTuples == "only":
        tuples = []
        # If features are encoded as a list of featureMember elements.
        gmlid_found = False
        for featureMember in gml.iter("{" + GML_NAMESPACE + "}featureMember"):
            for el in featureMember.iter():
                if el.get("{" + GML_NAMESPACE + "}id"):
                    gmlid = el.get("{" + GML_NAMESPACE + "}id")
                    att = True
                    gmlid_found = True
                if attribute in el.tag and att == True:
                    value = el.text
                    tuples.append((value, gmlid))
                    att = False
            if gmlid_found == False:
                raise Exception("No gml:id found in source feature service. This form of GML is not supported.")
        # If features are encoded as a featureMembers element.
        for featureMember in gml.iter("{" + GML_NAMESPACE + "}featureMembers"):
            for el in featureMember.iter():
                gmlid = el.get("{" + GML_NAMESPACE + "}id")
                for feat in el.getchildren():
                    if attribute in feat.tag:
                        value = feat.text
                        tuples.append((value, gmlid))

    if getTuples == "true":
        return sorted(values), sorted(tuples)
    elif getTuples == "only":
        return sorted(tuples)
    else:
        return sorted(values)
开发者ID:ayan-usgs,项目名称:pyGDP,代码行数:53,代码来源:shapefile_value_handle.py

示例8: getODRL

def getODRL(serviceURL):
    wfs = WebFeatureService(serviceURL)
    wfs.getcapabilities()    

    candidateURLs = re.findall(r'(https?://[^\s]+)', wfs.identification.accessconstraints)
    for url in candidateURLs:        
        response = urllib2.urlopen(url)
        response_text = response.read()
        if is_valid_protocol(response_text):
            return response_text
    # If we are here, there is not any valid ODRL XML in any of the URLs in Access Constraints
    return None
开发者ID:IAAA-Lab,项目名称:odrl-ogc-cache-policies,代码行数:12,代码来源:ODRL_Paper.py

示例9: webgisfilter

def webgisfilter(mapserv, layer, maxfeatures=None, startindex=None, bbox=None,
        filters=None):
    """webgis wfs client

    Each filter format should look like:

    {
        'attribute': ATTRIBUTE_NAME, # e.g. 'NAME'
        'operator': OPERATOR, # e.g. '='
        'value': VALUE # e.g. 'Prague'
    }

    Operators: = != ~ IN

    :param str mapserv: url to mapserver
    :param str layer: layer name
    :param int maxfeatures: number of returned features
    :param int startindex: starting feature index
    :param Tupple.<dict> filters: tupple of filters
    :return: json-encoded result
    :rtype: dict
    """

    mywfs = WebFeatureService(url=mapserv, version='1.0.0')
    fes = None
    if filters:
        if bbox:
            filters.append({ 'operator':'BBOX', 'value': bbox})
        fes = get_filter_root(get_filter_fes(filters))
        fes = etree.tostring(fes)

    if bbox and not filters:
        fes = None
    elif not bbox and filters:
        bbox = None
    elif bbox and filters:
        bbox = None

    layer_data = mywfs.getfeature(typename=[layer],
                                  filter=fes,
                                  bbox=bbox,
                                  featureid=None,
                                  outputFormat="GeoJSON",
                                  maxfeatures=maxfeatures,
                                  startindex=startindex)
    data = json.load(layer_data)

    for feature in data['features']:
        feature.pop('geometry')

    return data
开发者ID:bstroebl,项目名称:gislab-web,代码行数:51,代码来源:wfsfilter.py

示例10: GetWFSLayer

def GetWFSLayer(u, p):
  start = time.time()
  # Separate the WFS URL & the layer name
  split_url = u.split('?')
  server_url = split_url[0]
  ows = server_url[-3:]
  print 'The OGC standard is: '+ ows
  
  spacename_wfs = split_url[1]
  tmp_chemin = p + spacename_wfs+"_.zip"
  chemin = tmp_chemin[:-5]+".zip"
  
  if not os.path.exists(chemin):
    # Get the vector layer using OGC WFS standard
    wfs = WebFeatureService(server_url ,version='1.0.0')
    getFeature = wfs.getfeature(typename = [spacename_wfs], outputFormat ="shape-zip") 
    
    print('Downloading... : '+ spacename_wfs)
    print("From: "+ server_url)
    
    # Download the zipped shapefile
    data = getFeature.read()
    f = open(tmp_chemin ,'wb')
    f.write(data)
    f.close()
    
    # Delete .txt & .cst files from the zipped file
    zin = zipp(tmp_chemin, 'r')
#    zin.extractall(p)
    zout = zipp(chemin, 'w')
    for item in zin.infolist():
      buffer = zin.read(item.filename)
      ext = item.filename[-4:]
      if (ext != '.txt' and ext != '.cst'):
          zout.writestr(item, buffer)
          
    zout.close()
    zin.close()
    os.remove(tmp_chemin)
    
#    # Unzip zipped shapefile
    os.system("unzip "+ chemin + ' -d '+ p)
  
  # Calculat time
  temps =time.time() - start
  tps = round(temps,2)
  temps_ms = str(tps)
  
  print "GetWFSLayer download time : " + temps_ms +" ms"
  
  return
开发者ID:BVService,项目名称:bvservice-wps,代码行数:51,代码来源:GetWFSLayer.py

示例11: __init__

    def __init__(self, url='http://geo.woudc.org/ows', timeout=30):
        """
        Initialize a WOUDC Client.

        :returns: instance of pywoudc.WoudcClient
        """

        self.url = url
        """The URL of the WOUDC data service"""

        self.timeout = timeout
        """Time (in seconds) after which requests should timeout"""

        self.about = 'http://woudc.org/about/data-access.php'
        """The About Data Access page"""

        self.outputformat = 'application/json; subtype=geojson'
        """The default outputformat when requesting WOUDC data"""

        self.maxfeatures = 25000
        """The default limit of records to return"""

        LOGGER.info('Contacting %s', self.url)
        self.server = WebFeatureService(self.url, '1.1.0',
                                        timeout=self.timeout)
        """The main WOUDC server"""
开发者ID:tomkralidis,项目名称:pywoudc,代码行数:26,代码来源:__init__.py

示例12: HandleWFS

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,代码行数:59,代码来源:OGCServices.py

示例13: load_layer_data

def load_layer_data(request, template='layers/layer_detail.html'):
    context_dict = {}
    data_dict = json.loads(request.POST.get('json_data'))
    layername = data_dict['layer_name']
    filtered_attributes = data_dict['filtered_attributes']
    workspace, name = layername.split(':')
    location = "{location}{service}".format(** {
        'location': settings.OGC_SERVER['default']['LOCATION'],
        'service': 'wms',
    })

    try:
        username = settings.OGC_SERVER['default']['USER']
        password = settings.OGC_SERVER['default']['PASSWORD']
        wfs = WebFeatureService(location, version='1.1.0', username=username, password=password)
        response = wfs.getfeature(typename=name, propertyname=filtered_attributes, outputFormat='application/json')
        x = response.read()
        x = json.loads(x)
        features_response = json.dumps(x)
        decoded = json.loads(features_response)
        decoded_features = decoded['features']
        properties = {}
        for key in decoded_features[0]['properties']:
            properties[key] = []

        # loop the dictionary based on the values on the list and add the properties
        # in the dictionary (if doesn't exist) together with the value
        for i in range(len(decoded_features)):

            for key, value in decoded_features[i]['properties'].iteritems():
                if value != '' and isinstance(value, (string_types, int, float)):
                    properties[key].append(value)

        for key in properties:
            properties[key] = list(set(properties[key]))
            properties[key].sort()

        context_dict["feature_properties"] = properties
    except:
        print "Possible error with OWSLib."
    return HttpResponse(json.dumps(context_dict), content_type="application/json")
开发者ID:ingenieroariel,项目名称:geonode,代码行数:41,代码来源:views.py

示例14: get_wfs

def get_wfs(server_url, spacename_wfs):

    chemin = '/home/tmp/'+spacename_wfs+'.gml'

    if not os.path.exists(chemin):
        
        wfs = WebFeatureService(server_url +"/wfs/",version='1.0.0')
    
        vector = spacename_wfs
        
        print "Downloading the WFS: "+spacename_wfs
        print "From: "+server_url
        response = wfs.getfeature(typename =[vector])    
    
        data = response.read()
        f = open(chemin,'wb')
        f.write(data)
        f.close()
        print "Done"

    return chemin
开发者ID:geosas,项目名称:WPS_Process_SIGnature_target,代码行数:21,代码来源:get_wfs.py

示例15: get_features

def get_features(wfs_url, layer, verbose=False):
    """Get feature from Web Feature Service (WFS) in GeoJSON format
    
    Input:
       wfs_url: URL for web feature service. E.g. http://www.aifdr.org:8080/geoserver/ows?
       layer: Feature layer name as <workspace>:<layer>
       verbose [optional]: Flag controlling the verbosity level. Default is False.
       
    Output:
       GEOJSON dictionary or None.
    """
    
    if verbose:
        print('Retrieving %s from %s' % (layer, wfs_url))
        
    wfs = WebFeatureService(wfs_url, version='1.0.0')
    
    if layer not in wfs.contents.keys():
        return None
    response = wfs.getfeature(typename=[layer], outputFormat='json', maxfeatures=1)
    return geojson.loads(response.read())
开发者ID:sabman,项目名称:gs-science,代码行数:21,代码来源:api.py


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