def main(): try: from owslib.ogcapi.features import Features except: grass.fatal( _("OSWLib was not found. Install OSWLib (http://geopython.github.com/OWSLib/)." )) feats = Features(options["url"]) collections = feats.feature_collections() if flags["l"]: for coll in collections: print("{}".format(coll)) return if not options["layer"]: grass.fatal( _("Required parameter <layer> not set: (Name for input vector map layer)" )) elif options["layer"] not in collections: grass.fatal(_("Layer {} is not a Feature layer")) if not options["output"]: grass.fatal( _("Required parameter <output> not set: (Name for output vector map)" )) try: layer = feats.collection_items(options["layer"]) except Exception as e: grass.fatal( _("Problem retrieving data from the server. The error was: {}". format(e))) tmpfile = grass.tempfile() with open(tmpfile, "w") as f: json.dump(layer, f, indent=4) grass.run_command("v.import", input=tmpfile, output=options["output"])
def test_ogcapi_features_ldproxy(): w = Features(SERVICE_URL) assert w.url == 'https://www.ldproxy.nrw.de/rest/services/kataster/' assert w.url_query_string == 'f=json' conformance = w.conformance() assert len(conformance['conformsTo']) == 5 feature_collections = w.feature_collections() assert len(feature_collections) >= 0 # TODO: remove pytest.raises once ldproxy is fixed/updated with pytest.raises(RuntimeError): api = w.api() assert api['components']['parameters'] is not None assert api['paths'] is not None
def test_ogcapi_features_pygeoapi(): w = Features(SERVICE_URL) assert w.url == 'https://demo.pygeoapi.io/master/' assert w.url_query_string is None api = w.api() assert api['components']['parameters'] is not None paths = api['paths'] assert paths is not None assert paths['/collections/lakes'] is not None conformance = w.conformance() assert len(conformance['conformsTo']) == 17 collections = w.collections() assert len(collections) > 0 feature_collections = w.feature_collections() assert len(feature_collections) > 0 lakes = w.collection('lakes') assert lakes['id'] == 'lakes' assert lakes['title'] == 'Large Lakes' assert lakes['description'] == 'lakes of the world, public domain' #lakes_queryables = w.collection_queryables('lakes') #assert len(lakes_queryables['queryables']) == 6 # Minimum of limit param is 1 with pytest.raises(RuntimeError): lakes_query = w.collection_items('lakes', limit=0) lakes_query = w.collection_items('lakes', limit=1, admin='admin-0') assert lakes_query['numberMatched'] == 25 assert lakes_query['numberReturned'] == 1 assert len(lakes_query['features']) == 1