def getCoverage(self, identifier=None, bbox=None, time=None, format = None, crs=None, width=None, height=None, resx=None, resy=None, resz=None,parameter=None,method='Get',**kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf """ if log.isEnabledFor(logging.DEBUG): log.debug('WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s'%(identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs))) base_url = self.getOperationByName('GetCoverage').methods[method]['url'] if log.isEnabledFor(logging.DEBUG): log.debug('WCS 1.0.0 DEBUG: base url of server: %s'%base_url) #process kwargs request = {'version': self.version, 'request': 'GetCoverage', 'service':'WCS'} assert len(identifier) > 0 request['Coverage']=identifier #request['identifier'] = ','.join(identifier) if bbox: request['BBox']=','.join([self.__makeString(x) for x in bbox]) else: request['BBox']=None if time: request['time']=','.join(time) if crs: request['crs']=crs request['format']=format if width: request['width']=width if height: request['height']=height if resx: request['resx']=resx if resy: request['resy']=resy if resz: request['resz']=resz #anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw]=kwargs[kw] #encode and request data = urlencode(request) if log.isEnabledFor(logging.DEBUG): log.debug('WCS 1.0.0 DEBUG: Second part of URL: %s'%data) u=openURL(base_url, data, method, self.cookies) return u
def __init__( self, url, version, xml=None, parse_remote_metadata=False, timeout=30, username=None, password=None, auth=None, ): """Initialize.""" if auth: if username: auth.username = username if password: auth.password = password else: auth = Authentication() super(WebFeatureService_2_0_0, self).__init__(auth) if log.isEnabledFor(logging.DEBUG): log.debug("building WFS %s" % url) self.url = url self.version = version self.timeout = timeout self._capabilities = None reader = WFSCapabilitiesReader(self.version, auth=self.auth) if xml: self._capabilities = reader.readString(xml) else: self._capabilities = reader.read(self.url) self._buildMetadata(parse_remote_metadata)
def __init__(self, url, version, xml=None, parse_remote_metadata=False, timeout=30, username=None, password=None): """Initialize.""" if log.isEnabledFor(logging.DEBUG): log.debug('building WFS %s' % url) self.url = url self.version = version self.timeout = timeout self.username = username self.password = password self._capabilities = None reader = WFSCapabilitiesReader(self.version, username=username, password=password) if xml: self._capabilities = reader.readString(xml) else: self._capabilities = reader.read(self.url) self._buildMetadata(parse_remote_metadata)
def __init__(self, url, version, xml=None, parse_remote_metadata=False): """Initialize.""" if log.isEnabledFor(logging.DEBUG): log.debug('building WFS %s'%url) self.url = url self.version = version self._capabilities = None reader = WFSCapabilitiesReader(self.version) if xml: self._capabilities = reader.readString(xml) else: self._capabilities = reader.read(self.url) self._buildMetadata(parse_remote_metadata)
def __init__(self, url, version, xml=None, parse_remote_metadata=False, timeout=30, username=None, password=None): """Initialize.""" if log.isEnabledFor(logging.DEBUG): log.debug("building WFS %s" % url) self.url = url self.version = version self.timeout = timeout self.username = username self.password = password self._capabilities = None reader = WFSCapabilitiesReader(self.version) if xml: self._capabilities = reader.readString(xml) else: self._capabilities = reader.read(self.url) self._buildMetadata(parse_remote_metadata)
def getCoverage( self, identifier=None, bbox=None, time=None, format=None, crs=None, width=None, height=None, resx=None, resy=None, resz=None, parameter=None, method="Get", **kwargs ): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf """ if log.isEnabledFor(logging.DEBUG): log.debug( "WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s" % (identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs)) ) try: base_url = next( ( m.get("url") for m in self.getOperationByName("GetCoverage").methods if m.get("type").lower() == method.lower() ) ) except StopIteration: base_url = self.url if log.isEnabledFor(logging.DEBUG): log.debug("WCS 1.0.0 DEBUG: base url of server: %s" % base_url) # process kwargs request = {"version": self.version, "request": "GetCoverage", "service": "WCS"} assert len(identifier) > 0 request["Coverage"] = identifier # request['identifier'] = ','.join(identifier) if bbox: request["BBox"] = ",".join([self.__makeString(x) for x in bbox]) else: request["BBox"] = None if time: request["time"] = ",".join(time) if crs: request["crs"] = crs request["format"] = format if width: request["width"] = width if height: request["height"] = height if resx: request["resx"] = resx if resy: request["resy"] = resy if resz: request["resz"] = resz # anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw] = kwargs[kw] # encode and request data = urlencode(request) if log.isEnabledFor(logging.DEBUG): log.debug("WCS 1.0.0 DEBUG: Second part of URL: %s" % data) u = openURL(base_url, data, method, self.cookies) return u
def getfeature(self, typename=None, filter=None, bbox=None, featureid=None, featureversion=None, propertyname=None, maxfeatures=None, storedQueryID=None, storedQueryParams={}, method='Get', timeout=None, outputFormat=None): """Request and return feature data as a file-like object. #TODO: NOTE: have changed property name from ['*'] to None - check the use of this in WFS 2.0 Parameters ---------- typename : list List of typenames (string) filter : string XML-encoded OGC filter expression. bbox : tuple (left, bottom, right, top) in the feature type's coordinates == (minx, miny, maxx, maxy) featureid : list List of unique feature ids (string) featureversion : string Default is most recent feature version. propertyname : list List of feature property names. '*' matches all. maxfeatures : int Maximum number of features to be returned. method : string Qualified name of the HTTP DCP method to use. timeout : number A timeout value (in seconds) for the request. outputFormat: string (optional) Requested response format of the request. There are 3 different modes of use 1) typename and bbox (simple spatial query) 2) typename and filter (==query) (more expressive) 3) featureid (direct access to known features) """ if timeout: to = timeout else: to = self.timeout url = data = None if typename and type(typename) == type(""): typename = [typename] if method.upper() == "GET": (url) = self.getGETGetFeatureRequest(typename, filter, bbox, featureid, featureversion, propertyname, maxfeatures, storedQueryID, storedQueryParams, outputFormat) if log.isEnabledFor(logging.DEBUG): log.debug('GetFeature WFS GET url %s' % url) else: (url, data) = self.getPOSTGetFeatureRequest() # If method is 'Post', data will be None here u = urlopen(url, data, to) # check for service exceptions, rewrap, and return # We're going to assume that anything with a content-length > 32k # is data. We'll check anything smaller. try: length = int(u.info()['Content-Length']) have_read = False except KeyError: data = u.read() have_read = True length = len(data) if length < 32000: if not have_read: data = u.read() try: tree = etree.fromstring(data) except BaseException: # Not XML return StringIO(data) else: if tree.tag == "{%s}ServiceExceptionReport" % OGC_NAMESPACE: se = tree.find(nspath('ServiceException', OGC_NAMESPACE)) raise ServiceException(str(se.text).strip()) else: return StringIO(data) else: if have_read: return StringIO(data) return u
def getfeature(self, typename=None, filter=None, bbox=None, featureid=None, featureversion=None, propertyname=None, maxfeatures=None,storedQueryID=None, storedQueryParams={}, method='Get', outputFormat=None, startindex=None): """Request and return feature data as a file-like object. #TODO: NOTE: have changed property name from ['*'] to None - check the use of this in WFS 2.0 Parameters ---------- typename : list List of typenames (string) filter : string XML-encoded OGC filter expression. bbox : tuple (left, bottom, right, top) in the feature type's coordinates == (minx, miny, maxx, maxy) featureid : list List of unique feature ids (string) featureversion : string Default is most recent feature version. propertyname : list List of feature property names. '*' matches all. maxfeatures : int Maximum number of features to be returned. method : string Qualified name of the HTTP DCP method to use. outputFormat: string (optional) Requested response format of the request. startindex: int (optional) Start position to return feature set (paging in combination with maxfeatures) There are 3 different modes of use 1) typename and bbox (simple spatial query) 2) typename and filter (==query) (more expressive) 3) featureid (direct access to known features) """ url = data = None if typename and type(typename) == type(""): typename = [typename] if method.upper() == "GET": (url) = self.getGETGetFeatureRequest(typename, filter, bbox, featureid, featureversion, propertyname, maxfeatures, storedQueryID, storedQueryParams, outputFormat, 'Get', startindex) if log.isEnabledFor(logging.DEBUG): log.debug('GetFeature WFS GET url %s'% url) else: (url,data) = self.getPOSTGetFeatureRequest() # If method is 'Post', data will be None here u = urlopen(url, data, self.timeout) # check for service exceptions, rewrap, and return # We're going to assume that anything with a content-length > 32k # is data. We'll check anything smaller. try: length = int(u.info()['Content-Length']) have_read = False except KeyError: data = u.read() have_read = True length = len(data) if length < 32000: if not have_read: data = u.read() try: tree = etree.fromstring(data) except BaseException: # Not XML return StringIO(data) else: if tree.tag == "{%s}ServiceExceptionReport" % OGC_NAMESPACE: se = tree.find(nspath('ServiceException', OGC_NAMESPACE)) raise ServiceException(str(se.text).strip()) else: return StringIO(data) else: if have_read: return StringIO(data) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format=None, store=False, rangesubset=None, gridbaseCRS=None, gridtype=None, gridCS=None, gridorigin=None, gridoffsets=None, method='Get', **kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverageRequest(identifier=['TuMYrRQ4'], time=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='application/netcdf', store='true') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIMESEQUENCE=2792-06-01T00:00:00.0&FORMAT=application/netcdf if store = true, returns a coverages XML file if store = false, returns a multipart mime """ if log.isEnabledFor(logging.DEBUG): log.debug( 'WCS 1.1.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, rangesubset=%s, gridbaseCRS=%s, gridtype=%s, gridCS=%s, gridorigin=%s, gridoffsets=%s, method=%s, other_arguments=%s' % (identifier, bbox, time, format, rangesubset, gridbaseCRS, gridtype, gridCS, gridorigin, gridoffsets, method, str(kwargs))) if method == 'Get': method = self.ns.WCS_OWS('Get') try: base_url = next( (m.get('url') for m in self.getOperationByName('GetCoverage').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url #process kwargs request = { 'version': self.version, 'request': 'GetCoverage', 'service': 'WCS' } assert len(identifier) > 0 request['identifier'] = identifier #request['identifier'] = ','.join(identifier) if bbox: request['boundingbox'] = ','.join([repr(x) for x in bbox]) if time: request['timesequence'] = ','.join(time) request['format'] = format request['store'] = store #rangesubset: untested - require a server implementation if rangesubset: request['RangeSubset'] = rangesubset #GridCRS structure: untested - require a server implementation if gridbaseCRS: request['gridbaseCRS'] = gridbaseCRS if gridtype: request['gridtype'] = gridtype if gridCS: request['gridCS'] = gridCS if gridorigin: request['gridorigin'] = gridorigin if gridoffsets: request['gridoffsets'] = gridoffsets #anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw] = kwargs[kw] #encode and request data = urlencode(request) u = openURL(base_url, data, method, self.cookies) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format=None, subsets=None, resolutions=None, sizes=None, crs=None, width=None, height=None, resx=None, resy=None, resz=None, parameter=None, method="Get", timeout=30, **kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41), format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf example 2.0.1 URL http://earthserver.pml.ac.uk/rasdaman/ows?&SERVICE=WCS&VERSION=2.0.1&REQUEST=GetCoverage &COVERAGEID=V2_monthly_CCI_chlor_a_insitu_test&SUBSET=Lat(40,50)&SUBSET=Long(-10,0)&SUBSET=ansi(144883,145000)&FORMAT=application/netcdf cvg=wcs.getCoverage(identifier=['myID'], format='application/netcdf', subsets=[('axisName',min,max), ('axisName',min,max),('axisName',min,max)]) """ if log.isEnabledFor(logging.DEBUG): log.debug( "WCS 2.0.1 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s" # noqa % ( identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs), )) try: base_url = next( (m.get("url") for m in self.getOperationByName("GetCoverage").methods if m.get("type").lower() == method.lower())) except StopIteration: base_url = self.url log.debug("WCS 2.0.1 DEBUG: base url of server: %s" % base_url) request = { "version": self.version, "request": "GetCoverage", "service": "WCS" } assert len(identifier) > 0 request["CoverageID"] = identifier[0] if crs: request["crs"] = crs request["format"] = format if width: request["width"] = width if height: request["height"] = height # anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw] = kwargs[kw] # encode and request data = urlencode(request) if subsets: data += param_list_to_url_string(subsets, 'subset') if resolutions: log.debug('Adding vendor-specific RESOLUTION parameter.') data += param_list_to_url_string(resolutions, 'resolution') if sizes: log.debug('Adding vendor-specific SIZE parameter.') data += param_list_to_url_string(sizes, 'size') log.debug("WCS 2.0.1 DEBUG: Second part of URL: %s" % data) u = openURL(base_url, data, method, self.cookies, auth=self.auth, timeout=timeout, headers=self.headers) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format=None, crs=None, width=None, height=None, resx=None, resy=None, resz=None, parameter=None, method='Get', timeout=30, **kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41), format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf """ if log.isEnabledFor(logging.DEBUG): msg = 'WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier={}, bbox={}, time={}, format={}, crs={}, width={}, height={}, resx={}, resy={}, resz={}, parameter={}, method={}, other_arguments={}' # noqa log.debug( msg.format(identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs))) try: base_url = next( (m.get('url') for m in self.getOperationByName('GetCoverage').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url log.debug('WCS 1.0.0 DEBUG: base url of server: %s' % base_url) # process kwargs request = { 'version': self.version, 'request': 'GetCoverage', 'service': 'WCS' } assert len(identifier) > 0 request['Coverage'] = identifier # request['identifier'] = ','.join(identifier) if bbox: request['BBox'] = ','.join([makeString(x) for x in bbox]) else: request['BBox'] = None if time: request['time'] = ','.join(time) if crs: request['crs'] = crs request['format'] = format if width: request['width'] = width if height: request['height'] = height if resx: request['resx'] = resx if resy: request['resy'] = resy if resz: request['resz'] = resz # anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw] = kwargs[kw] # encode and request data = urlencode(request) log.debug('WCS 1.0.0 DEBUG: Second part of URL: %s' % data) u = openURL(base_url, data, method, self.cookies, auth=self.auth, timeout=timeout, headers=self.headers) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format = None, store=False, rangesubset=None, gridbaseCRS=None, gridtype=None, gridCS=None, gridorigin=None, gridoffsets=None, method='Get',**kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverageRequest(identifier=['TuMYrRQ4'], time=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='application/netcdf', store='true') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIMESEQUENCE=2792-06-01T00:00:00.0&FORMAT=application/netcdf if store = true, returns a coverages XML file if store = false, returns a multipart mime """ if log.isEnabledFor(logging.DEBUG): log.debug('WCS 1.1.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, rangesubset=%s, gridbaseCRS=%s, gridtype=%s, gridCS=%s, gridorigin=%s, gridoffsets=%s, method=%s, other_arguments=%s'%(identifier, bbox, time, format, rangesubset, gridbaseCRS, gridtype, gridCS, gridorigin, gridoffsets, method, str(kwargs))) if method == 'Get': method=self.ns.WCS_OWS('Get') try: base_url = next((m.get('url') for m in self.getOperationByName('GetCoverage').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url #process kwargs request = {'version': self.version, 'request': 'GetCoverage', 'service':'WCS'} assert len(identifier) > 0 request['identifier']=identifier #request['identifier'] = ','.join(identifier) if bbox: request['boundingbox']=','.join([repr(x) for x in bbox]) if time: request['timesequence']=','.join(time) request['format']=format request['store']=store #rangesubset: untested - require a server implementation if rangesubset: request['RangeSubset']=rangesubset #GridCRS structure: untested - require a server implementation if gridbaseCRS: request['gridbaseCRS']=gridbaseCRS if gridtype: request['gridtype']=gridtype if gridCS: request['gridCS']=gridCS if gridorigin: request['gridorigin']=gridorigin if gridoffsets: request['gridoffsets']=gridoffsets #anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw]=kwargs[kw] #encode and request data = urlencode(request) u=openURL(base_url, data, method, self.cookies) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format = None, subsets=None,crs=None, width=None, height=None, resx=None, resy=None, resz=None,parameter=None,method='Get',**kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf example 2.0.1 URL http://earthserver.pml.ac.uk/rasdaman/ows?&SERVICE=WCS&VERSION=2.0.1&REQUEST=GetCoverage &COVERAGEID=V2_monthly_CCI_chlor_a_insitu_test&SUBSET=Lat(40,50)&SUBSET=Long(-10,0)&SUBSET=ansi(144883,145000)&FORMAT=application/netcdf cvg=wcs.getCoverage(identifier=['myID'], format='application/netcdf', subsets=[('axisName',min,max),('axisName',min,max),('axisName',min,max)]) """ if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s'%(identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs))) try: base_url = next((m.get('url') for m in self.getOperationByName('GetCoverage').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.0 DEBUG: base url of server: %s'%base_url) request = {'version': self.version, 'request': 'GetCoverage', 'service':'WCS'} assert len(identifier) > 0 request['CoverageID']=identifier[0] if crs: request['crs']=crs request['format']=format if width: request['width']=width if height: request['height']=height #anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw]=kwargs[kw] #encode and request data = urlencode(request) if subsets: for subset in subsets: if len(subset) > 2: if not self.is_number(subset[1]): data = data + "&"+ urlencode({"subset":subset[0]+'("'+self.__makeString(subset[1])+'","'+self.__makeString(subset[2])+'")'}) else: data = data + "&"+ urlencode({"subset":subset[0]+'('+self.__makeString(subset[1])+','+self.__makeString(subset[2])+')'}) else: if not self.is_number(subset[1]): data = data + "&"+ urlencode({"subset":subset[0]+'("'+self.__makeString(subset[1])+'")'}) else: data = data + "&"+ urlencode({"subset":subset[0]+'('+self.__makeString(subset[1])+')'}) if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.0 DEBUG: Second part of URL: %s'%data) u = openURL(base_url, data, method, self.cookies, auth=self.auth) return u
def getCoverage( self, identifier=None, bbox=None, time=None, format=None, store=False, rangesubset=None, gridbaseCRS=None, gridtype=None, gridCS=None, gridorigin=None, gridoffsets=None, method="Get", **kwargs ): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverageRequest(identifier=['TuMYrRQ4'], time=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='application/netcdf', store='true') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIMESEQUENCE=2792-06-01T00:00:00.0&FORMAT=application/netcdf if store = true, returns a coverages XML file if store = false, returns a multipart mime """ if log.isEnabledFor(logging.DEBUG): log.debug( "WCS 1.1.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, rangesubset=%s, gridbaseCRS=%s, gridtype=%s, gridCS=%s, gridorigin=%s, gridoffsets=%s, method=%s, other_arguments=%s" % ( identifier, bbox, time, format, rangesubset, gridbaseCRS, gridtype, gridCS, gridorigin, gridoffsets, method, str(kwargs), ) ) if method == "Get": method = "{http://www.opengis.net/wcs/1.1/ows}Get" base_url = self.getOperationByName("GetCoverage").methods[method]["url"] # process kwargs request = {"version": self.version, "request": "GetCoverage", "service": "WCS"} assert len(identifier) > 0 request["identifier"] = identifier # request['identifier'] = ','.join(identifier) if bbox: request["boundingbox"] = ",".join([repr(x) for x in bbox]) if time: request["timesequence"] = ",".join(time) request["format"] = format request["store"] = store # rangesubset: untested - require a server implementation if rangesubset: request["RangeSubset"] = rangesubset # GridCRS structure: untested - require a server implementation if gridbaseCRS: request["gridbaseCRS"] = gridbaseCRS if gridtype: request["gridtype"] = gridtype if gridCS: request["gridCS"] = gridCS if gridorigin: request["gridorigin"] = gridorigin if gridoffsets: request["gridoffsets"] = gridoffsets # anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw] = kwargs[kw] # encode and request data = urlencode(request) u = openURL(base_url, data, method, self.cookies) return u
def getfeature( self, typename=None, filter=None, bbox=None, featureid=None, featureversion=None, propertyname=None, maxfeatures=None, storedQueryID=None, storedQueryParams=None, method="Get", outputFormat=None, startindex=None, sortby=None, ): """Request and return feature data as a file-like object. #TODO: NOTE: have changed property name from ['*'] to None - check the use of this in WFS 2.0 Parameters ---------- typename : list List of typenames (string) filter : string XML-encoded OGC filter expression. bbox : tuple (left, bottom, right, top) in the feature type's coordinates == (minx, miny, maxx, maxy) featureid : list List of unique feature ids (string) featureversion : string Default is most recent feature version. propertyname : list List of feature property names. '*' matches all. maxfeatures : int Maximum number of features to be returned. method : string Qualified name of the HTTP DCP method to use. outputFormat: string (optional) Requested response format of the request. startindex: int (optional) Start position to return feature set (paging in combination with maxfeatures) sortby: list (optional) List of property names whose values should be used to order (upon presentation) the set of feature instances that satify the query. There are 3 different modes of use 1) typename and bbox (simple spatial query) 2) typename and filter (==query) (more expressive) 3) featureid (direct access to known features) """ storedQueryParams = storedQueryParams or {} url = data = None if typename and type(typename) == type(""): # noqa: E721 typename = [typename] if method.upper() == "GET": (url) = self.getGETGetFeatureRequest( typename, filter, bbox, featureid, featureversion, propertyname, maxfeatures, storedQueryID, storedQueryParams, outputFormat, "Get", startindex, sortby, ) if log.isEnabledFor(logging.DEBUG): log.debug("GetFeature WFS GET url %s" % url) else: (url, data) = self.getPOSTGetFeatureRequest() # If method is 'Post', data will be None here u = openURL(url, data, method, timeout=self.timeout, auth=self.auth) # check for service exceptions, rewrap, and return # We're going to assume that anything with a content-length > 32k # is data. We'll check anything smaller. if "Content-Length" in u.info(): length = int(u.info()["Content-Length"]) have_read = False else: data = u.read() have_read = True length = len(data) if length < 32000: if not have_read: data = u.read() try: tree = etree.fromstring(data) except BaseException: # Not XML return makeStringIO(data) else: if tree.tag == "{%s}ServiceExceptionReport" % OGC_NAMESPACE: se = tree.find(nspath("ServiceException", OGC_NAMESPACE)) raise ServiceException(str(se.text).strip()) else: return makeStringIO(data) else: if have_read: return makeStringIO(data) return u
def getCoverage(self, identifier=None, bbox=None, time=None, format = None, subsets=None,crs=None, width=None, height=None, resx=None, resy=None, resz=None,parameter=None,method='Get',**kwargs): """Request and return a coverage from the WCS as a file-like object note: additional **kwargs helps with multi-version implementation core keyword arguments should be supported cross version example: cvg=wcs.getCoverage(identifier=['TuMYrRQ4'], timeSequence=['2792-06-01T00:00:00.0'], bbox=(-112,36,-106,41),format='cf-netcdf') is equivalent to: http://myhost/mywcs?SERVICE=WCS&REQUEST=GetCoverage&IDENTIFIER=TuMYrRQ4&VERSION=1.1.0&BOUNDINGBOX=-180,-90,180,90&TIME=2792-06-01T00:00:00.0&FORMAT=cf-netcdf example 2.0.1 URL http://earthserver.pml.ac.uk/rasdaman/ows?&SERVICE=WCS&VERSION=2.0.1&REQUEST=GetCoverage &COVERAGEID=V2_monthly_CCI_chlor_a_insitu_test&SUBSET=Lat(40,50)&SUBSET=Long(-10,0)&SUBSET=ansi(144883,145000)&FORMAT=application/netcdf cvg=wcs.getCoverage(identifier=['myID'], format='application/netcdf', subsets=[('axisName',min,max),('axisName',min,max),('axisName',min,max)]) """ if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.1 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s'%(identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs))) try: base_url = next((m.get('url') for m in self.getOperationByName('GetCoverage').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.1 DEBUG: base url of server: %s'%base_url) request = {'version': self.version, 'request': 'GetCoverage', 'service':'WCS'} assert len(identifier) > 0 request['CoverageID']=identifier[0] if crs: request['crs']=crs request['format']=format if width: request['width']=width if height: request['height']=height #anything else e.g. vendor specific parameters must go through kwargs if kwargs: for kw in kwargs: request[kw]=kwargs[kw] #encode and request data = urlencode(request) if subsets: for subset in subsets: if len(subset) > 2: if not self.is_number(subset[1]): data = data + "&"+ urlencode({"subset":subset[0]+'("'+self.__makeString(subset[1])+'","'+self.__makeString(subset[2])+'")'}) else: data = data + "&"+ urlencode({"subset":subset[0]+'('+self.__makeString(subset[1])+','+self.__makeString(subset[2])+')'}) else: if not self.is_number(subset[1]): data = data + "&"+ urlencode({"subset":subset[0]+'("'+self.__makeString(subset[1])+'")'}) else: data = data + "&"+ urlencode({"subset":subset[0]+'('+self.__makeString(subset[1])+')'}) if log.isEnabledFor(logging.DEBUG): log.debug('WCS 2.0.1 DEBUG: Second part of URL: %s'%data) u=openURL(base_url, data, method, self.cookies) return u