Пример #1
0
def test_wps_request3():
    # Supply process input argument
    wfsUrl = "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)
    processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
    inputs = [
        ("FEATURE_ATTRIBUTE_NAME", "STATE"),
        ("DATASET_URI",
         "dods://igsarm-cida-thredds1.er.usgs.gov:8080/thredds/dodsC/dcp/conus_grid.w_meta.ncml"
         ), ("DATASET_ID", "ccsm3_a1b_tmax"), ("DATASET_ID", "ccsm3_a1b_pr"),
        ("DATASET_ID", "ccsm3_a1fi_tmax"),
        ("TIME_START", "1960-01-01T00:00:00.000Z"),
        ("TIME_END", "1960-12-31T00:00:00.000Z"),
        ("REQUIRE_FULL_COVERAGE", "true"), ("DELIMITER", "COMMA"),
        ("STATISTICS", "MEAN"), ("STATISTICS", "MINIMUM"),
        ("STATISTICS", "MAXIMUM"), ("STATISTICS", "WEIGHT_SUM"),
        ("STATISTICS", "VARIANCE"), ("STATISTICS", "STD_DEV"),
        ("STATISTICS", "COUNT"), ("GROUP_BY", "STATISTIC"),
        ("SUMMARIZE_TIMESTEP", "true"),
        ("SUMMARIZE_FEATURE_ATTRIBUTE", "true"),
        ("FEATURE_COLLECTION", featureCollection)
    ]
    output = "OUTPUT"

    # build XML request for WPS process execution
    execution = WPSExecution()
    requestElement = execution.buildRequest(processid, inputs, output=output)
    request = etree.tostring(requestElement)

    # Compare to cached XML request
    _request = open(resource_file('wps_USGSExecuteRequest2.xml'), 'rb').read()
    assert compare_xml(request, _request) is True
Пример #2
0
def _getFeatureCollectionGeoType(geoType, attribute, value, gmlIDs, wfs_url):
    """
    This function returns a featurecollection. It takes a geotype and determines if
    the geotype is a shapfile or polygon.

    If value is set to None, a FeatureCollection with all features will be returned.

    """

    # This is a polygon
    if isinstance(geoType, list):
        return GMLMultiPolygonFeatureCollection([geoType])
    elif isinstance(geoType, str):
        if value is None:
            if gmlIDs is None:
                # Using an empty gmlIDs element results in all features being returned to the constructed WFS query.
                gmlIDs = []
                print('All shapefile attributes will be used.')

        tmp_id = []

        if gmlIDs is None:
            if type(value) == type(tmp_id):
                gmlIDs = []

                for v in value:
                    tuples = shapefile_id_handle.getTuples(geoType,
                                                           attribute,
                                                           wfs_url=wfs_url)
                    tmp_id = shapefile_id_handle._getFilterID(tuples, v)
                    gmlIDs = gmlIDs + tmp_id
                print(tmp_id)

                if not tmp_id:
                    raise Exception(
                        "Didn't find any features matching given attribute values."
                    )
            else:
                tuples = shapefile_id_handle.getTuples(geoType,
                                                       attribute,
                                                       wfs_url=wfs_url)
                gmlIDs = shapefile_id_handle._getFilterID(tuples, value)
                if not gmlIDs:
                    raise Exception(
                        "Didn't find any features matching given attribute value."
                    )

        geometry_attribute = 'the_geom'
        if 'arcgis' in wfs_url.lower():
            geometry_attribute = 'Shape'

        query = WFSQuery(geoType,
                         propertyNames=[geometry_attribute, attribute],
                         filters=gmlIDs)

        return WFSFeatureCollection(wfs_url, query)
    else:
        raise Exception(
            'Geotype is not a shapefile or a recognizable polygon.')
Пример #3
0
    def _getFeatureCollectionGeoType(self,
                                     geoType,
                                     attribute='the_geom',
                                     value=None,
                                     gmlIDs=None):
        """
        This function returns a featurecollection. It takes a geotype and determines if
        the geotype is a shapfile or polygon.
        """

        # This is a polygon
        if isinstance(geoType, list):
            return GMLMultiPolygonFeatureCollection([geoType])
        elif isinstance(geoType, str):
            if value == None and gmlIDs == None:
                print 'must input a value and attribute for shapefile'
                return
            else:
                tmpID = []
                if gmlIDs is None:
                    if type(value) == type(tmpID):
                        gmlIDs = []
                        for v in value:
                            tuples = self.getTuples(geoType, attribute)
                            tmpID = self._getFilterID(tuples, v)
                            gmlIDs = gmlIDs + tmpID
                    else:
                        tuples = self.getTuples(geoType, attribute)
                        gmlIDs = self._getFilterID(tuples, value)

                query = WFSQuery(geoType,
                                 propertyNames=["the_geom", attribute],
                                 filters=gmlIDs)
                return WFSFeatureCollection(WFS_URL, query)
        else:
            print 'Geotype is not a shapefile or a recognizable polygon.'
            return None
Пример #4
0
     "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")

from owslib.wps import monitorExecution
monitorExecution(execution)

# Alternatively, define the feature through an embedded query to a WFS server:
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)

# You can also submit a pre-made request encoded as WPS XML:
request = open(
    '/Users/cinquini/Documents/workspace-cog/wps/tests/resources/wps_USGSExecuteRequest1.xml',
    'rb').read()
execution = wps.execute(None, [], request=request)

monitorExecution(execution)