Skip to content

Instantly share code, notes, and snippets.

@epifanio
Created December 18, 2023 11:38
Show Gist options
  • Save epifanio/76394c59f5eeb2cd2fc6ea70ec1705a4 to your computer and use it in GitHub Desktop.
Save epifanio/76394c59f5eeb2cd2fc6ea70ec1705a4 to your computer and use it in GitHub Desktop.
csw_test_endpoint = "https://nbs.csw.met.no"
ElementSetName = "full"
field_to_query = "title"
text_to_query = '*1A_EW*'
start_time = "2022-10-01 00:00"
end_time = "2022-10-07 00:00"
lowerCorner = "-25 70"
upperCorner = "50 85"
from geolinks import sniff_link
from owslib.csw import CatalogueServiceWeb
from owslib.fes import (
And,
BBox,
Or,
PropertyIsEqualTo,
PropertyIsGreaterThanOrEqualTo,
PropertyIsLessThanOrEqualTo,
PropertyIsLike,
)
csw = CatalogueServiceWeb(csw_test_endpoint, timeout=60)
# Create filters
text_filter = PropertyIsLike(
propertyname="apiso:AnyText",
literal=f"{text_to_query}",
wildCard="*",
singleChar="?",
escapeChar="\\",
)
bbox_filter = BBox(lowerCorner.split() + upperCorner.split())
time_filter1 = PropertyIsLessThanOrEqualTo(
propertyname="apiso:TempExtent_begin", literal=f"{end_time}"
)
time_filter2 = PropertyIsGreaterThanOrEqualTo(
propertyname="apiso:TempExtent_end", literal=f"{start_time}"
)
# Combine filters
filter = And([text_filter, bbox_filter, time_filter1, time_filter2])
# Use the filter in a CSW getrecords request
csw.getrecords2(
constraints=[filter],
esn=f"{ElementSetName}",
startposition=1,
maxrecords=5,
)
csw.results['matches']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment