# Path: nansat/nsr.py
# class NSR(osr.SpatialReference, object):
#     """Nansat Spatial Reference. Overrides constructor of osr.SpatialReference.
# 
#     Parameters
#     ----------
#     srs : 0, PROJ4 or EPSG or WKT or osr.SpatialReference, NSR
#         Specifies spatial reference system (SRS)
#         PROJ4:
#         string with proj4 options [http://trac.osgeo.org/proj/] e.g.:
#         '+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs'
#         '+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=0 +no_defs'
#         EPSG:
#         integer with EPSG number, [http://spatialreference.org/],
#         e.g. 4326
#         WKT:
#         string with Well Know Text of SRS. E.g.:
#         'GEOGCS["WGS 84",
#             DATUM["WGS_1984",
#                 SPHEROID["WGS 84",6378137,298.257223563,
#                     AUTHORITY["EPSG","7030"]],
#                 TOWGS84[0,0,0,0,0,0,0],
#                 AUTHORITY["EPSG","6326"]],
#             PRIMEM["Greenwich",0,
#                 AUTHORITY["EPSG","8901"]],
#             UNIT["degree",0.0174532925199433,
#                 AUTHORITY["EPSG","9108"]],
#             AUTHORITY["EPSG","4326"]]'
# 
#     """
# 
#     def __init__(self, srs=0):
#         """Create Spatial Reference System from input parameter"""
#         if sys.version_info.major == 2:
#             str_types = (str, unicode)
#         else:
#             str_types = str
#         # create SRS
#         osr.SpatialReference.__init__(self)
# 
#         # parse input parameters
#         status = 1
#         if srs is 0:
#             # generate default WGS84 SRS
#             status = self.ImportFromEPSG(4326)
#         elif isinstance(srs, str_types):
#             # parse as proj4 string
#             status = self.ImportFromProj4(str(srs))
#             if status > 0:
#                 # parse as WKT string
#                 status = self.ImportFromWkt(str(srs))
#             if status > 0:
#                 raise NansatProjectionError('Proj4 or WKT (%s) is wrong' % srs)
#         elif isinstance(srs, int):
#             # parse as EPSG code
#             status = self.ImportFromEPSG(srs)
#             if status > 0:
#                 raise NansatProjectionError('EPSG %d is wrong' % srs)
#         elif type(srs) in [osr.SpatialReference, NSR]:
#             # parse from input Spatial Reference
#             status = self.ImportFromWkt(srs.ExportToWkt())
#             if status > 0:
#                 raise NansatProjectionError('NSR %s is wrong' % srs)
# 
#     @property
#     def wkt(self):
#         """Well Known Text representation of SRS"""
#         return self.ExportToWkt()
# 
# Path: nansat/utils.py
#     MATPLOTLIB_IS_INSTALLED = False
#     MATPLOTLIB_IS_INSTALLED = True
# NUMPY_TO_GDAL_TYPE_MAP = {
#         'uint8': 1,
#         'int8': 1,
#         'uint16': 2,
#         'int16': 3,
#         'uint32': 4,
#         'int32': 5,
#         'float32': 6,
#         'float64': 7,
#         'complex64': 10,
#         'complex128': 11
#     }
# def remove_keys(dict, keys):
# def register_colormaps():
# def initial_bearing(lon1, lat1, lon2, lat2):
# def haversine(lon1, lat1, lon2, lat2):
# def add_logger(logName='', logLevel=None):
# def get_random_color(c0=None, minDist=100, low=0, high=255):
# def parse_time(time_string):
# 
# Path: nansat/exceptions.py
# class NansatProjectionError(Exception):
#     """ Cannot get the projection """
#     pass


import unittest
from nansat import NSR
from nansat.utils import osr
from nansat.exceptions import NansatProjectionError

    def test_init_from_proj4_unicode(self):
        nsr = NSR(u'+proj=longlat')

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_init_from_wkt(self):
        nsr = NSR(
        'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,'\
        'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,'\
        'AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],'\
        'AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]')

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_init_from_NSR(self):
        nsr = NSR(NSR(4326))

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_dont_init_from_invalid(self):
        self.assertRaises(NansatProjectionError, NSR, -10)
        self.assertRaises(NansatProjectionError, NSR, 'some crap')
        ss = osr.SpatialReference()

# Path: nansat/nsr.py
# class NSR(osr.SpatialReference, object):
#     """Nansat Spatial Reference. Overrides constructor of osr.SpatialReference.
# 
#     Parameters
#     ----------
#     srs : 0, PROJ4 or EPSG or WKT or osr.SpatialReference, NSR
#         Specifies spatial reference system (SRS)
#         PROJ4:
#         string with proj4 options [http://trac.osgeo.org/proj/] e.g.:
#         '+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs'
#         '+proj=stere +datum=WGS84 +ellps=WGS84 +lat_0=75 +lon_0=0 +no_defs'
#         EPSG:
#         integer with EPSG number, [http://spatialreference.org/],
#         e.g. 4326
#         WKT:
#         string with Well Know Text of SRS. E.g.:
#         'GEOGCS["WGS 84",
#             DATUM["WGS_1984",
#                 SPHEROID["WGS 84",6378137,298.257223563,
#                     AUTHORITY["EPSG","7030"]],
#                 TOWGS84[0,0,0,0,0,0,0],
#                 AUTHORITY["EPSG","6326"]],
#             PRIMEM["Greenwich",0,
#                 AUTHORITY["EPSG","8901"]],
#             UNIT["degree",0.0174532925199433,
#                 AUTHORITY["EPSG","9108"]],
#             AUTHORITY["EPSG","4326"]]'
# 
#     """
# 
#     def __init__(self, srs=0):
#         """Create Spatial Reference System from input parameter"""
#         if sys.version_info.major == 2:
#             str_types = (str, unicode)
#         else:
#             str_types = str
#         # create SRS
#         osr.SpatialReference.__init__(self)
# 
#         # parse input parameters
#         status = 1
#         if srs is 0:
#             # generate default WGS84 SRS
#             status = self.ImportFromEPSG(4326)
#         elif isinstance(srs, str_types):
#             # parse as proj4 string
#             status = self.ImportFromProj4(str(srs))
#             if status > 0:
#                 # parse as WKT string
#                 status = self.ImportFromWkt(str(srs))
#             if status > 0:
#                 raise NansatProjectionError('Proj4 or WKT (%s) is wrong' % srs)
#         elif isinstance(srs, int):
#             # parse as EPSG code
#             status = self.ImportFromEPSG(srs)
#             if status > 0:
#                 raise NansatProjectionError('EPSG %d is wrong' % srs)
#         elif type(srs) in [osr.SpatialReference, NSR]:
#             # parse from input Spatial Reference
#             status = self.ImportFromWkt(srs.ExportToWkt())
#             if status > 0:
#                 raise NansatProjectionError('NSR %s is wrong' % srs)
# 
#     @property
#     def wkt(self):
#         """Well Known Text representation of SRS"""
#         return self.ExportToWkt()
# 
# Path: nansat/utils.py
#     MATPLOTLIB_IS_INSTALLED = False
#     MATPLOTLIB_IS_INSTALLED = True
# NUMPY_TO_GDAL_TYPE_MAP = {
#         'uint8': 1,
#         'int8': 1,
#         'uint16': 2,
#         'int16': 3,
#         'uint32': 4,
#         'int32': 5,
#         'float32': 6,
#         'float64': 7,
#         'complex64': 10,
#         'complex128': 11
#     }
# def remove_keys(dict, keys):
# def register_colormaps():
# def initial_bearing(lon1, lat1, lon2, lat2):
# def haversine(lon1, lat1, lon2, lat2):
# def add_logger(logName='', logLevel=None):
# def get_random_color(c0=None, minDist=100, low=0, high=255):
# def parse_time(time_string):
# 
# Path: nansat/exceptions.py
# class NansatProjectionError(Exception):
#     """ Cannot get the projection """
#     pass


# Path: nansat/tests/test_nsr.py
import unittest
from nansat import NSR
from nansat.utils import osr
from nansat.exceptions import NansatProjectionError


    def test_init_from_proj4_unicode(self):
        nsr = NSR(u'+proj=longlat')

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_init_from_wkt(self):
        nsr = NSR(
        'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,'\
        'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,'\
        'AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],'\
        'AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]')

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_init_from_NSR(self):
        nsr = NSR(NSR(4326))

        self.assertEqual(type(nsr), NSR)
        self.assertEqual(nsr.Validate(), 0)
        self.assertTrue('longlat' in nsr.ExportToProj4())

    def test_dont_init_from_invalid(self):
        self.assertRaises(NansatProjectionError, NSR, -10)
        self.assertRaises(NansatProjectionError, NSR, 'some crap')
        ss = osr.SpatialReference()

        self.assertRaises(NansatProjectionError, NSR, ss)