Skip to content
Commits on Source (5)
---
exclude_paths:
- 'tests/**'
- 'docs/conf.py'
[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
disable=W0311, C0301, C0103, C0326, W1201
......@@ -14,7 +14,8 @@ install:
- if [ "$LXML" == "true" ]; then pip install lxml; fi
script:
- python -m pytest
- pep8 owslib/wmts.py
- flake8 owslib/wmts.py
- flake8 owslib/wps.py
after_success:
- coveralls
notifications:
......
Changes
=======
0.17.0 (2018-09-04)
-------------------
- Fixed test-suite and converted doctests to unit-tests (#339).
- Support for OWS Context (#483 thanks @allixender)
- Support for WCS 2.0.0 and 2.0.1 (#430, thanks @doclements)
- numerous bug-fixes, especially for WPS.
0.7 (2013-02-18)
---------------
......@@ -67,3 +75,23 @@ Changes
------------------
- Change license to BSD.
- Added service contact metadata.
0.1.0 (2006-10-19)
------------------
- New and improved metadata API.
- Wrappers for GetCapabilities, WMS GetMap, and WFS GetFeature requests.
- Doctests.
0.0.1 (2006-07-30)
------------------
- Brought OWSLib up out of the PCL trunk into its own space.
- Updated the testing frameworm.
- Initial test coverage:
Name Stmts Exec Cover Missing
====== ======= ====== ======= =========
wms 105 68 64% 36, 41-48, 61-63, 114-118, 125-155, 172, 203-205
wfs 74 69 93% 146, 166, 199-201
wmc 111 0 0% 33-220
TOTAL 290 137 47%
====== ======= ====== ======= =========
- elementtree or lxml
HISTORY
=======
OWSLib 0.1: 19 October 2006
---------------------------
- New and improved metadata API.
- Wrappers for GetCapabilities, WMS GetMap, and WFS GetFeature requests.
- Doctests.
OWSLib 0.0: 30 July 2006
------------------------
- Brought OWSLib up out of the PCL trunk into its own space.
- Updated the testing frameworm.
- Initial test coverage:
Name Stmts Exec Cover Missing
-------------------------------------
wms 105 68 64% 36, 41-48, 61-63, 114-118, 125-155, 172, 203-205
wfs 74 69 93% 146, 166, 199-201
wmc 111 0 0% 33-220
-------------------------------------
TOTAL 290 137 47%
See http://geopython.github.io/OWSLib/#installation
BSD 3-Clause License
Copyright (c) 2006, Ancient World Mapping Center
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (c) 2006, Ancient World Mapping Center
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Ancient World Mapping Center nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
include *.txt
include *.rst
recursive-include owslib
OWSLib
======
.. image:: https://travis-ci.org/geopython/OWSLib.svg?branch=master
:target: https://travis-ci.org/geopython/OWSLib
:alt: Travis Build
.. image:: https://api.codacy.com/project/badge/Grade/09f15588c99943e3976cdf20b7b32c8d
:target: https://www.codacy.com/project/cehbrecht/OWSLib/dashboard?utm_source=github.com&utm_medium=referral&utm_content=geopython/OWSLib&utm_campaign=Badge_Grade_Dashboard
:alt: Codacy Check
.. image:: https://img.shields.io/github/license/geopython/OWSLib.svg
:target: https://github.com/geopython/OWSLib/blob/master/LICENSE
:alt: GitHub license
.. image:: https://badges.gitter.im/geopython/OWSLib.svg
:target: https://gitter.im/geopython/OWSLib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
:alt: Join the chat at https://gitter.im/geopython/OWSLib
OWSLib is a Python package for client programming with Open Geospatial
Consortium (OGC) web service (hence OWS) interface standards, and their
related content models.
......@@ -15,6 +31,11 @@ Dependencies
OWSLib requires elementtree (standard in 2.5 as xml.etree) or lxml.
Installation
------------
See http://geopython.github.io/OWSLib/#installation
Usage
-----
......
owslib (0.16.0-4) UNRELEASED; urgency=medium
owslib (0.17.0-1) unstable; urgency=medium
* Team upload.
* New upstream release.
* Bump Standards-Version to 4.2.1, no changes.
* Refresh patches.
-- Bas Couwenberg <sebastic@debian.org> Tue, 28 Aug 2018 14:50:26 +0200
-- Bas Couwenberg <sebastic@debian.org> Thu, 20 Sep 2018 07:38:39 +0200
owslib (0.16.0-3) unstable; urgency=medium
......
......@@ -3,7 +3,7 @@ Author: Johan Van de Wauw <johan@vandewauw.be>
--- a/docs/en/index.rst
+++ b/docs/en/index.rst
@@ -5,11 +5,7 @@
@@ -5,11 +5,7 @@ OWSLib |release| documentation
.. toctree::
:maxdepth: 2
......
......@@ -52,6 +52,8 @@ Standards Support
+-------------------+---------------------+
| `OGC OWS Common`_ | 1.0.0, 1.1.0, 2.0 |
+-------------------+---------------------+
| `OGC OWS Context`_ | 1.0.0 (alpha/under-review) |
+-------------------+---------------------+
| `NASA DIF`_ | 9.7 |
+-------------------+---------------------+
| `FGDC CSDGM`_ | 1998 |
......@@ -134,6 +136,7 @@ Fedora:
As of Fedora 20, OWSLib is part of the Fedora core package collection
.. code-block:: bash
$ yum install OWSLib
Usage
......@@ -420,186 +423,7 @@ WMC
WPS
---
Inspect a remote WPS and retrieve the supported processes:
.. code-block:: python
>>> from owslib.wps import WebProcessingService
>>> wps = WebProcessingService('http://cida.usgs.gov/climate/gdp/process/WebProcessingService', verbose=False, skip_caps=True)
>>> wps.getcapabilities()
>>> wps.identification.type
'WPS'
>>> wps.identification.title
'Geo Data Portal WPS Processing'
>>> wps.identification.abstract
'Geo Data Portal WPS Processing'
>>> for operation in wps.operations:
... operation.name
...
'GetCapabilities'
'DescribeProcess'
'Execute'
>>> for process in wps.processes:
... process.identifier, process.title
...
('gov.usgs.cida.gdp.wps.algorithm.FeatureCoverageIntersectionAlgorithm', 'Feature Coverage WCS Intersection')
('gov.usgs.cida.gdp.wps.algorithm.FeatureCoverageOPeNDAPIntersectionAlgorithm', 'Feature Coverage OPeNDAP Intersection')
('gov.usgs.cida.gdp.wps.algorithm.FeatureCategoricalGridCoverageAlgorithm', 'Feature Categorical Grid Coverage')
('gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm', 'Feature Weighted Grid Statistics')
('gov.usgs.cida.gdp.wps.algorithm.FeatureGridStatisticsAlgorithm', 'Feature Grid Statistics')
('gov.usgs.cida.gdp.wps.algorithm.PRMSParameterGeneratorAlgorithm', 'PRMS Parameter Generator')
>>>
Determine how a specific process needs to be invoked - i.e. what are its input parameters, and output result:
.. code-block:: python
>>> from owslib.wps import printInputOutput
>>> process = wps.describeprocess('gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm')
>>> process.identifier
'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
>>> process.title
'Feature Weighted Grid Statistics'
>>> process.abstract
'This algorithm generates area weighted statistics of a gridded dataset for a set of vector polygon features. Using the bounding-box that encloses ...
>>> for input in process.dataInputs:
... printInputOutput(input)
...
identifier=FEATURE_COLLECTION, title=Feature Collection, abstract=A feature collection encoded as a WFS request or one of the supported GML profiles.,...
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/2.0.0/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/2.1.1/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/2.1.2/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/2.1.2.1/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/3.0.0/base/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/3.0.1/base/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/3.1.0/base/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/3.1.1/base/feature.xsd
Supported Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/3.2.1/base/feature.xsd
Default Value: mimeType=text/xml, encoding=UTF-8, schema=http://schemas.opengis.net/gml/2.0.0/feature.xsd
minOccurs=1, maxOccurs=1
identifier=DATASET_URI, title=Dataset URI, abstract=The base data web service URI for the dataset of interest., data type=anyURI
Allowed Value: AnyValue
Default Value: None
minOccurs=1, maxOccurs=1
identifier=DATASET_ID, title=Dataset Identifier, abstract=The unique identifier for the data type or variable of interest., data type=string
Allowed Value: AnyValue
Default Value: None
minOccurs=1, maxOccurs=2147483647
identifier=REQUIRE_FULL_COVERAGE, title=Require Full Coverage, abstract=If turned on, the service will require that the dataset of interest ....
Allowed Value: True
Default Value: True
minOccurs=1, maxOccurs=1
identifier=TIME_START, title=Time Start, abstract=The date to begin analysis., data type=dateTime
Allowed Value: AnyValue
Default Value: None
minOccurs=0, maxOccurs=1
identifier=TIME_END, title=Time End, abstract=The date to end analysis., data type=dateTime
Allowed Value: AnyValue
Default Value: None
minOccurs=0, maxOccurs=1
identifier=FEATURE_ATTRIBUTE_NAME, title=Feature Attribute Name, abstract=The attribute that will be used to label column headers in processing output., ...
Allowed Value: AnyValue
Default Value: None
minOccurs=1, maxOccurs=1
identifier=DELIMITER, title=Delimiter, abstract=The delimiter that will be used to separate columns in the processing output., data type=string
Allowed Value: COMMA
Allowed Value: TAB
Allowed Value: SPACE
Default Value: COMMA
minOccurs=1, maxOccurs=1
identifier=STATISTICS, title=Statistics, abstract=Statistics that will be returned for each feature in the processing output., data type=string
Allowed Value: MEAN
Allowed Value: MINIMUM
Allowed Value: MAXIMUM
Allowed Value: VARIANCE
Allowed Value: STD_DEV
Allowed Value: SUM
Allowed Value: COUNT
Default Value: None
minOccurs=1, maxOccurs=7
identifier=GROUP_BY, title=Group By, abstract=If multiple features and statistics are selected, this will change whether the processing output ...
Allowed Value: STATISTIC
Allowed Value: FEATURE_ATTRIBUTE
Default Value: None
minOccurs=1, maxOccurs=1
identifier=SUMMARIZE_TIMESTEP, title=Summarize Timestep, abstract=If selected, processing output will include columns with summarized statistics ...
Allowed Value: True
Default Value: True
minOccurs=0, maxOccurs=1
identifier=SUMMARIZE_FEATURE_ATTRIBUTE, title=Summarize Feature Attribute, abstract=If selected, processing output will include a final row of ...
Allowed Value: True
Default Value: True
minOccurs=0, maxOccurs=1
>>> for output in process.processOutputs:
... printInputOutput(output)
...
identifier=OUTPUT, title=Output File, abstract=A delimited text file containing requested process output., data type=ComplexData
Supported Value: mimeType=text/csv, encoding=UTF-8, schema=None
Default Value: mimeType=text/csv, encoding=UTF-8, schema=None
reference=None, mimeType=None
>>>
Submit a processing request (extraction of a climate index variable over a specific GML polygon, for a given period of time), monitor the execution until complete:
.. code-block:: python
>>> from owslib.wps import GMLMultiPolygonFeatureCollection
>>> polygon = [(-102.8184, 39.5273), (-102.8184, 37.418), (-101.2363, 37.418), (-101.2363, 39.5273), (-102.8184, 39.5273)]
>>> featureCollection = GMLMultiPolygonFeatureCollection( [polygon] )
>>> processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
>>> inputs = [ ("FEATURE_ATTRIBUTE_NAME","the_geom"),
... ("DATASET_URI", "dods://cida.usgs.gov/qa/thredds/dodsC/derivatives/derivative-days_above_threshold.pr.ncml"),
... ("DATASET_ID", "ensemble_b1_pr-days_above_threshold"),
... ("TIME_START","2010-01-01T00:00:00.000Z"),
... ("TIME_END","2011-01-01T00:00:00.000Z"),
... ("REQUIRE_FULL_COVERAGE","false"),
... ("DELIMITER","COMMA"),
... ("STATISTICS","MEAN"),
... ("GROUP_BY","STATISTIC"),
... ("SUMMARIZE_TIMESTEP","false"),
... ("SUMMARIZE_FEATURE_ATTRIBUTE","false"),
... ("FEATURE_COLLECTION", featureCollection)
... ]
>>> output = "OUTPUT"
>>> execution = wps.execute(processid, inputs, output = "OUTPUT")
Executing WPS request...
Execution status=ProcessStarted
>>> from owslib.wps import monitorExecution
>>> monitorExecution(execution)
Checking execution status... (location=http://cida.usgs.gov/climate/gdp/process/RetrieveResultServlet?id=6809217153012787208)
Execution status=ProcessSucceeded
Execution status: ProcessSucceeded
Output URL=http://cida.usgs.gov/climate/gdp/process/RetrieveResultServlet?id=6809217153012787208OUTPUT.3cbcd666-a912-456f-84a3-6ede450aca95
>>>
Alternatively, define the feature through an embedded query to a WFS server:
.. code-block:: python
>>> from owslib.wps import WFSQuery, WFSFeatureCollection
>>> wfsUrl = "http://cida.usgs.gov/climate/gdp/proxy/http://igsarm-cida-gdp2.er.usgs.gov:8082/geoserver/wfs"
>>> query = WFSQuery("sample:CONUS_States", propertyNames=['the_geom',"STATE"], filters=["CONUS_States.508","CONUS_States.469"])
>>> featureCollection = WFSFeatureCollection(wfsUrl, query)
>>> # same process submission as above
...
You can also submit a pre-made request encoded as WPS XML:
.. code-block:: python
>>> request = open('/Users/cinquini/Documents/workspace-cog/wps/tests/resources/wps_USGSExecuteRequest1.xml','rb').read()
>>> execution = wps.execute(None, [], request=request)
Executing WPS request...
Execution status=ProcessStarted
>>> monitorExecution(execution)
Checking execution status... (location=http://cida.usgs.gov/climate/gdp/process/RetrieveResultServlet?id=5103866488472745994)
Execution status=ProcessSucceeded
Execution status: ProcessSucceeded
Output URL=http://cida.usgs.gov/climate/gdp/process/RetrieveResultServlet?id=5103866488472745994OUTPUT.f80e2a78-96a9-4343-9777-be60fac5b256
.. include:: ../../tests/_broken/doctests_sphinx/wps_example_usgs.txt
SOS 1.0
-------
......@@ -614,13 +438,16 @@ GetObservation
SOS 2.0
-------
Examples of service metadata and GetObservation
+++++++++++++++++++++++++++++++++++++++++++++++
.. include:: ../../tests/doctests/sos_20_52n_geoviqua.txt
.. include:: ../../tests/_broken/doctests_sphinx/sos_20_52N_demo.txt
Using the GetObservation response decoder for O&M and WaterML2.0 results
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.. include:: ../../tests/doctests/sos_20_timeseries_decoder_ioos.txt
.. include:: ../../tests/_broken/doctests_sphinx/sos_20_timeseries_decoder_ioos.txt
SensorML
--------
......@@ -663,7 +490,7 @@ Swiss GM03
WMTS
----
.. include:: ../../tests/doctests/wmts.txt
.. include:: ../../tests/_broken/doctests_sphinx/wmts_demo.txt
Result:
......@@ -677,6 +504,41 @@ WaterML
.. include:: ../../tests/doctests/wml11_cuahsi.txt
OGC OWS Context 1.0.0 Atom CML and GeoJSON Encoding (alpha/under-review)
------------------------------------------------------------------------
The OGC OWS Context implementation in OWSlib is currently in alpha and under review, and will still be improved.
Please get in touch if you (want to) use it and provide feedback on how more comfortable it should be
(especially handling geometries and dates in different encodings) and if it doesn't treat your "standards-compliant" OWS Context document right.
Greatly appreciated :-)
Basic reading/parsing of OGC Web Services Context Documents (OWS Context) in OWC Atom 1.0.0 Encoding and OWC GeoJSON 1.0.0 Encoding Standards:
.. include:: ../../tests/doctests/owscontext.txt
additionally, possibility to construct OWS Context documents from scratch, and then write/serialise into OWC Atom 1.0.0 Encoding or OWC GeoJSON 1.0.0 Encoding Standards:
.. code-block:: python
>>> from owslib.owscontext.core import OwcResource, OwcContext
>>> myContext=OwcContext(id='http://my.url.com/context/id/1',
update_date='2017-11-02T15:24:24.446+12:00',
title='Awesome new Context doc')
>>> myContext.rights='Creative Commons 4.0 BY'
>>> myEntry=OwcResource(id='http://my.url.com/resource/demo-feature-1',
update_date='2017-11-02T15:24:24.446+12:00',
title='This is a feature')
>>> contributor={'name': 'Alex K',
'email': None,
'uri': 'https://allixender.blogspot.com'}
>>> myEntry.authors.append(contributor)
>>> # ... here also continue to build your OGC data offerings, e.g. WMS GetMap etc.
>>> myContext.resources.append(myEntry)
>>> myContext.to_json()
>>> myContext.to_atomxml()
Development
===========
......@@ -783,7 +645,7 @@ POSSIBILITY OF SUCH DAMAGE.
Credits
=======
.. include:: ../../CREDITS.txt
.. include:: ../../AUTHORS.rst
.. _`Open Geospatial Consortium`: http://www.opengeospatial.org/
.. _`OGC WMS`: http://www.opengeospatial.org/standards/wms
......@@ -799,6 +661,7 @@ Credits
.. _`OGC WMTS`: http://www.opengeospatial.org/standards/wmts
.. _`OGC Filter`: http://www.opengeospatial.org/standards/filter
.. _`OGC OWS Common`: http://www.opengeospatial.org/standards/common
.. _`OGC OWS Context`: http://www.opengeospatial.org/standards/owc
.. _`NASA DIF`: http://gcmd.nasa.gov/User/difguide/
.. _`FGDC CSDGM`: http://www.fgdc.gov/metadata/csdgm
.. _`ISO 19115`: http://www.iso.org/iso/catalogue_detail.htm?csnumber=26020
......
from __future__ import (absolute_import, division, print_function)
__version__ = '0.16.0'
__version__ = '0.17.0'
# -*- coding: ISO-8859-15 -*-
# =============================================================================
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Oliver Clements <olcl@pml.ac.uk>
#
# Contact email: olcl@pml.ac.uk
# =============================================================================
##########NOTE: Does not conform to new interfaces yet #################
from __future__ import (absolute_import, division, print_function)
from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.ows import OwsCommon, ServiceIdentification, ServiceProvider, OperationsMetadata
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
from owslib.util import openURL, testXMLValue
from owslib.etree import etree
from owslib.crs import Crs
import os, errno
import dateutil.parser as parser
from datetime import timedelta
import logging
from owslib.util import log, datetime_from_ansi, datetime_from_iso
# function to save writing out WCS namespace in full each time
def ns(tag):
return '{http://www.opengis.net/ows/2.0}'+tag
def nsWCS2(tag):
return '{http://www.opengis.net/wcs/2.0}'+tag
class WebCoverageService_2_0_0(WCSBase):
"""Abstraction for OGC Web Coverage Service (WCS), version 2.0.0
Implements IWebCoverageService.
"""
def __getitem__(self,name):
''' check contents dictionary to allow dict like access to service layers'''
if name in self.__getattribute__('contents').keys():
return self.__getattribute__('contents')[name]
else:
raise KeyError("No content named %s" % name)
def __init__(self,url,xml, cookies):
self.version='2.0.0'
self.url = url
self.cookies=cookies
self.ows_common = OwsCommon(version='2.0.0')
# initialize from saved capability document or access the server
reader = WCSCapabilitiesReader(self.version, self.cookies)
if xml:
self._capabilities = reader.readString(xml)
else:
self._capabilities = reader.read(self.url)
# check for exceptions
se = self._capabilities.find('ServiceException')
if se is not None:
err_message = str(se.text).strip()
raise ServiceException(err_message, xml)
#serviceIdentification metadata
subelem=self._capabilities.find(ns('ServiceIdentification'))
self.identification=ServiceIdentification(subelem, namespace=self.ows_common.namespace)
#serviceProvider metadata
serviceproviderelem=self._capabilities.find(ns('ServiceProvider'))
self.provider=ServiceProvider(serviceproviderelem, namespace=self.ows_common.namespace)
#serviceOperations metadata
self.operations=[]
for elem in self._capabilities.find(ns('OperationsMetadata'))[:]:
if elem.tag !=ns('ExtendedCapabilities'):
self.operations.append(OperationsMetadata(elem, namespace=self.ows_common.namespace))
#serviceContents metadata
self.contents={}
for elem in self._capabilities.findall(nsWCS2('Contents/')+nsWCS2('CoverageSummary')):
cm=ContentMetadata(elem, self)
self.contents[cm.id]=cm
#exceptions
self.exceptions = [f.text for f \
in self._capabilities.findall('Capability/Exception/Format')]
def items(self):
'''supports dict-like items() access'''
items=[]
for item in self.contents:
items.append((item,self.contents[item]))
return items
def __makeString(self,value):
#using repr unconditionally breaks things in some circumstances if a value is already a string
if type(value) is not str:
sval=repr(value)
else:
sval = value
return sval
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)
return u
def is_number(self,s):
"""simple helper to test if value is number as requests with numbers dont
need quote marks
"""
try:
float(s)
return True
except ValueError:
return False
def getOperationByName(self, name):
"""Return a named operation item."""
for item in self.operations:
if item.name == name:
return item
raise KeyError("No operation named %s" % name)
class ContentMetadata(object):
"""
Implements IContentMetadata
"""
def __init__(self, elem, service):
"""Initialize. service is required so that describeCoverage requests may be made"""
#TODO - examine the parent for bounding box info.
self._elem=elem
self._service=service
self.id=elem.find(nsWCS2('CoverageId')).text
self.title = testXMLValue(elem.find(ns('label')))
self.abstract= testXMLValue(elem.find(ns('description')))
self.keywords = [f.text for f in elem.findall(ns('keywords')+'/'+ns('keyword'))]
self.boundingBox=None #needed for iContentMetadata harmonisation
self.boundingBoxWGS84 = None
b = elem.find(ns('lonLatEnvelope'))
if b is not None:
gmlpositions=b.findall('{http://www.opengis.net/gml}pos')
lc=gmlpositions[0].text
uc=gmlpositions[1].text
self.boundingBoxWGS84 = (
float(lc.split()[0]),float(lc.split()[1]),
float(uc.split()[0]), float(uc.split()[1]),
)
#others not used but needed for iContentMetadata harmonisation
self.styles=None
self.crsOptions=None
self.defaulttimeposition=None
#grid is either a gml:Grid or a gml:RectifiedGrid if supplied as part of the DescribeCoverage response.
def _getGrid(self):
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
gridelem= self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.3/rgrid}ReferenceableGridByVectors')
if gridelem is not None:
grid=ReferenceableGridByVectors(gridelem)
else:
# HERE I LOOK FOR RECTIFIEDGRID
gridelem=self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.2}RectifiedGrid')
grid=RectifiedGrid(gridelem)
return grid
grid=property(_getGrid, None)
#timelimits are the start/end times, timepositions are all timepoints. WCS servers can declare one or both or neither of these.
# in wcs 2.0 this can be gathered from the Envelope tag
def _getTimeLimits(self):
# timepoints, timelimits=[],[]
# b=self._elem.find(ns('lonLatEnvelope'))
# if b is not None:
# timepoints=b.findall('{http://www.opengis.net/gml}timePosition')
# else:
# #have to make a describeCoverage request...
# if not hasattr(self, 'descCov'):
# self.descCov=self._service.getDescribeCoverage(self.id)
# for pos in self.descCov.findall(ns('CoverageOffering/')+ns('domainSet/')+ns('temporalDomain/')+'{http://www.opengis.net/gml}timePosition'):
# timepoints.append(pos)
# if timepoints:
# timelimits=[timepoints[0].text,timepoints[1].text]
return [self.timepositions[0],self.timepositions[-1]]
timelimits=property(_getTimeLimits, None)
def _getTimePositions(self):
timepositions=[]
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
gridelem= self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.3/rgrid}ReferenceableGridByVectors')
if gridelem is not None:
# irregular time axis
cooeficients = []
grid_axes = gridelem.findall('{http://www.opengis.net/gml/3.3/rgrid}generalGridAxis')
for elem in grid_axes:
if elem.find('{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}gridAxesSpanned').text in ["ansi", "unix"]:
cooeficients = elem.find('{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}coefficients').text.split(' ')
for x in cooeficients:
x = x.replace('"', '')
t_date = datetime_from_iso(x)
timepositions.append(t_date)
else:
# regular time
if(len(self.grid.origin)>2):
t_grid = self.grid
t_date = t_grid.origin[2]
start_pos = parser.parse(t_date, fuzzy=True)
step = float(t_grid.offsetvectors[2][2])
start_pos = start_pos + timedelta(days=(step/2))
no_steps = int(t_grid.highlimits[2])
for x in range(no_steps):
t_pos = start_pos + timedelta(days=(step * x))
#t_date = datetime_from_ansi(t_pos)
#t_date = t_pos.isoformat()
timepositions.append(t_pos)
else:
# no time axis
timepositions = None
return timepositions
timepositions=property(_getTimePositions, None)
def _getOtherBoundingBoxes(self):
''' incomplete, should return other bounding boxes not in WGS84
#TODO: find any other bounding boxes. Need to check for gml:EnvelopeWithTimePeriod.'''
bboxes=[]
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
for envelope in self.descCov.findall(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}boundedBy/'+'{http://www.opengis.net/gml/3.2}Envelope'):
bbox = {}
bbox['nativeSrs'] = envelope.attrib['srsName']
lc = envelope.find('{http://www.opengis.net/gml/3.2}lowerCorner')
lc =lc.text.split()
uc = envelope.find('{http://www.opengis.net/gml/3.2}upperCorner')
uc =uc.text.split()
bbox['bbox'] = (
float(lc[0]),float(lc[1]),
float(uc[0]), float(uc[1])
)
bboxes.append(bbox)
return bboxes
boundingboxes=property(_getOtherBoundingBoxes,None)
def _getSupportedCRSProperty(self):
# gets supported crs info
crss=[]
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('responseCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('requestResponseCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('nativeCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
return crss
supportedCRS=property(_getSupportedCRSProperty, None)
def _getSupportedFormatsProperty(self):
# gets supported formats info
frmts =[]
for elem in self._service._capabilities.findall(nsWCS2('ServiceMetadata/')+nsWCS2('formatSupported')):
frmts.append(elem.text)
return frmts
supportedFormats=property(_getSupportedFormatsProperty, None)
def _getAxisDescriptionsProperty(self):
#gets any axis descriptions contained in the rangeset (requires a DescribeCoverage call to server).
axisDescs =[]
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('rangeSet/')+ns('RangeSet/')+ns('axisDescription/')+ns('AxisDescription')):
axisDescs.append(AxisDescription(elem)) #create a 'AxisDescription' object.
return axisDescs
axisDescriptions=property(_getAxisDescriptionsProperty, None)
#Adding classes to represent gml:grid and gml:rectifiedgrid. One of these is used for the cvg.grid property
#(where cvg is a member of the contents dictionary)
#There is no simple way to convert the offset values in a rectifiedgrid grid to real values without CRS understanding, therefore this is beyond the current scope of owslib, so the representation here is purely to provide access to the information in the GML.
class Grid(object):
''' Simple grid class to provide axis and value information for a gml grid '''
def __init__(self, grid):
self.axislabels = []
self.dimension=None
self.lowlimits=[]
self.highlimits=[]
if grid is not None:
self.dimension=int(grid.get('dimension'))
self.lowlimits= grid.find('{http://www.opengis.net/gml/3.2}limits/{http://www.opengis.net/gml/3.2}GridEnvelope/{http://www.opengis.net/gml/3.2}low').text.split(' ')
self.highlimits = grid.find('{http://www.opengis.net/gml/3.2}limits/{http://www.opengis.net/gml/3.2}GridEnvelope/{http://www.opengis.net/gml/3.2}high').text.split(' ')
for axis in grid.findall('{http://www.opengis.net/gml/3.2}axisLabels')[0].text.split(' '):
self.axislabels.append(axis)
class RectifiedGrid(Grid):
''' RectifiedGrid class, extends Grid with additional offset vector information '''
def __init__(self, rectifiedgrid):
super(RectifiedGrid,self).__init__(rectifiedgrid)
self.origin=rectifiedgrid.find('{http://www.opengis.net/gml/3.2}origin/{http://www.opengis.net/gml/3.2}Point/{http://www.opengis.net/gml/3.2}pos').text.split()
self.offsetvectors=[]
for offset in rectifiedgrid.findall('{http://www.opengis.net/gml/3.2}offsetVector'):
self.offsetvectors.append(offset.text.split())
class ReferenceableGridByVectors(Grid):
''' ReferenceableGridByVectors class, extends Grid with additional vector information '''
def __init__(self, refereceablegridbyvectors):
super(ReferenceableGridByVectors,self).__init__(refereceablegridbyvectors)
self.origin=refereceablegridbyvectors.find('{http://www.opengis.net/gml/3.3/rgrid}origin/{http://www.opengis.net/gml/3.2}Point/{http://www.opengis.net/gml/3.2}pos').text.split()
self.offsetvectors=[]
for offset in refereceablegridbyvectors.findall('{http://www.opengis.net/gml/3.3/rgrid}generalGridAxis/{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}offsetVector'):
self.offsetvectors.append(offset.text.split())
class AxisDescription(object):
''' Class to represent the AxisDescription element optionally found as part of the RangeSet and used to
define ordinates of additional dimensions such as wavelength bands or pressure levels'''
def __init__(self, axisdescElem):
self.name=self.label=None
self.values=[]
for elem in axisdescElem.getchildren():
if elem.tag == ns('name'):
self.name = elem.text
elif elem.tag == ns('label'):
self.label = elem.text
elif elem.tag == ns('values'):
for child in elem.getchildren():
self.values.append(child.text)
# -*- coding: ISO-8859-15 -*-
# =============================================================================
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Oliver Clements <olcl@pml.ac.uk>
#
# Contact email: olcl@pml.ac.uk
# =============================================================================
##########NOTE: Does not conform to new interfaces yet #################
from __future__ import (absolute_import, division, print_function)
from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.ows import OwsCommon, ServiceIdentification, ServiceProvider, OperationsMetadata
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
from owslib.util import openURL, testXMLValue
from owslib.etree import etree
from owslib.crs import Crs
import os, errno
import dateutil.parser as parser
from datetime import timedelta
import logging
from owslib.util import log, datetime_from_ansi, datetime_from_iso
# function to save writing out WCS namespace in full each time
def ns(tag):
return '{http://www.opengis.net/ows/2.0}'+tag
def nsWCS2(tag):
return '{http://www.opengis.net/wcs/2.0}'+tag
class WebCoverageService_2_0_1(WCSBase):
"""Abstraction for OGC Web Coverage Service (WCS), version 2.0.1
Implements IWebCoverageService.
"""
def __getitem__(self,name):
''' check contents dictionary to allow dict like access to service layers'''
if name in self.__getattribute__('contents').keys():
return self.__getattribute__('contents')[name]
else:
raise KeyError("No content named %s" % name)
def __init__(self,url,xml, cookies):
self.version='2.0.1'
self.url = url
self.cookies=cookies
self.ows_common = OwsCommon(version='2.0.1')
# initialize from saved capability document or access the server
reader = WCSCapabilitiesReader(self.version, self.cookies)
if xml:
self._capabilities = reader.readString(xml)
else:
self._capabilities = reader.read(self.url)
# check for exceptions
se = self._capabilities.find('ServiceException')
if se is not None:
err_message = str(se.text).strip()
raise ServiceException(err_message, xml)
#serviceIdentification metadata
subelem=self._capabilities.find(ns('ServiceIdentification'))
self.identification=ServiceIdentification(subelem, namespace=self.ows_common.namespace)
#serviceProvider metadata
serviceproviderelem=self._capabilities.find(ns('ServiceProvider'))
self.provider=ServiceProvider(serviceproviderelem, namespace=self.ows_common.namespace)
#serviceOperations metadata
self.operations=[]
for elem in self._capabilities.find(ns('OperationsMetadata'))[:]:
if elem.tag !=ns('ExtendedCapabilities'):
self.operations.append(OperationsMetadata(elem, namespace=self.ows_common.namespace))
#serviceContents metadata
self.contents={}
for elem in self._capabilities.findall(nsWCS2('Contents/')+nsWCS2('CoverageSummary')):
cm=ContentMetadata(elem, self)
self.contents[cm.id]=cm
#exceptions
self.exceptions = [f.text for f \
in self._capabilities.findall('Capability/Exception/Format')]
def items(self):
'''supports dict-like items() access'''
items=[]
for item in self.contents:
items.append((item,self.contents[item]))
return items
def __makeString(self,value):
#using repr unconditionally breaks things in some circumstances if a value is already a string
if type(value) is not str:
sval=repr(value)
else:
sval = value
return sval
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
def is_number(self,s):
"""simple helper to test if value is number as requests with numbers dont
need quote marks
"""
try:
float(s)
return True
except ValueError:
return False
def getOperationByName(self, name):
"""Return a named operation item."""
for item in self.operations:
if item.name == name:
return item
raise KeyError("No operation named %s" % name)
class ContentMetadata(object):
"""
Implements IContentMetadata
"""
def __init__(self, elem, service):
"""Initialize. service is required so that describeCoverage requests may be made"""
#TODO - examine the parent for bounding box info.
self._elem=elem
self._service=service
self.id=elem.find(nsWCS2('CoverageId')).text
self.title = testXMLValue(elem.find(ns('label')))
self.abstract= testXMLValue(elem.find(ns('description')))
self.keywords = [f.text for f in elem.findall(ns('keywords')+'/'+ns('keyword'))]
self.boundingBox=None #needed for iContentMetadata harmonisation
self.boundingBoxWGS84 = None
b = elem.find(ns('lonLatEnvelope'))
if b is not None:
gmlpositions=b.findall('{http://www.opengis.net/gml}pos')
lc=gmlpositions[0].text
uc=gmlpositions[1].text
self.boundingBoxWGS84 = (
float(lc.split()[0]),float(lc.split()[1]),
float(uc.split()[0]), float(uc.split()[1]),
)
#others not used but needed for iContentMetadata harmonisation
self.styles=None
self.crsOptions=None
self.defaulttimeposition=None
#grid is either a gml:Grid or a gml:RectifiedGrid if supplied as part of the DescribeCoverage response.
def _getGrid(self):
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
gridelem= self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.3/rgrid}ReferenceableGridByVectors')
if gridelem is not None:
grid=ReferenceableGridByVectors(gridelem)
else:
# HERE I LOOK FOR RECTIFIEDGRID
gridelem=self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.2}RectifiedGrid')
grid=RectifiedGrid(gridelem)
return grid
grid=property(_getGrid, None)
#timelimits are the start/end times, timepositions are all timepoints. WCS servers can declare one or both or neither of these.
# in wcs 2.0 this can be gathered from the Envelope tag
def _getTimeLimits(self):
# timepoints, timelimits=[],[]
# b=self._elem.find(ns('lonLatEnvelope'))
# if b is not None:
# timepoints=b.findall('{http://www.opengis.net/gml}timePosition')
# else:
# #have to make a describeCoverage request...
# if not hasattr(self, 'descCov'):
# self.descCov=self._service.getDescribeCoverage(self.id)
# for pos in self.descCov.findall(ns('CoverageOffering/')+ns('domainSet/')+ns('temporalDomain/')+'{http://www.opengis.net/gml}timePosition'):
# timepoints.append(pos)
# if timepoints:
# timelimits=[timepoints[0].text,timepoints[1].text]
return [self.timepositions[0],self.timepositions[-1]]
timelimits=property(_getTimeLimits, None)
def _getTimePositions(self):
timepositions=[]
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
gridelem= self.descCov.find(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}domainSet/'+'{http://www.opengis.net/gml/3.3/rgrid}ReferenceableGridByVectors')
if gridelem is not None:
# irregular time axis
cooeficients = []
grid_axes = gridelem.findall('{http://www.opengis.net/gml/3.3/rgrid}generalGridAxis')
for elem in grid_axes:
if elem.find('{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}gridAxesSpanned').text in ["ansi", "unix"]:
cooeficients = elem.find('{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}coefficients').text.split(' ')
for x in cooeficients:
x = x.replace('"', '')
t_date = datetime_from_iso(x)
timepositions.append(t_date)
else:
# regular time
if(len(self.grid.origin)>2):
t_grid = self.grid
t_date = t_grid.origin[2]
start_pos = parser.parse(t_date, fuzzy=True)
step = float(t_grid.offsetvectors[2][2])
start_pos = start_pos + timedelta(days=(step/2))
no_steps = int(t_grid.highlimits[2])
for x in range(no_steps):
t_pos = start_pos + timedelta(days=(step * x))
#t_date = datetime_from_ansi(t_pos)
#t_date = t_pos.isoformat()
timepositions.append(t_pos)
else:
# no time axis
timepositions = None
return timepositions
timepositions=property(_getTimePositions, None)
def _getOtherBoundingBoxes(self):
''' incomplete, should return other bounding boxes not in WGS84
#TODO: find any other bounding boxes. Need to check for gml:EnvelopeWithTimePeriod.'''
bboxes=[]
if not hasattr(self, 'descCov'):
self.descCov=self._service.getDescribeCoverage(self.id)
for envelope in self.descCov.findall(nsWCS2('CoverageDescription/')+'{http://www.opengis.net/gml/3.2}boundedBy/'+'{http://www.opengis.net/gml/3.2}Envelope'):
bbox = {}
bbox['nativeSrs'] = envelope.attrib['srsName']
lc = envelope.find('{http://www.opengis.net/gml/3.2}lowerCorner')
lc =lc.text.split()
uc = envelope.find('{http://www.opengis.net/gml/3.2}upperCorner')
uc =uc.text.split()
bbox['bbox'] = (
float(lc[0]),float(lc[1]),
float(uc[0]), float(uc[1])
)
bboxes.append(bbox)
return bboxes
boundingboxes=property(_getOtherBoundingBoxes,None)
def _getSupportedCRSProperty(self):
# gets supported crs info
crss=[]
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('responseCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('requestResponseCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('supportedCRSs/')+ns('nativeCRSs')):
for crs in elem.text.split(' '):
crss.append(Crs(crs))
return crss
supportedCRS=property(_getSupportedCRSProperty, None)
def _getSupportedFormatsProperty(self):
# gets supported formats info
frmts =[]
for elem in self._service._capabilities.findall(nsWCS2('ServiceMetadata/')+nsWCS2('formatSupported')):
frmts.append(elem.text)
return frmts
supportedFormats=property(_getSupportedFormatsProperty, None)
def _getAxisDescriptionsProperty(self):
#gets any axis descriptions contained in the rangeset (requires a DescribeCoverage call to server).
axisDescs =[]
for elem in self._service.getDescribeCoverage(self.id).findall(ns('CoverageOffering/')+ns('rangeSet/')+ns('RangeSet/')+ns('axisDescription/')+ns('AxisDescription')):
axisDescs.append(AxisDescription(elem)) #create a 'AxisDescription' object.
return axisDescs
axisDescriptions=property(_getAxisDescriptionsProperty, None)
#Adding classes to represent gml:grid and gml:rectifiedgrid. One of these is used for the cvg.grid property
#(where cvg is a member of the contents dictionary)
#There is no simple way to convert the offset values in a rectifiedgrid grid to real values without CRS understanding, therefore this is beyond the current scope of owslib, so the representation here is purely to provide access to the information in the GML.
class Grid(object):
''' Simple grid class to provide axis and value information for a gml grid '''
def __init__(self, grid):
self.axislabels = []
self.dimension=None
self.lowlimits=[]
self.highlimits=[]
if grid is not None:
self.dimension=int(grid.get('dimension'))
self.lowlimits= grid.find('{http://www.opengis.net/gml/3.2}limits/{http://www.opengis.net/gml/3.2}GridEnvelope/{http://www.opengis.net/gml/3.2}low').text.split(' ')
self.highlimits = grid.find('{http://www.opengis.net/gml/3.2}limits/{http://www.opengis.net/gml/3.2}GridEnvelope/{http://www.opengis.net/gml/3.2}high').text.split(' ')
for axis in grid.findall('{http://www.opengis.net/gml/3.2}axisLabels')[0].text.split(' '):
self.axislabels.append(axis)
class RectifiedGrid(Grid):
''' RectifiedGrid class, extends Grid with additional offset vector information '''
def __init__(self, rectifiedgrid):
super(RectifiedGrid,self).__init__(rectifiedgrid)
self.origin=rectifiedgrid.find('{http://www.opengis.net/gml/3.2}origin/{http://www.opengis.net/gml/3.2}Point/{http://www.opengis.net/gml/3.2}pos').text.split()
self.offsetvectors=[]
for offset in rectifiedgrid.findall('{http://www.opengis.net/gml/3.2}offsetVector'):
self.offsetvectors.append(offset.text.split())
class ReferenceableGridByVectors(Grid):
''' ReferenceableGridByVectors class, extends Grid with additional vector information '''
def __init__(self, refereceablegridbyvectors):
super(ReferenceableGridByVectors,self).__init__(refereceablegridbyvectors)
self.origin=refereceablegridbyvectors.find('{http://www.opengis.net/gml/3.3/rgrid}origin/{http://www.opengis.net/gml/3.2}Point/{http://www.opengis.net/gml/3.2}pos').text.split()
self.offsetvectors=[]
for offset in refereceablegridbyvectors.findall('{http://www.opengis.net/gml/3.3/rgrid}generalGridAxis/{http://www.opengis.net/gml/3.3/rgrid}GeneralGridAxis/{http://www.opengis.net/gml/3.3/rgrid}offsetVector'):
self.offsetvectors.append(offset.text.split())
class AxisDescription(object):
''' Class to represent the AxisDescription element optionally found as part of the RangeSet and used to
define ordinates of additional dimensions such as wavelength bands or pressure levels'''
def __init__(self, axisdescElem):
self.name=self.label=None
self.values=[]
for elem in axisdescElem.getchildren():
if elem.tag == ns('name'):
self.name = elem.text
elif elem.tag == ns('label'):
self.label = elem.text
elif elem.tag == ns('values'):
for child in elem.getchildren():
self.values.append(child.text)