Example #1
0
 def tearDown(self):
     # restore the original datapath, othwise this could cause other
     # tests to have errors
     pyproj.set_datapath(self.datadir_save)
Example #2
0
 def test_utf8_set_datapath(self):
     # Issue #83 reported that Unicode characters in the installation
     # path this would cause a UnicodeEncodeError
     # the path is fictious and not meant to be a real path
     pyproj.set_datapath(u'göteborg')
Example #3
0
def raster_drill(layer, x, y, format_):
    """
    Writes the information in the format provided by the user
    and reads some information from the geomet-climate yaml

    :param layer: layer name
    :param x: x coordinate
    :param y: y coordinate
    :param format_: output format (GeoJSON or CSV)

    :return: return the final file fo a given location
    """

    from msc_pygeoapi.process.cccs import (GEOMET_CLIMATE_CONFIG,
                                           GEOMET_CLIMATE_BASEPATH,
                                           GEOMET_CLIMATE_BASEPATH_VRT,
                                           GEOMET_CLIMATE_EPSG)

    if GEOMET_CLIMATE_EPSG is not None:
        pyproj.set_datapath(GEOMET_CLIMATE_EPSG)
    else:
        raise Exception("Could not locate geomet-climate EPSG file.")

    LOGGER.info('start raster drilling')

    if format_ not in ['CSV', 'GeoJSON']:
        msg = 'Invalid format'
        LOGGER.error(msg)
        raise ValueError(msg)

    with open(GEOMET_CLIMATE_CONFIG, encoding='utf-8') as fh:
        cfg = yaml.load(fh, Loader=CLoader)

    data_basepath = GEOMET_CLIMATE_BASEPATH
    climate_model_path = cfg['layers'][layer]['climate_model']['basepath']
    file_path = cfg['layers'][layer]['filepath']
    inter_path = os.path.join(climate_model_path, file_path)

    if ('ABS' in layer
            or 'ANO' in layer and layer.startswith('CANGRD') is False):

        keys = [
            'Model', 'Variable', 'Scenario', 'Period', 'Type', 'Percentile'
        ]
        values = layer.replace('_', '.').split('.')
        layer_keys = dict(zip(keys, values))

        file_name = cfg['layers'][layer]['filename']

    elif 'TREND' not in layer and layer.startswith('CANGRD'):
        keys = ['Model', 'Type', 'Variable', 'Period']
        values = layer.replace('_', '.').split('.')
        layer_keys = dict(zip(keys, values))

        data_basepath = GEOMET_CLIMATE_BASEPATH_VRT
        climate_model_path = cfg['layers'][layer]['climate_model']['basepath']
        file_path = cfg['layers'][layer]['filepath']
        inter_path = os.path.join(climate_model_path, file_path)

        file_name = '{}.vrt'.format(cfg['layers'][layer]['filename'])

    elif layer.startswith('SPEI'):
        keys = ['Variable', 'Variation', 'Scenario', 'Period', 'Percentile']
        values = layer.replace('-', '.').replace('_', '.').split('.')
        layer_keys = dict(zip(keys, values))
        layer_keys['Type'] = 'ABS'

        file_name = cfg['layers'][layer]['filename']

    elif layer.startswith('INDICES'):
        keys = ['Model', 'Variable', 'Scenario', 'Percentile']
        values = layer.replace('_', '.').split('.')
        layer_keys = dict(zip(keys, values))
        layer_keys['Type'] = 'ABS'

        file_name = cfg['layers'][layer]['filename']

    else:
        msg = 'Not a valid or time enabled layer: {}'.format(layer)
        LOGGER.error(msg)
        raise ValueError(msg)

    srs = osr.SpatialReference()
    srs.ImportFromWkt(cfg['layers'][layer]['climate_model']['projection'])
    inProj = Proj(init='epsg:4326')
    outProj = Proj(srs.ExportToProj4())
    _x, _y = transform(inProj, outProj, x, y)

    ds = os.path.join(data_basepath, inter_path, file_name)

    data = get_location_info(ds, _x, _y, cfg['layers'][layer], layer_keys)
    output = serialize(data, cfg['layers'][layer], format_, x, y)

    return output
Example #4
0
md = makemd(erddap_metadata)

md["dimensions"] = getDimensions(erddap_metadata)

md["parameters"] = getParameterList(erddap_metadata)

print('    dataset info retrieved')
try:
    md["proj_crs_code"]
except:
    md["proj_crs_code"] = "EPSG:4326"  #assume that if a projection is not specified it is 4326
else:
    pass

pyproj.set_datapath('/usr/local/miniconda3/share/proj')  # fixes bad env path

#Keep track of the input info to pass back to the webpage
req = {
    'projection': map_proj,
    'dataset_id': dataset_id,
    'parameter': parameter,
    'colorBar': colorBar,
    'cache_date': cache_date,
    'time': time,
    'timep': timep,
    'tab': tab
}

# Test defining 3412...
# 03/12/19 was using northpolarstereo instead of sterographic.
Example #5
0
 def test_utf8_set_datapath(self):
     # Issue #83 reported that Unicode characters in the installation
     # path this would cause a UnicodeEncodeError
     # the path is fictious and not meant to be a real path
     pyproj.set_datapath(u'göteborg')
Example #6
0
 def tearDown(self):
     # restore the original datapath, othwise this could cause other
     # tests to have errors
     pyproj.set_datapath(self.datadir_save)
Example #7
0
    def transBBtoLL(sourceSrs,extents):
        
        try:
            minx = extents[0]
            maxx = extents[1]
            miny = extents[2]
            maxy = extents[3]
            
            newsrs = sourceSrs.ExportToProj4() 

            # The following lines have been replaced to use pyproj instead of osr due
            # to the current flakiness of TransformPoint not acceptint arguements.
            # i.e. (NotImplementedError: Wrong number of arguments for overloaded function 
            # 'CoordinateTransformation_TransformPoint'.)
    ##        targetSrs = osr.SpatialReference()
    ##        targetSrs.ImportFromEPSG(4326)
    ##        
    ##        transform = osr.CoordinateTransformation(sourceSrs,targetSrs)
    ##        
    ##        ulcoord = transform.TransformPoint(minx, maxy, 0.0)
    ##        llcoord = transform.TransformPoint(minx, miny, 0.0)
    ##        lrcoord = transform.TransformPoint(maxx, miny, 0.0)
    ##        urcoord = transform.TransformPoint(maxx, maxy, 0.0)
            
            
            boundbox = OrderedDict()
            if sourceSrs.GetAttrValue("AUTHORITY",1) == "4326" and not sourceSrs.IsProjected():
                boundbox['maxx'] = maxx
                boundbox['maxy'] = maxy
                boundbox['minx'] = minx
                boundbox['miny'] = miny
                
            else:
               # pyproj section 
                pyproj.set_datapath(MDR.GNConnection.projData)
                pyproj.pyproj_datadir = MDR.GNConnection.projData
                
                pyproj.set_datapath(MDR.GNConnection.projData)
                
                p1 = pyproj.Proj(newsrs)
                
                p2 = pyproj.Proj(init='epsg:4326')

                ulcoord = pyproj.transform(p1, p2, minx, maxy)
                lrcoord = pyproj.transform(p1, p2, maxx, miny)
                llcoord = pyproj.transform(p1, p2, minx, miny)
                urcoord = pyproj.transform(p1, p2, maxx, maxy)
                
                # end pyproj section
                
                boundbox['maxx'] = max(lrcoord[0], urcoord[0])
                boundbox['maxy'] = max(ulcoord[1], urcoord[1])
                boundbox['minx'] = min(llcoord[0], ulcoord[0])
                boundbox['miny'] = min(llcoord[1], lrcoord[1])
     
            extent = OrderedDict()
            EX_Extent = OrderedDict()
            geographicElement = OrderedDict()
            EX_GeographicBoundingBox = OrderedDict()
            minx = OrderedDict([('{http://www.isotc211.org/2005/gco}Decimal',boundbox['minx'])])
            EX_GeographicBoundingBox['{http://www.isotc211.org/2005/gmd}westBoundLongitude'] = minx
            maxx = OrderedDict([('{http://www.isotc211.org/2005/gco}Decimal',boundbox['maxx'])])
            EX_GeographicBoundingBox['{http://www.isotc211.org/2005/gmd}eastBoundLongitude'] = maxx
            miny = OrderedDict([('{http://www.isotc211.org/2005/gco}Decimal',boundbox['miny'])])
            EX_GeographicBoundingBox['{http://www.isotc211.org/2005/gmd}southBoundLatitude'] = miny
            maxy = OrderedDict([('{http://www.isotc211.org/2005/gco}Decimal',boundbox['maxy'])])
            EX_GeographicBoundingBox['{http://www.isotc211.org/2005/gmd}northBoundLatitude'] = maxy
            geographicElement['{http://www.isotc211.org/2005/gmd}EX_GeographicBoundingBox'] = EX_GeographicBoundingBox
            EX_Extent['{http://www.isotc211.org/2005/gmd}geographicElement'] = geographicElement
            extent['{http://www.isotc211.org/2005/gmd}EX_Extent'] = EX_Extent
        
        except:
            boundbox = "Faulty proj4 parameters"
            extent = None
            
        
        return boundbox, extent