示例#1
0
def test_wps_request3():
    # Supply process input arguments
    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://igsarm-cida-thredds1.er.usgs.gov:8080/thredds/dodsC/dcp/conus_grid.w_meta.ncml"),
              ("DATASET_ID", "ccsm3_a1b_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", "false"),
              ("SUMMARIZE_FEATURE_ATTRIBUTE", "false"),
              ("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_USGSExecuteRequest3.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
    print 'Process input:'
    printInputOutput(input, indent='\t')
for output in process.processOutputs:
    print 'Process output:'
    printInputOutput(output, indent='\t')

# 3a) Execute
# Submits an HTTP POST "Execute" process request to the WPS service, keeps checking the status of the request,
# and retrieves the output once the request terminates successfully (displaying any errors if found).
# This request uses a FEATURE_COLLECTION input obtained from a live WFS service.
#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)
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")