Skip to content

Instantly share code, notes, and snippets.

@lukecampbell
Created August 29, 2016 15:18
Show Gist options
  • Save lukecampbell/0586ecb81c6ce08d9ae2c4285a6f38c7 to your computer and use it in GitHub Desktop.
Save lukecampbell/0586ecb81c6ce08d9ae2c4285a6f38c7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"nbformat_minor": 0, "cells": [{"execution_count": 70, "cell_type": "code", "source": "from owslib.csw import CatalogueServiceWeb\nfrom owslib.fes import SortBy, SortProperty\nfrom owslib import fes\nimport datetime as dt", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 79, "cell_type": "code", "source": "#csw = CatalogueServiceWeb('http://www.ngdc.noaa.gov/geoportal/csw',timeout=60) # NGDC Geoportal\ncsw = CatalogueServiceWeb('https://dev-catalog.ioos.us/csw',timeout=60)\n#csw = CatalogueServiceWeb('http://192.168.99.100:8081/',timeout=60)", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 80, "cell_type": "code", "source": "# adjust to match MaxRecordDefault of CSW, if would be cleaner if we pick this up Capabilities XML\n# this issue will allow for this: https://github.com/geopython/OWSLib/issues/211\npagesize = 10\nsort_property = 'dc:title' # a supported queryable of the CSW\nsort_order = 'ASC' # should be 'ASC' or 'DESC'", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 81, "cell_type": "code", "source": "sortby = SortBy([SortProperty(sort_property, sort_order)])\nfoo=sortby.properties", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 82, "cell_type": "code", "source": "# hopefully something like this will be implemented in fes soon\ndef dateRange(start_date, stop_date, constraint='overlaps'):\n start_date = start_date.strftime('%Y-%m-%d %H:00')\n stop_date = stop_date.strftime('%Y-%m-%d %H:00')\n if constraint == 'overlaps':\n start = fes.PropertyIsLessThanOrEqualTo(propertyname='apiso:TempExtent_begin', literal=stop_date)\n stop = fes.PropertyIsGreaterThanOrEqualTo(propertyname='apiso:TempExtent_end', literal=start_date)\n elif constraint == 'within':\n start = fes.PropertyIsGreaterThanOrEqualTo(propertyname='apiso:TempExtent_begin', literal=start_date)\n stop = fes.PropertyIsLessThanOrEqualTo(propertyname='apiso:TempExtent_end', literal=stop_date)\n return start,stop", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 83, "cell_type": "code", "source": "start, stop = dateRange(dt.datetime(2014, 12, 1, 16, 43), dt.datetime(2016, 12, 10, 16, 43))\nfilter1 = fes.PropertyIsLike(propertyname='apiso:AnyText',literal=('*G1SST*'),\n escapeChar='\\\\',wildCard='*',singleChar='?')", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 84, "cell_type": "code", "source": "filter_list = [fes.And([filter1, start, stop])]\ncsw.getrecords2(constraints=filter_list)\ncsw.results['matches']", "outputs": [{"execution_count": 84, "output_type": "execute_result", "data": {"text/plain": "1"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.10", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment