#!/usr/bin/env python
###############################################################################
# $Id: osr_erm.py 20894 2010-10-19 12:30:02Z dron $
#
# Project:  GDAL/OGR Test Suite
# Purpose:  Test ERMapper spatial reference implementation.
# Author:   Andrey Kiselev, dron@ak4719.spb.edu
# 
###############################################################################
# Copyright (c) 2010, Andrey Kiselev <dron@ak4719.spb.edu>
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
###############################################################################

import os
import sys

sys.path.append( '../pymod' )

import gdaltest
try:
    from osgeo import osr
except:
    import osr

###############################################################################
# Test for the http://trac.osgeo.org/gdal/ticket/3787 problem.
# Spherical datums should have inverse flattening parameter 0.0, not 1.0.
#

def osr_erm_1():
    
    for sphere_datum in ['SPHERE', 'SPHERE2', 'USSPHERE']:
        srs = osr.SpatialReference()
        srs.ImportFromERM('MRWORLD', sphere_datum, 'METRE')

        if srs.GetInvFlattening() != 0.0 \
           or abs(srs.GetSemiMajor() - srs.GetSemiMinor() > 0.0000005):
            gdaltest.post_reason('Wrong ERMapper spherical datum parameters (bug #3787). Be sure your "ecw_cs.wkt" is from 20890 revision or newer.')
            return 'fail'

    return 'success'

gdaltest_list = [ 
    osr_erm_1,
    None ]

if __name__ == '__main__':

    gdaltest.setup_run( 'osr_erm' )

    gdaltest.run_tests( gdaltest_list )

    gdaltest.summarize()

