Ejemplo n.º 1
0
    def get_ingest(self,
                   options=dict()):
        """Does a GET request to /ws/admin/ingest.

        A webservice to ingest all or a CSV list of data resources into the
        biocache. An ingest will perform all the steps required to publish a
        data resource to the biocache.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    api_key -- string -- An apiKey to use to perform the task.
                        Only validated api keys will be allowed to perform
                        this action.
                    dr -- string -- An optional CSV param that supports a list
                        of one of more data resources to ingest

        Returns:
            void: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/admin/ingest"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "apiKey": options.get('api_key', None),
            "dr": options.get('dr', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
Ejemplo n.º 2
0
    def get_deleted_occurrences(self,
                                date):
        """Does a GET request to /ws/occurrence/deleted.

        Returns the records uuids that have been deleted since the supplied
        date inclusive. Records will be deleted if they have been erroneously
        added as duplicates, or for datasets that require a full reload due to
        a lack of consistent identifiers within the dataset.

        Args:
            date (string): Date in "yyyy-MM-dd" format

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrence/deleted"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "date": date
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 3
0
    def get_compare_original_vs_processed(self,
                                          uuid):
        """Does a GET request to /ws/occurrence/compare/{UUID}.

        Compare the original record to the processed (interpreted) version of
        the record.

        Args:
            uuid (string): The identifier for the record.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrence/compare/{UUID}"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "UUID": uuid
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 4
0
    def get_occurrence_indexed_fields(self):
        """Does a GET request to /ws/index/fields.

        List in JSON the index fields within the occurrence store

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/index/fields"

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
    def resolve_names(self):
        """Creates a dictionary representation of this object.
        
        This method converts an object to a dictionary that represents the
        format that the model should be in when passed into an API Request.
        Because of this, the generated dictionary may have different
        property names to that of the model itself.
        
        Returns:
            dict: The dictionary representing the object.
        
        """
        # Create a mapping from Model property names to API property names
        replace_names = {
            "stored": "stored",
            "indexed": "indexed",
            "description": "description",
            "data_type": "dataType",
            "name": "name",
        }

        retval = dict()

        return APIHelper.resolve_names(self, replace_names, retval)
Ejemplo n.º 6
0
    def get_occurrence_facet_download(self,
                                      options=dict()):
        """Does a GET request to /ws/occurrences/facets/download.

        CSV download of a facet. In addition to the parameters listed, range
        based faceting is supported by using the SOLR parameters.  The facets,
        q and fq values support the stored & indexed fields

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    facets -- string -- eg. species_guid
                    fq -- list of string -- additional filters. eg.
                        fq=state_conservation:Endangered
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrences/facets/download"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "facets": options.get('facets', None),
            "fq": options.get('fq', None),
            "q": options.get('q', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 7
0
    def create_occurrence_query_cache(self,
                                      options=dict()):
        """Does a POST request to /ws/webportal/params.

        Add query details to a cache to reduce the size of the query params
        that are being passed around. This is particularly useful if you
        requests are too large for a GET.  Returns a text identification for
        the query that has been cached. This identification can be used as
        part of the value for a search q. ie q=qid:

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    fq -- string -- Filters to be applied to the original
                        query. These are additional params of the form
                        fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    wkt -- string -- The polygon area in which to limit
                        records.

        Returns:
            string: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/webportal/params"

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare parameters
        parameters = {
            "fq": options.get('fq', None),
            "q": options.get('q', None),
            "wkt": options.get('wkt', None)
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.post(query_url, headers=headers, params=parameters)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 8
0
    def retrieve_geojson_cluster_for_group(self,
                                           options=dict()):
        """Does a GET request to /ws/geojson/radius-points.

        Supports the additional parameters pageSize, start, sort, dir - to
        allow paging through the results

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    dir -- string -- dir
                    fq -- list of string -- The filter query
                    group -- string -- Species group
                    lat -- double -- The latitude to limit the query by (must
                        be used with lon and radius)
                    lon -- double -- The longitude to limit the query by (must
                        be used with lat and radius)
                    page_size -- int -- Number of records to return
                    q -- string -- The query which defaults to : when not
                        supplied
                    radius -- string -- The radius in km to limit the search
                        to. must be used with lat and lon.
                    sort -- string -- sort
                    start -- int -- Record offset, to enable paging

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/geojson/radius-points"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "dir": options.get('dir', None),
            "fq": options.get('fq', None),
            "group": options.get('group', None),
            "lat":  options.get('lat', None) if options.get('lat', None) is not None else -41.290817,
            "lon":  options.get('lon', None) if options.get('lon', None) is not None else 174.753377,
            "pageSize": options.get('page_size', None),
            "q": options.get('q', None),
            "radius":  options.get('radius', None) if options.get('radius', None) is not None else "20",
            "sort": options.get('sort', None),
            "start": options.get('start', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 9
0
    def get_scatterplot_image(self,
                              options=dict()):
        """Does a GET request to /ws/scatterplot.

        Return an image for occurrences and two environmental layers as a
        scatterplot.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    q -- string --   Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    x -- string --   Environmental layer for the X dimension
                        of the scatterplot. See fields at
                        http://biocache.ala.org.au/ws/index/fields with
                        dataType=double.
                    y -- string --   Environmental layer for the Y dimension
                        of the scatterplot. See fields at
                        http://biocache.ala.org.au/ws/index/fields with
                        dataType=double.
                    fq -- list of string --   Filters to be applied to the
                        original query. These are additional params of the
                        form fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://bie.ala.org.au/ws/admin/indexFields for all the
                        fields that a queryable.
                    height -- int --   Height of the returned image in pixels.
                        The default value is 256.
                    pointcolour -- string --   Colour of the occurrence
                        points. The default value is 0000FF (blue).
                    pointradius -- string --   Size of occurrence points. The
                        default value is 3.
                    width -- int --   Widith of the returned image in pixels.
                        The default value is 256.

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/scatterplot"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "q": options.get('q', None),
            "x": options.get('x', None),
            "y": options.get('y', None),
            "fq": options.get('fq', None),
            "height": options.get('height', None),
            "pointcolour": options.get('pointcolour', None),
            "pointradius": options.get('pointradius', None),
            "width": options.get('width', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 10
0
    def get_occurrence_download(self,
                                options=dict()):
        """Does a GET request to /ws/occurrences/index/download.

        Occurrence download. Downloads of the following formats are supported:
        CSV     SHAPE  The output format is determined based on the fileType
        param.  The download will return a ZIP file that contains the data in
        the requested format and a Readme and citataion.csv. Please be aware
        that a shape file download will be large. Each of the fields is
        included as a feature. It is advised to select a subset of information
        to be included. 

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    reason_type_id -- int -- A reason code for the download.
                        See reasons for valid values.
                    email -- string -- The email address of the user
                        performing the download.
                    esc -- string -- The Escape character to use for a CSV
                        file. This will default to " in order to produce an
                        Excel compliant CSV file.
                    extra -- string -- a CSV list of fields in include in
                        addition to the "fields". This is useful if you would
                        like to make use of the default fields and include
                        extra fields.
                    fields -- string -- A CSV list of fields to include in the
                        download. This can be an index field name OR a Darwin
                        Core Field name. There is a default list that is
                        included if no value is supplied.
                    file -- string -- The name of the file to produce. This
                        will default to data. 
                    file_type -- string -- The file format for the download.
                        Either csv or shp. When no value is supplied csv is
                        assumed. 
                    fq -- list of string -- Filters to be applied to the
                        original query. These are additional params of the
                        form fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    lat -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    lon -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    qa -- string -- A CSV list of record issues to include in
                        the download. See assertions for possible values to
                        include. When no value is supplied all the record
                        issues are included. To include NO record issues set
                        this value to none.
                    radius -- double -- The radius in which to limit records
                        (relative to the lat, lon point). Use with lat and lon
                        to specify a "search" circle.
                    reason -- string -- A user supplied description of the
                        reason for the download
                    sep -- string -- The separator character to use for a CSV
                        file. This will default to , .
                    source_type_id -- OccurrenceDownloadSourceTypeIdTypeEnum
                        -- A source type code for the download. This indicates
                        which system requested the download. See sources for
                        valid values.
                    wkt -- string -- The polygon area in which to limit
                        records.

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrences/index/download"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "reasonTypeId": options.get('reason_type_id', None),
            "email": options.get('email', None),
            "esc": options.get('esc', None),
            "extra": options.get('extra', None),
            "fields": options.get('fields', None),
            "file": options.get('file', None),
            "fileType": options.get('file_type', None),
            "fq": options.get('fq', None),
            "lat":  options.get('lat', None) if options.get('lat', None) is not None else -41.290817,
            "lon":  options.get('lon', None) if options.get('lon', None) is not None else 174.753377,
            "q": options.get('q', None),
            "qa": options.get('qa', None),
            "radius":  options.get('radius', None) if options.get('radius', None) is not None else 20,
            "reason": options.get('reason', None),
            "sep": options.get('sep', None),
            "sourceTypeId":  options.get('source_type_id', None).to_string() if options.get('source_type_id', None) is not None else None,
            "wkt":  options.get('wkt', None) if options.get('wkt', None) is not None else "POLYGON((160 -60,160 -25,180 -25,180 -60,160 -60))"
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 11
0
    def get_occurrence_search(self,
                              options=dict()):
        """Does a GET request to /ws/occurrences/search.

        JSON occurrence search. In addition to the parameters listed, range
        based faceting is supported by using the SOLR parameters. 

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    dir -- string -- Supports "asc" or "desc" 
                    facet -- string -- Supported values are "off" or "on". By
                        default, its "on". This is worth switching off if
                        facetting is not required, to reduce the JSON being
                        sent.
                    facets -- string -- Comma separated list of the fields to
                        create facets on e.g. facets=basis_of_record.
                    flimit -- int -- Maximum number of facet values to return
                    foffset -- int -- Facet offset, to enable paging
                    fprefix -- string -- Limits facets to values that start
                        with the supplied value
                    fq -- list of string -- Filters to be applied to the
                        original query. These are additional params of the
                        form fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    fsort -- string -- Method in which to sort the facets
                        either "count" or "index" 
                    lat -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    lon -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    page_size -- int -- Number of records to return
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    radius -- double -- The radius in which to limit records
                        (relative to the lat, lon point). Use with lat and lon
                        to specify a "search" circle.
                    sort -- string -- The indexed field to sort by
                    start_index -- int -- Record offset, to enable paging
                    wkt -- string -- The polygon area in which to limit
                        records.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrences/search"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "dir": options.get('dir', None),
            "facet":  options.get('facet', None) if options.get('facet', None) is not None else "on",
            "facets": options.get('facets', None),
            "flimit": options.get('flimit', None),
            "foffset": options.get('foffset', None),
            "fprefix": options.get('fprefix', None),
            "fq": options.get('fq', None),
            "fsort": options.get('fsort', None),
            "lat":  options.get('lat', None) if options.get('lat', None) is not None else -41.290817,
            "lon":  options.get('lon', None) if options.get('lon', None) is not None else 174.753377,
            "pageSize": options.get('page_size', None),
            "q": options.get('q', None),
            "radius":  options.get('radius', None) if options.get('radius', None) is not None else 20,
            "sort": options.get('sort', None),
            "startIndex": options.get('start_index', None),
            "wkt":  options.get('wkt', None) if options.get('wkt', None) is not None else "POLYGON((160 -60,160 -25,180 -25,180 -60,160 -60))"
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 12
0
    def get_wms_get_map(self, options=dict()):
        """Does a GET request to /ws/ogc/wms/reflect.

        WMS services for point occurrence data

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    dir -- int --   Supports "asc" or "desc"
                    env -- string --   Additional parameters. e.g.
                        ENV=color%3Acd3844%3Bsize%3A3%3Bopacity%3A0.8.     
                        color - hex RGB values. e.g. colour:cd3844.     size -
                        radius of points in pixels.     opacity - opacity
                        value 0 - 1.     sel - fq parameter applied to
                        CQL_FILTER. Matching occurrences will be highlighted
                        on the map in a Red circle.     uncertainty - presence
                        of the uncertainty parameter draws uncertainty circles
                        to a fixed maximum of 30km.     colormode - facet
                        colouring type.         -1 (default) use color value. 
                        grid map as density grid. Grid cells drawn are not
                        restricted to within any query WKT parameters.        
                        facetname colour as categories in a facet.        
                        facetname,cutpoints colour as range in a facet using
                        the supplied comma separated cutpoints. 4 to 10 values
                        are required. Include minimum and maximum. Minimum and
                        maximum values do not need to be accurate. e.g.
                        colormode:year,1800,1900,1950,1970,1990,2010
                    facet -- string --   Supported values are "off" or "on".
                        By default, its "on". This is worth switching off if
                        facetting is not required, to reduce the JSON being
                        sent.
                    facets -- string --   Comma separated list of the fields
                        to create facets on e.g. facets=basis_of_record.
                    flimit -- int --   Maximum number of facet values to
                        return
                    foffset -- int --   Facet offset, to enable paging
                    fprefix -- int --   Limits facets to values that start
                        with the supplied value
                    fq -- list of string --   Filters to be applied to the
                        original query. These are additional params of the
                        form fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    fsort -- int --   Method in which to sort the facets
                        either "count" or "index"
                    lat -- double --   The decimal latitude to limit records
                        to. Use with lon and radius to specify a "search"
                        circle
                    lon -- double --   The decimal latitude to limit records
                        to. Use with lon and radius to specify a "search"
                        circle
                    page_size -- int --   Number of records to return
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    radius -- double --   The radius in which to limit records
                        (relative to the lat, lon point). Use with lat and lon
                        to specify a "search" circle.
                    sort -- int --   The indexed field to sort by
                    start_index -- int --   Record offset, to enable paging
                    wkt -- string --   The polygon area in which to limit
                        records. For information on Well known text

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/ws/ogc/wms/reflect"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(
            query_builder,
            {
                "dir": options.get("dir", None),
                "ENV": options.get("env", None),
                "facet": options.get("facet", None),
                "facets": options.get("facets", None),
                "flimit": options.get("flimit", None),
                "foffset": options.get("foffset", None),
                "fprefix": options.get("fprefix", None),
                "fq": options.get("fq", None),
                "fsort": options.get("fsort", None),
                "lat": options.get("lat", None) if options.get("lat", None) is not None else -41.290817,
                "lon": options.get("lon", None) if options.get("lon", None) is not None else 174.753377,
                "pageSize": options.get("page_size", None),
                "q": options.get("q", None),
                "radius": options.get("radius", None) if options.get("radius", None) is not None else 20,
                "sort": options.get("sort", None),
                "startIndex": options.get("start_index", None),
                "wkt": options.get("wkt", None)
                if options.get("wkt", None) is not None
                else "POLYGON((160 -60,160 -25,180 -25,180 -60,160 -60))",
            },
        )

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {"user-agent": "APIMATIC 2.0"}

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)

        return response.body
Ejemplo n.º 13
0
    def get_generate_static_map(self, options=dict()):
        """Does a GET request to /ws/mapping/wms/image.

        Generate a static image with various formatting options.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    extents -- string --   minx,miny,maxx,maxy 
                        160.0,-60.0,180.0,-25.0
                    baselayer -- string --   Base layer to use from
                        http://spatial.ala.org.au/geoserver
                    baselayer_prefix -- string --   Default "ALA:"
                    dpi -- string --   Dots per inch. Default is 300.
                    file_name -- string --   File name to use
                    format -- string --   Default 'jpg'
                    fq -- string --   Filters to be applied to the original
                        query. These are additional params of the form
                        fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    outline -- string --   Point outline. Default is false
                    outline_colour -- string --   Default #000000
                    pcolour -- string --   Point colour in hex. Default is
                        FF0000
                    popacity -- string --   Point opacity. Default is 0.8
                    pradiusmm -- string --   Species point radius in mm,
                        integer
                    pradiuspx -- string --   Species point radius in pixels,
                        integer. Only pradiuspx or pradiusmm need be supplied.
                        If both supplied, pradiuspx takes precendence.
                    q -- string --   Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    scale -- string --   Include a scale. DefaultValue =
                        "off".
                    widthmm -- string --   Image width in mm

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI

        # Prepare query string for API call
        query_builder += "/ws/mapping/wms/image"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(
            query_builder,
            {
                "extents": options.get("extents", None),
                "baselayer": options.get("baselayer", None),
                "baselayerPrefix": options.get("baselayer_prefix", None)
                if options.get("baselayer_prefix", None) is not None
                else "ALA",
                "dpi": options.get("dpi", None) if options.get("dpi", None) is not None else "300",
                "fileName": options.get("file_name", None),
                "format": options.get("format", None) if options.get("format", None) is not None else "jpg",
                "fq": options.get("fq", None),
                "outline": options.get("outline", None) if options.get("outline", None) is not None else "false",
                "outlineColour": options.get("outline_colour", None)
                if options.get("outline_colour", None) is not None
                else "0x000000",
                "pcolour": options.get("pcolour", None) if options.get("pcolour", None) is not None else "FF0000",
                "popacity": options.get("popacity", None) if options.get("popacity", None) is not None else "0.8",
                "pradiusmm": options.get("pradiusmm", None),
                "pradiuspx": options.get("pradiuspx", None),
                "q": options.get("q", None),
                "scale": options.get("scale", None) if options.get("scale", None) is not None else "off",
                "widthmm": options.get("widthmm", None),
            },
        )

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {"user-agent": "APIMATIC 2.0"}

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body)

        return response.body
Ejemplo n.º 14
0
    def get_occurrence_facet_search(self,
                                    options=dict()):
        """Does a GET request to /ws/occurrence/facets.

        Use this service to retrieve counts for facets e.g. the number of taxa
        matching a query. Note: fq is ignore for this web service. If
        required, include any fq query into the q param with an AND clause.

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    facets -- string -- Comma separated list of the fields to
                        create facets on e.g. facets=basis_of_record.
                    dir -- string -- Supports "asc" or "desc"
                    flimit -- int -- Maximum number of facet values to return
                    foffset -- int -- Facet offset, to enable paging
                    fprefix -- string -- Limits facets to values that start
                        with the supplied value
                    fsort -- string -- Method in which to sort the facets
                        either "count" or "index"
                    lat -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    lon -- double -- The decimal latitude to limit records to.
                        Use with lon and radius to specify a "search" circle
                    lookup -- bool -- Only suitable for facets that are
                        returning taxon GUIDs (e.g.species_guid) If set to
                        true this will try to perform a taxon lookup against
                        the guid and will return additional taxon information
                    q -- string -- Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    radius -- double -- The radius in which to limit records
                        (relative to the lat, lon point). Use with lat and lon
                        to specify a "search" circle.
                    sort -- string -- The indexed field to sort by
                    start_index -- int -- Record offset, to enable paging
                    wkt -- string -- The polygon area in which to limit
                        records.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/occurrence/facets"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "facets": options.get('facets', None),
            "dir": options.get('dir', None),
            "flimit": options.get('flimit', None),
            "foffset": options.get('foffset', None),
            "fprefix": options.get('fprefix', None),
            "fsort": options.get('fsort', None),
            "lat":  options.get('lat', None) if options.get('lat', None) is not None else -41.290817,
            "lon":  options.get('lon', None) if options.get('lon', None) is not None else 174.753377,
            "lookup": options.get('lookup', None),
            "q": options.get('q', None),
            "radius":  options.get('radius', None) if options.get('radius', None) is not None else 20,
            "sort": options.get('sort', None),
            "startIndex": options.get('start_index', None),
            "wkt":  options.get('wkt', None) if options.get('wkt', None) is not None else "POLYGON((160 -60,160 -25,180 -25,180 -60,160 -60))"
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 15
0
    def get_download_list_of_species_in_group(self,
                                              options=dict()):
        """Does a GET request to /ws/explore/group/{group}/download.

        Retrieve all species groups and counts. The first count is total
        number of occurrence, the second is the number of distinct species

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    group -- string -- group
                    fq -- list of string -- The filter query
                    lat -- double -- The latitude to limit the query by (must
                        be used with lon and radius)
                    lon -- double -- The longitude to limit the query by (must
                        be used with lat and radius)
                    q -- string -- The query which defaults to : when not
                        supplied
                    radius -- int -- The radius in km of the circle to limit
                        to (must be used with lat and lon)

        Returns:
            binary: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/explore/group/{group}/download"

        # Process optional template parameters
        query_builder = APIHelper.append_url_with_template_parameters(query_builder, { 
            "group": options.get('group', None)
        })

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "fq": options.get('fq', None),
            "lat":  options.get('lat', None) if options.get('lat', None) is not None else -41.290817,
            "lon":  options.get('lon', None) if options.get('lon', None) is not None else 174.753377,
            "q": options.get('q', None),
            "radius":  options.get('radius', None) if options.get('radius', None) is not None else 20
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 16
0
    def get_endemic_species_list(self,
                                 options=dict()):
        """Does a GET request to /ws/explore/endemic/species.

        List endemic species within an area

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    facets -- string --   The field on which to based the
                        species list. This can be taxon_concept_lsid or
                        species_guid
                    fq -- string --   Filters to be applied to the original
                        query. These are additional params of the form
                        fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://biocache.ala.org.au/ws/index/fields for all the
                        fields that a queryable.
                    q -- string --   The initial query. q=: will query
                        anything, q=macropus will do a free text search for
                        macropus, q=kingdom:Fungi will search for records with
                        a kingdom of Fungi. For a listing of the fields that
                        can be queried in a q=INDEXEDFIELD:VALUE fashion, see
                        /index/fields. This will restrict the records that are
                        considered in then region. For example this could
                        allow people to restrict the service to endemic
                        birds.
                    wkt -- string --   The Well Known Text Area in which to
                        provide the endemic species.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/explore/endemic/species"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "facets": options.get('facets', None),
            "fq": options.get('fq', None),
            "q": options.get('q', None),
            "wkt":  options.get('wkt', None) if options.get('wkt', None) is not None else "POLYGON((160 -60,160 -25,180 -25,180 -60,160 -60))"
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body
Ejemplo n.º 17
0
    def get_scatterplot_query(self,
                              options=dict()):
        """Does a GET request to /ws/scatterplot/point.json.

        Returns x and y axis co-ordinates corresponding to image pixel points
        (origin top left) for two pointspointx1 pointx2 pointy1 pointy2
        http://biocache.ala.org.au/ws/scatterplot/point.json?q=Macropus%20Agili
        s&x=el874&y=el871&height=512&width=512&pointx1=200&pointy1=200&pointx2=
        500&pointy2=0

        Args:
            options (dict, optional): Key-value pairs for any of the
                parameters to this API Endpoint. All parameters to the
                endpoint are supplied through the dictionary with their names
                being the key and their desired values being the value. A list
                of parameters that can be used are::

                    fq -- list of string --   Filters to be applied to the
                        original query. These are additional params of the
                        form fq=INDEXEDFIELD:VALUE e.g. fq=kingdom:Fungi. See
                        http://bie.ala.org.au/ws/admin/indexFields for all the
                        fields that a queryable.
                    height -- int --   Height of the returned image in pixels.
                        The default value is 256.
                    pointx_1 -- int --   X coordinate for the first
                        scatterplot image pixel. Origin is the top left
                        corner.
                    pointx_2 -- int --   X coordinate for the second
                        scatterplot image pixel. Origin is the top left
                        corner.
                    pointy_1 -- int --   Y coordinate for the first
                        scatterplot image pixel. Origin is the top left
                        corner.
                    pointy_2 -- int --   Y coordinate for the second
                        scatterplot image pixel. Origin is the top left
                        corner.
                    q -- string --   Query of the form field:value e.g.
                        q=genus:Macropus or a free text search e.g.
                        q=Macropus
                    width -- int --   Widith of the returned image in pixels.
                        The default value is 256.
                    x -- string --   Environmental layer for the X dimension
                        of the scatterplot. See fields at
                        http://biocache.ala.org.au/ws/index/fields with
                        dataType=double.
                    y -- string --   Environmental layer for the Y dimension
                        of the scatterplot. See fields at
                        http://biocache.ala.org.au/ws/index/fields with
                        dataType=double.

        Returns:
            mixed: Response from the API. 

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        # The base uri for api requests
        query_builder = Configuration.BASE_URI
 
        # Prepare query string for API call
        query_builder += "/ws/scatterplot/point.json"

        # Process optional query parameters
        query_builder = APIHelper.append_url_with_query_parameters(query_builder, {
            "fq": options.get('fq', None),
            "height": options.get('height', None),
            "pointx1": options.get('pointx_1', None),
            "pointx2": options.get('pointx_2', None),
            "pointy1": options.get('pointy_1', None),
            "pointy2": options.get('pointy_2', None),
            "q": options.get('q', None),
            "width": options.get('width', None),
            "x": options.get('x', None),
            "y": options.get('y', None)
        })

        # Validate and preprocess url
        query_url = APIHelper.clean_url(query_builder)

        # Prepare headers
        headers = {
            "user-agent": "APIMATIC 2.0",
            "accept": "application/json"
        }

        # Prepare and invoke the API call request to fetch the response
        response = unirest.get(query_url, headers=headers)

        # Error handling using HTTP status codes
        if response.code < 200 or response.code > 206:  # 200 = HTTP OK
            raise APIException("HTTP Response Not OK", response.code, response.body) 
    
        return response.body