Exemple #1
0
    def test_recursive(self):
        """Test a location filter expression using a recursive expression
        with And(Not(WithinDistance(Point) filter.

        Test whether the generated XML is correct.

        """
        point_and_box = And([
            Not([WithinDistance(Point(150000, 150000), 100)]),
            Within(Box(94720, 186910, 112220, 202870))
        ])
        xml = set_geometry_column(point_and_box, 'geom')

        assert clean_xml(etree.tostring(xml).decode('utf8')) == clean_xml(
            '<ogc:And><ogc:Not><ogc:DWithin><ogc:PropertyName>geom</ogc'
            ':PropertyName><gml:Point srsDimension="2" '
            'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml'
            ':pos>150000.000000 '
            '150000.000000</gml:pos></gml:Point><gml:Distance '
            'units="meter">100.000000</gml:Distance></ogc:DWithin></ogc:Not'
            '><ogc:Within><ogc:PropertyName>geom</ogc:PropertyName><gml'
            ':Envelope srsDimension="2" '
            'srsName="http://www.opengis.net/gml/srs/epsg.xml#31370"><gml'
            ':lowerCorner>94720.000000 '
            '186910.000000</gml:lowerCorner><gml:upperCorner>112220.000000 '
            '202870.000000</gml:upperCorner></gml:Envelope></ogc:Within'
            '></ogc:And>')
Exemple #2
0
    def get_wfs_features(self, filter_list, propertyname='*'):
        """Query the file index WFS layer with the given filters and return a list of features.

        :param filter_list: list of filters to apply (owslib.fes.OgcExpression instances)
        :param propertyname: str or list or property name(s) to return
        :return: list of features from the parsed GetFeature response
        """

        ogc_filter = ogc_filter_to_string(And(filter_list))
        wfs_response = self.state_query.query_wfs_getfeature_dict(
            typename=[self.FILE_INDEX_LAYER],
            filter=ogc_filter,
            propertyname=propertyname)
        if not wfs_response or 'features' not in wfs_response:
            raise PipelineSystemError(
                "Invalid WFS response received from '{wfs_url}'".format(
                    wfs_url=self.config.pipeline_config['global'].get(
                        'wfs_url')))

        return wfs_response['features']
Exemple #3
0
    def search(self,
               location=None,
               query=None,
               sort_by=None,
               return_fields=None,
               max_features=None):
        """Search for objects of this type. Provide `location` and/or
        `query` and/or `max_features`.
        When `return_fields` is None, all fields are returned.

        Excludes 'empty' filters (i.e. Putten without Filters) by extending
        the `query` with a not-null check on pkey_filter.

        Parameters
        ----------
        location : pydov.util.location.AbstractLocationFilter or \
                   owslib.fes.BinaryLogicOpType<AbstractLocationFilter> or \
                   owslib.fes.UnaryLogicOpType<AbstractLocationFilter>
            Location filter limiting the features to retrieve. Can either be a
            single instance of a subclass of AbstractLocationFilter, or a
            combination using And, Or, Not of AbstractLocationFilters.
        query : owslib.fes.OgcExpression
            OGC filter expression to use for searching. This can contain any
            combination of filter elements defined in owslib.fes. The query
            should use the fields provided in `get_fields()`. Note that not
            all fields are currently supported as a search parameter.
        sort_by : owslib.fes.SortBy, optional
            List of properties to sort by.
        return_fields : list<str> or tuple<str> or set<str>
            A list of fields to be returned in the output data. This should
            be a subset of the fields provided in `get_fields()`. Note that
            not all fields are currently supported as return fields.
        max_features : int
            Limit the maximum number of features to request.

        Returns
        -------
        pandas.core.frame.DataFrame
            DataFrame containing the output of the search query.

        Raises
        ------
        pydov.util.errors.InvalidSearchParameterError
            When not one of `location` or `query` or `max_features` is
            provided.

        pydov.util.errors.InvalidFieldError
            When at least one of the fields in `return_fields` is unknown.

            When a field that is only accessible as return field is used as
            a query parameter.

            When a field that can only be used as a query parameter is used as
            a return field.

        pydov.util.errors.FeatureOverflowError
            When the number of features to be returned is equal to the
            maxFeatures limit of the WFS server.

        AttributeError
            When the argument supplied as return_fields is not a list,
            tuple or set.

        NotImplementedError
            This is an abstract method that should be implemented in a
            subclass.

        """
        self._pre_search_validation(location, query, sort_by, return_fields,
                                    max_features)

        exclude_empty_filters = Not(
            [PropertyIsNull(propertyname='pkey_filter')])

        if query is not None:
            query = And([query, exclude_empty_filters])
        else:
            query = exclude_empty_filters

        fts = self._search(location=location,
                           query=query,
                           sort_by=sort_by,
                           return_fields=return_fields,
                           max_features=max_features)

        gw_filters = self._type.from_wfs(fts, self.__wfs_namespace)

        df = pd.DataFrame(data=self._type.to_df_array(gw_filters,
                                                      return_fields),
                          columns=self._type.get_field_names(return_fields))

        return df
Exemple #4
0
from owslib.csw import CatalogueServiceWeb
cenia = CatalogueServiceWeb('http://geoportal.gov.cz/php/micka/csw/index.php')
print (cenia.service)

cenia.getrecords2()
print (cenia.results)

for rec in cenia.records:
    print (cenia.records[rec].title)

from owslib.fes import PropertyIsLike, BBox, And, PropertyIsEqualTo
wms_query = PropertyIsEqualTo('csw:AnyText', 'WMS')
praha_query = BBox([14.22,49.94,14.71,50.18])
praha_and_wms = And([praha_query, wms_query])
cenia.getrecords2([praha_and_wms], esn='full')
print (cenia.results)

for recid in cenia.records:
    record = cenia.records[recid]
    print (u'{}: {} {} {} {}'.format(record.title, record.bbox.minx, record.bbox.miny,
                                     record.bbox.maxx, record.bbox.maxy))

zm_query = PropertyIsEqualTo('csw:AnyText', 'ZM10')
cenia.getrecords2([zm_query], esn='full')
zm10 = cenia.records['CZ-CUZK-WMS-ZM10-P']
print (zm10.type)

print (u'{}\n{}'.format(zm10.title, zm10.abstract))

url = zm10.references[0]['url']
# vumop.getrecords2()
# print(vumop.results)

cenia = WCS("http://geoportal.gov.cz/php/micka/csw/index.php")
cenia.getrecords2()
print(cenia.results)

for rec in cenia.records:
    print(cenia.records[rec].title)
print("_" * 45)

# filtrovani seznamu
from owslib.fes import PropertyIsLike, BBox, And, PropertyIsEqualTo
wms_query = PropertyIsEqualTo('csw:AnyText', 'WMS')
praha_query = BBox([14.22, 49.94, 14.71, 50.18])
praha_and_wms = And([praha_query, wms_query])
cenia.getrecords2([praha_and_wms], esn='full')
print(cenia.results)
print("_" * 45)

for recid in cenia.records:
    record = cenia.records[recid]
    print(u'{}: {} {} {} {}'.format(record.title, record.bbox.minx,
                                    record.bbox.miny, record.bbox.maxx,
                                    record.bbox.maxy))
print("_" * 45)

zm_query = PropertyIsEqualTo('csw:AnyText', '%ZM10%')
cenia.getrecords2([zm_query], esn='full')
zm10 = cenia.records['CZ-CUZK-WMS-ZM10-P']
print(zm10.type)