Beispiel #1
0
    def get_layer_info(self, layer_type):
        """ Gets the layer information """

        layer_params = {}

        base_bsve = "https://api-qa.bsvecosystem.net/data/v2/sources/"
        headers = getExtraHeaders()

        if layer_type == 'vector':
            bsve_wfs = base_bsve + "geofeatures/data/result?"
            wfs_qs = quote(
                "$filter=name eq {} and request eq describefeaturetype&$format=text/xml; subtype=gml/3.1.1"
                .format(self._type_name),
                safe='=&$ ').replace(' ', '+')
            resp = requests.get(bsve_wfs + wfs_qs, headers=headers)
            tree = ET.fromstring(resp.content)
            layer_params['layerType'] = layer_type
            layer_params['subType'] = WmsStyle._get_vector_type(tree)
            layer_params['attributes'] = self._get_attributes(tree)

        elif layer_type == 'raster':
            wcs_url = base_bsve + \
                      "geocoverage/data/result?$filter=identifiers eq {}".format(self._type_name)
            resp = requests.get(wcs_url, headers=headers)
            tree = ET.fromstring(resp.content)
            sub_type, bands = WmsStyle._get_bands(tree)
            layer_params['layerType'] = layer_type
            layer_params['bands'] = bands
            layer_params['subType'] = sub_type

        return layer_params
Beispiel #2
0
    def _get_min_max_count(self, attribute):
        """Gets the min max and count values for a given
        numeric attribute
        """

        url = "https://api-qa.bsvecosystem.net/data/v2/sources/geoprocessing/request"
        headers = getExtraHeaders()
        headers.update({'Content-Type': 'application/xml'})
        xml_data = wps_template(self._type_name, attribute)
        res = requests.post(url, data=xml_data, headers=headers)

        # Means wps is not activated
        if res.status_code == 404:
            return None
        elif 'Exception' in res.text:
            return None
        else:
            prop = {}
            xml_res = ET.fromstring(res.content)
            for elem in xml_res.iter():
                if 'Min' in elem.tag:
                    prop['min'] = elem.text
                elif 'Max' in elem.tag:
                    prop['max'] = elem.text
                elif 'Count' in elem.tag:
                    prop['count'] = elem.text
            return prop
Beispiel #3
0
    def createBsveDataset(self, params, layer_type):
        typeName = params['type_name']

        headers = getExtraHeaders()

        try:
            layer_info = BsveWmsStyle(typeName).get_layer_info(layer_type)
        except TypeError:
            layer_info = ""

        # TODO: Add the legend url here once it is
        # ready on bsve side
        self.requireParams(('name'), params)
        name = params['name']

        params['layer_info'] = layer_info
        params['adapter'] = 'bsve'

        legend_url = "https://api-dev.bsvecosystem.net/data/v2/sources/geotiles/data/result?"
        legend_qs = quote(
            "$filter=name eq {} and request eq getlegendgraphic and height eq 20 and width eq 20"
            .format(typeName),
            safe='= ').replace(' ', '+')

        r = requests.get(legend_url + legend_qs, headers=headers)
        legend = b64encode(r.content)
        params['legend'] = legend
        dataset = self.constructDataset(name, params)
        return dataset
Beispiel #4
0
    def createBsveSource(self, params):
        """ Hits the bsve urls """

        # Bsve geoserver (wms get capabilities url)
        wms = "https://api-qa.bsvecosystem.net/data/v2/" + \
              "sources/geotiles/meta/list"

        resp = requests.get(wms, headers=getExtraHeaders())
        data = json.loads(resp.text)

        layers = []

        for d in data['tiles']:
            wms_params = {}
            wms_params['type_name'] = d['name']
            wms_params['name'] = d['styles'][0]['title']
            wms_params['abstract'] = d['abstract']
            wms_params['source'] = {
                'layer_source': 'Reference',
                'source_type': 'wms'
            }
            wms_params['geo_render'] = {'type': 'wms'}
            layer_type = 'raster' if 'WCS' in d['keywords'] else 'vector'
            dataset = self.createBsveDataset(wms_params, layer_type)
            layers.append(dataset)

        return layers
Beispiel #5
0
    def GET(self, url, **params):
        headers = getExtraHeaders()
        if 'minerva_credentials' in params:
            creds = params['minerva_credentials']
            del params['minerva_credentials']
            auth = 'Basic ' + b64encode(decryptCredentials(bytes(creds)))
            headers['Authorization'] = auth

        r = requests.get(url, params=params, headers=headers)
        cherrypy.response.headers['Content-Type'] = r.headers['content-type']
        return r.content
Beispiel #6
0
    def GET(self, url, **params):
        headers = getExtraHeaders()
        if 'minerva_credentials' in params:
            creds = params['minerva_credentials']
            del params['minerva_credentials']
            auth = 'Basic ' + b64encode(decryptCredentials(bytes(creds)))
            headers['Authorization'] = auth

        r = requests.get(url, params=params, headers=headers)
        cherrypy.response.headers['Content-Type'] = r.headers['content-type']
        return r.content
Beispiel #7
0
def callBsveFeatureInfo(baseUrl, params, typeNames):
    """Call bsve api for getting information about
    a lat long locaion"""

    headers = getExtraHeaders()
    headers.update({'Content-Type': 'application/xml'})

    typeNames = ",".join(typeNames)

    parameters = quote("$filter=names eq {} and query_layers eq {} and request eq getfeatureinfo and exceptions eq application/vnd.ogc.se_xml and feature_count eq 50 and projection eq EPSG:3857 and format eq image/png and geo.bbox eq {} and width eq {} and height eq {} and x eq {} and y eq {} and format_options eq callbak:getLayerFeatures&$format=application/json".format(typeNames, typeNames, params['bbox'], params['width'], params['height'], params['x'], params['y'] ), safe='=&$ ').replace(' ', '+')

    req = requests.get(baseUrl, params=parameters, headers=headers)

    return req.content
def callBsveFeatureInfo(params, typeNames):
    """Call bsve api for getting information about
    a lat long locaion"""

    baseUrl = bsveRoot() + '/data/v2/sources/geotiles/data/result'
    headers = getExtraHeaders()
    headers.update({'Content-Type': 'application/xml'})

    typeNames = ",".join(typeNames)

    parameters = quote("$filter=names eq {} and query_layers eq {} and request eq getfeatureinfo and exceptions eq application/vnd.ogc.se_xml and feature_count eq 50 and projection eq EPSG:3857 and format eq image/png and geo.bbox eq {} and width eq {} and height eq {} and x eq {} and y eq {} and format_options eq callbak:getLayerFeatures&$format=application/json".format(typeNames, typeNames, params['bbox'], params['width'], params['height'], params['x'], params['y'] ), safe='=&$ ').replace(' ', '+')

    req = requests.get(baseUrl, params=parameters, headers=headers)

    return req.content
Beispiel #9
0
    def createBsveSource(self, params):
        root = bsveRoot()
        extraHeaders = getExtraHeaders()
        wms = root + "/data/v2/sources/geotiles/meta/list"
        user = self.getCurrentUser()

        resp = requests.get(wms, headers=extraHeaders)
        data = json.loads(resp.text)

        needConvert = False

        existingLayers = self.getLayers(user)
        newLayers = set()

        for d in data['tiles']:
            typeName = d['name']
            newLayers.add(typeName)
            if typeName in existingLayers:
                continue
            needConvert = True

        if needConvert:
            job = self.model('job', 'jobs').createLocalJob(
                title='Reference datasets update',
                user=user,
                type='minerva.bsve',
                public=False,
                kwargs={
                    'user': user,
                    'bsveRoot': root,
                    'extraHeaders': extraHeaders
                },
                module='girder.plugins.bsve.create_bsve_dataset_worker',
                async=True)
            self.model('job', 'jobs').scheduleJob(job)
            return job
    def createBsveSource(self, params):
        root = bsveRoot()
        extraHeaders = getExtraHeaders()
        wms = root + "/data/v2/sources/geotiles/meta/list"
        user = self.getCurrentUser()

        resp = requests.get(wms, headers=extraHeaders)
        data = json.loads(resp.text)

        needConvert = False

        existingLayers = self.getLayers(user)
        newLayers = set()

        for d in data['tiles']:
            typeName = d['name']
            newLayers.add(typeName)
            if typeName in existingLayers:
                continue
            needConvert = True

        if needConvert:
            job = self.model('job', 'jobs').createLocalJob(
                title='Reference datasets update',
                user=user,
                type='minerva.bsve',
                public=False,
                kwargs={
                    'user': user,
                    'bsveRoot': root,
                    'extraHeaders': extraHeaders
                },
                module='girder.plugins.bsve.create_bsve_dataset_worker',
                async=True)
            self.model('job', 'jobs').scheduleJob(job)
            return job