~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to tests/algorithms/projections/projectioncshandlingtest.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
     projectioncshandlingtest.h
 
3
     --------------------------------------
 
4
    Date                 : Sun Sep 16 12:20:35 AKDT 2007
 
5
    Copyright            : (C) 2007 by Gary E. Sherman
 
6
    Email                : sherman at mrcc dot com
 
7
 ***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************/
1
15
#include <iostream>
2
16
#include <fstream>
3
17
#include <cppunit/TestCase.h>
8
22
#include <qstring.h>
9
23
//gdal and ogr includes
10
24
#include <ogr_api.h>
11
 
#include <ogr_spatialref.h>
 
25
#include <ogr_srs_api.h>
12
26
#include <cpl_error.h>
13
 
class ProjectionCsHandlingTest : public CppUnit::TestCase { 
14
 
  public: 
15
 
    ProjectionCsHandlingTest(){}
 
27
class ProjectionCsHandlingTest : public CppUnit::TestCase
 
28
{
 
29
  public:
 
30
    ProjectionCsHandlingTest() {}
16
31
 
17
32
    ProjectionCsHandlingTest( std::string name ) : CppUnit::TestCase( name ) { }
18
33
 
19
34
    static CppUnit::Test *suite()
20
35
    {
21
36
      CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "ProjectionCsHandlingTest" );
22
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
23
 
            "testProjImportWkt", 
24
 
            &ProjectionCsHandlingTest::testProjImportWkt ) );
25
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
26
 
            "testProjExportToProj4", 
27
 
            &ProjectionCsHandlingTest::testProjExportToProj4 ) );
28
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
29
 
            "testProjNad27ExportToProj4", 
30
 
            &ProjectionCsHandlingTest::testProjNad27ExportToProj4 ) );
31
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
32
 
            "testProjNad83ExportToProj4", 
33
 
            &ProjectionCsHandlingTest::testProjNad83ExportToProj4 ) );
34
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
35
 
            "testFetchWktAttributes",
36
 
            &ProjectionCsHandlingTest::testFetchWktAttributes ) );
37
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
38
 
            "testProjEpsgExportToProj4",
39
 
            &ProjectionCsHandlingTest::testProjEpsgExportToProj4 ) );
40
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
41
 
            "testAkAlbersExportToProj4NoMorph",
42
 
            &ProjectionCsHandlingTest::testAkAlbersExportToProj4NoMorph ) );
43
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
44
 
            "testAkAlbersExportToProj4Morph",
45
 
            &ProjectionCsHandlingTest::testAkAlbersExportToProj4Morph ) ); suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
46
 
            "testWktFromFile",
47
 
            &ProjectionCsHandlingTest::testWktFromFile ) );
48
 
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>( 
49
 
            "testOgrTransform",
50
 
            &ProjectionCsHandlingTest::testOgrTransform ) );
 
37
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
38
                               "testProjImportWkt",
 
39
                               &ProjectionCsHandlingTest::testProjImportWkt ) );
 
40
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
41
                               "testProjExportToProj4",
 
42
                               &ProjectionCsHandlingTest::testProjExportToProj4 ) );
 
43
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
44
                               "testProjNad27ExportToProj4",
 
45
                               &ProjectionCsHandlingTest::testProjNad27ExportToProj4 ) );
 
46
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
47
                               "testProjNad83ExportToProj4",
 
48
                               &ProjectionCsHandlingTest::testProjNad83ExportToProj4 ) );
 
49
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
50
                               "testFetchWktAttributes",
 
51
                               &ProjectionCsHandlingTest::testFetchWktAttributes ) );
 
52
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
53
                               "testProjEpsgExportToProj4",
 
54
                               &ProjectionCsHandlingTest::testProjEpsgExportToProj4 ) );
 
55
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
56
                               "testAkAlbersExportToProj4NoMorph",
 
57
                               &ProjectionCsHandlingTest::testAkAlbersExportToProj4NoMorph ) );
 
58
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
59
                               "testAkAlbersExportToProj4Morph",
 
60
                               &ProjectionCsHandlingTest::testAkAlbersExportToProj4Morph ) ); suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
61
                                     "testWktFromFile",
 
62
                                     &ProjectionCsHandlingTest::testWktFromFile ) );
 
63
      suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
 
64
                               "testOgrTransform",
 
65
                               &ProjectionCsHandlingTest::testOgrTransform ) );
51
66
      return suiteOfTests;
52
 
    }  
53
 
    // 
 
67
    }
 
68
    //
54
69
    // Setup the common test members, etc
55
70
    //
56
71
    void setUp()
57
72
    {
58
73
      // wkt for creating a spatial refernence system
59
74
      wkt =   "GEOGCS[\"WGS 84\", "
60
 
        "  DATUM[\"WGS_1984\", "
61
 
        "    SPHEROID[\"WGS 84\",6378137,298.257223563, "
62
 
        "      AUTHORITY[\"EPSG\",7030]], "
63
 
        "    TOWGS84[0,0,0,0,0,0,0], "
64
 
        "    AUTHORITY[\"EPSG\",6326]], "
65
 
        "  PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
66
 
        "  UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
67
 
        "  AXIS[\"Lat\",NORTH], "
68
 
        "  AXIS[\"Long\",EAST], "
69
 
        "  AUTHORITY[\"EPSG\",4326]]";
 
75
              "  DATUM[\"WGS_1984\", "
 
76
              "    SPHEROID[\"WGS 84\",6378137,298.257223563, "
 
77
              "      AUTHORITY[\"EPSG\",7030]], "
 
78
              "    TOWGS84[0,0,0,0,0,0,0], "
 
79
              "    AUTHORITY[\"EPSG\",6326]], "
 
80
              "  PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
 
81
              "  UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
 
82
              "  AXIS[\"Lat\",NORTH], "
 
83
              "  AXIS[\"Long\",EAST], "
 
84
              "  AUTHORITY[\"EPSG\",4326]]";
70
85
      wktDest = "GEOGCS[\"GCS_North_American_1927\",DATUM[\"D_North_American_1927\",SPHEROID[\"Clarke_1866\",6378206.4,294.9786982]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]";
71
86
      wktDestNad83 = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
72
87
      wktEpsg = "GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.978698213901]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]]";
73
88
 
74
 
      wktAkAlbers = "PROJCS[\"Alaska_Albers_Equal_Area_Conic\",GEOGCS[\"GCS_North_American_1927\",DATUM[\"D_North_American_1927\",SPHEROID[\"Clarke_1866\",6378206.4,294.9786982]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Albers\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-154.0],PARAMETER[\"Standard_Parallel_1\",55.0],PARAMETER[\"Standard_Parallel_2\",65.0],PARAMETER[\"Latitude_Of_Origin\",50.0],UNIT[\"Meter\",1.0]]";
 
89
      wktAkAlbers = "PROJCS[\"Alaska_Albers_Equal_Area_Conic\",GEOGCS[\"GCS_North_American_1927\",DATUM[\"D_North_American_1927\",SPHEROID[\"Clarke_1866\",6378206.4,294.9786982]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],CRS[\"Albers\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-154.0],PARAMETER[\"Standard_Parallel_1\",55.0],PARAMETER[\"Standard_Parallel_2\",65.0],PARAMETER[\"Latitude_Of_Origin\",50.0],UNIT[\"Meter\",1.0]]";
75
90
    }
76
91
 
77
92
    //
78
93
    // Test creation of a OGRSpatialReference object from wkt
79
94
    //
80
 
    void testProjImportWkt() {
 
95
    void testProjImportWkt()
 
96
    {
81
97
      // create a spatial reference system object
82
 
      std::cout << "\n\nCreating and OGRSpatialReference object from WKT" << std::endl; 
83
 
      OGRSpatialReference myInputSpatialRefSys;
84
 
      char *pWkt = (char*)wkt.ascii();
85
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
98
      std::cout << "\n\nCreating and OGRSpatialReference object from Wkt" << std::endl;
 
99
      OGRSpatialReferenceH myInputSpatialRefSys = OSRNewSpatialReference( NULL );
 
100
      char *pWkt = ( char* )wkt.ascii();
 
101
      CPPUNIT_ASSERT( OSRImportFromWkt( myInputSpatialRefSys, &pWkt ) == OGRERR_NONE );
 
102
      OSRDestroySpatialReference( myInputSpatialRefSys );
86
103
    }
87
104
    //
88
105
    // Test fetch of proj4 parameters from an OGRSpatialReference object
90
107
    //
91
108
    void testProjExportToProj4()
92
109
    {
93
 
      std::cout << "\n\nGetting proj4 parameters from OGRSpatialReference object" << std::endl; 
 
110
      std::cout << "\n\nGetting proj4 parameters from OGRSpatialReference object" << std::endl;
94
111
      // set up the spatial ref
95
 
      OGRSpatialReference myInputSpatialRefSys;
96
 
      char *pWkt = (char*)wkt.ascii();
97
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
112
      OGRSpatialReferenceH myInputSpatialRefSys;
 
113
      char *pWkt = ( char* )wkt.ascii();
 
114
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
98
115
      // get the proj4 for the projection
99
116
      char *proj4src;
100
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
101
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
102
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
117
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
118
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
119
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
103
120
 
104
121
    }
105
122
    //
108
125
    //
109
126
    void testProjNad27ExportToProj4()
110
127
    {
111
 
      std::cout << "\n\nGetting NAD27 proj4 parameters from OGRSpatialReference object" << std::endl; 
 
128
      std::cout << "\n\nGetting NAD27 proj4 parameters from OGRSpatialReference object" << std::endl;
112
129
      // set up the spatial ref
113
130
      OGRSpatialReference myInputSpatialRefSys;
114
 
      char *pWkt = (char*)wktDest.ascii();
115
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
131
      char *pWkt = ( char* )wktDest.ascii();
 
132
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
116
133
      // get the proj4 for the projection
117
134
      char *proj4src;
118
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
119
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
120
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
135
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
136
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
137
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
121
138
 
122
139
    }
123
140
    //
126
143
    //
127
144
    void testProjNad83ExportToProj4()
128
145
    {
129
 
      std::cout << "\n\nGetting NAD83 proj4 parameters used in states.shp" << std::endl; 
 
146
      std::cout << "\n\nGetting NAD83 proj4 parameters used in states.shp" << std::endl;
130
147
      // set up the spatial ref
131
148
      OGRSpatialReference myInputSpatialRefSys;
132
 
      char *pWkt = (char*)wktDestNad83.ascii();
133
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
149
      char *pWkt = ( char* )wktDestNad83.ascii();
 
150
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
134
151
      // morph it from esri
135
 
      std::cout << "\tMorphing from ESRI to standard form before getting proj4 parameters" << std::endl; 
136
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE);
 
152
      std::cout << "\tMorphing from ESRI to standard form before getting proj4 parameters" << std::endl;
 
153
      CPPUNIT_ASSERT( myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE );
137
154
      // get the proj4 for the projection
138
155
      char *proj4src;
139
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
140
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
141
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
156
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
157
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
158
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
142
159
    }
143
160
    //
144
161
    // Test fetch of proj4 parameters from GEOGCS NAD83 OGRSpatialReference object
145
 
    // in EPSG format
 
162
    // in EpsgCrsId format
146
163
    // Failure occurs if datum field is not found in the proj4 parameter string
147
164
    //
148
165
    void testProjEpsgExportToProj4()
149
166
    {
150
 
      std::cout << "\n\nGetting NAD83 proj4 parameters from an EPSG format WKT" << std::endl; 
 
167
      std::cout << "\n\nGetting NAD83 proj4 parameters from an EpsgCrsId format Wkt" << std::endl;
151
168
      // set up the spatial ref
152
169
      OGRSpatialReference myInputSpatialRefSys;
153
 
      char *pWkt = (char*)wktEpsg.ascii();
154
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
170
      char *pWkt = ( char* )wktEpsg.ascii();
 
171
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
155
172
      // get the proj4 for the projection
156
173
      char *proj4src;
157
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
158
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
159
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
174
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
175
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
176
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
160
177
    }
161
178
    //
162
179
    // Test fetch of proj4 parameters from Alaska Albers  OGRSpatialReference object
165
182
    //
166
183
    void testAkAlbersExportToProj4NoMorph()
167
184
    {
168
 
      std::cout << "\n\nGetting Alaska Albers proj4 parameters from kodiak.prj" << std::endl; 
 
185
      std::cout << "\n\nGetting Alaska Albers proj4 parameters from kodiak.prj" << std::endl;
169
186
      // set up the spatial ref
170
187
      OGRSpatialReference myInputSpatialRefSys;
171
 
      char *pWkt = (char*)wktAkAlbers.ascii();
172
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
173
 
      std::cout << "\tGetting proj4 paramters without morph to ESRI form" << std::endl; 
 
188
      char *pWkt = ( char* )wktAkAlbers.ascii();
 
189
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
 
190
      std::cout << "\tGetting proj4 parameters without morph to ESRI form" << std::endl;
174
191
      // get the proj4 for the unmorphed projection
175
192
      char *proj4src;
176
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
177
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
178
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
193
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
194
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
195
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
179
196
    }
180
197
    //
181
198
    // Test fetch of proj4 parameters from Alaska Albers  OGRSpatialReference object
184
201
    //
185
202
    void testAkAlbersExportToProj4Morph()
186
203
    {
187
 
      std::cout << "\n\nGetting Alaska Albers proj4 parameters from kodiak.prj" << std::endl; 
 
204
      std::cout << "\n\nGetting Alaska Albers proj4 parameters from kodiak.prj" << std::endl;
188
205
      // set up the spatial ref
189
206
      OGRSpatialReference myInputSpatialRefSys;
190
 
      char *pWkt = (char*)wktAkAlbers.ascii();
191
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
192
 
      std::cout << "\tGetting proj4 paramters with morph to ESRI form" << std::endl; 
193
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE);
 
207
      char *pWkt = ( char* )wktAkAlbers.ascii();
 
208
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
 
209
      std::cout << "\tGetting proj4 parameters with morph to ESRI form" << std::endl;
 
210
      CPPUNIT_ASSERT( myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE );
194
211
      // get the proj4 for the unmorphed projection
195
212
      char *proj4src;
196
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
197
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
198
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
213
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
214
      std::cout << "\tPROJ4: " << proj4src << std::endl;
 
215
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
199
216
    }
200
217
    //
201
218
    // Test fetching of wkt properties from a spatial ref object
202
219
    //
203
220
    void testFetchWktAttributes()
204
221
    {
205
 
      std::cout << "\n\nFetching states.prj WKT attributes using OGRSpatialReference::GetAttrValue" << std::endl; 
 
222
      std::cout << "\n\nFetching states.prj Wkt attributes using OGRSpatialReference::GetAttrValue" << std::endl;
206
223
      // set up the spatial ref - use the nad83 from states.prj
207
224
      OGRSpatialReference myInputSpatialRefSys;
208
 
      char *pWkt = (char*)wktDestNad83.ascii();
209
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
 
225
      char *pWkt = ( char* )wktDestNad83.ascii();
 
226
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
210
227
      // test access to the datum
211
 
      const char *datum = myInputSpatialRefSys.GetAttrValue("DATUM", 0);
212
 
      CPPUNIT_ASSERT(datum != 0);
213
 
      std::cout << "\tDatum: " << datum << std::endl; 
 
228
      const char *datum = myInputSpatialRefSys.GetAttrValue( "DATUM", 0 );
 
229
      CPPUNIT_ASSERT( datum != 0 );
 
230
      std::cout << "\tDatum: " << datum << std::endl;
214
231
    }
215
232
    //
216
 
    // Test the WKT contained in wkt.txt in the current directory to see if
 
233
    // Test the Wkt contained in wkt.txt in the current directory to see if
217
234
    // the datum can be determined
218
235
    //
219
236
    void testWktFromFile()
220
237
    {
221
 
      std::ifstream wktIn("./wkt.txt");
 
238
      std::ifstream wktIn( "./wkt.txt" );
222
239
      char *buf = new char[16384];
223
 
      wktIn.getline(buf, 16384);
 
240
      wktIn.getline( buf, 16384 );
224
241
      wktIn.close();
225
 
      std::cout << "\n\nGetting proj4 parameters from wkt.txt" << std::endl; 
226
 
      std::cout << buf << std::endl; 
 
242
      std::cout << "\n\nGetting proj4 parameters from wkt.txt" << std::endl;
 
243
      std::cout << buf << std::endl;
227
244
      // set up the spatial ref
228
245
      OGRSpatialReference myInputSpatialRefSys;
229
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&buf)== OGRERR_NONE);
230
 
      //      std::cout << "\tGetting proj4 paramters with morph to ESRI form" << std::endl; 
 
246
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &buf ) == OGRERR_NONE );
 
247
      //      std::cout << "\tGetting proj4 parameters with morph to ESRI form" << std::endl;
231
248
      //      CPPUNIT_ASSERT(myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE);
232
249
      // get the proj4 for the unmorphed projection
233
250
      char *proj4src;
234
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
235
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
 
251
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
252
      std::cout << "\tPROJ4: " << proj4src << std::endl;
236
253
      // morph it then spew it
237
254
      myInputSpatialRefSys.morphFromESRI();
238
 
      myInputSpatialRefSys.exportToProj4(&proj4src);
239
 
      std::cout << "\tMorphed PROJ4: " << proj4src << std::endl;  
240
 
      CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
 
255
      myInputSpatialRefSys.exportToProj4( &proj4src );
 
256
      std::cout << "\tMorphed PROJ4: " << proj4src << std::endl;
 
257
      CPPUNIT_ASSERT( QString( proj4src ).find( "datum" ) > -1 );
241
258
 
242
259
    }
243
260
    void testOgrTransform()
244
261
    {
245
 
      std::cout << "\n\nTesting OGR transform of kodiak.prj to WGS 84 Geographic" << std::endl; 
 
262
      std::cout << "\n\nTesting OGR transform of kodiak.prj to WGS 84 Geographic" << std::endl;
246
263
      // set up the spatial ref
247
264
      OGRSpatialReference myInputSpatialRefSys;
248
 
      char *pWkt = (char*)wktAkAlbers.ascii();
249
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
250
 
      std::cout << "\tGetting proj4 paramters with morph to ESRI form" << std::endl; 
251
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE);
252
 
      OGRSpatialReference oTargetSRS;
253
 
      char *pWgs84 = (char *)wkt.ascii();
254
 
      oTargetSRS.importFromWkt(&pWgs84);
 
265
      char *pWkt = ( char* )wktAkAlbers.ascii();
 
266
      CPPUNIT_ASSERT( myInputSpatialRefSys.importFromWkt( &pWkt ) == OGRERR_NONE );
 
267
      std::cout << "\tGetting proj4 parameters with morph to ESRI form" << std::endl;
 
268
      CPPUNIT_ASSERT( myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE );
 
269
      OGRSpatialReference oTarcrs;
 
270
      char *pWgs84 = ( char * )wkt.ascii();
 
271
      oTarcrs.importFromWkt( &pWgs84 );
255
272
      OGRCoordinateTransformation *poCT;
256
273
      poCT = OGRCreateCoordinateTransformation( &myInputSpatialRefSys,
257
 
          &oTargetSRS );
 
274
             &oTarcrs );
258
275
      double x = 0.0;
259
276
      double y = 0.0;
260
 
      poCT->Transform(1, &x, &y);
261
 
      std::cout << "Transformed 0,0 albers point = " << x << ", " << y << std::endl; 
262
 
      CPPUNIT_ASSERT((x == -154.0) || (y == 50.0));
 
277
      poCT->Transform( 1, &x, &y );
 
278
      std::cout << "Transformed 0,0 albers point = " << x << ", " << y << std::endl;
 
279
      CPPUNIT_ASSERT(( x == -154.0 ) || ( y == 50.0 ) );
263
280
      // get the proj4 for the morphed projection
264
281
      char *proj4src;
265
 
      CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
266
 
      std::cout << "\tPROJ4: " << proj4src << std::endl;  
 
282
      CPPUNIT_ASSERT( myInputSpatialRefSys.exportToProj4( &proj4src ) == OGRERR_NONE );
 
283
      std::cout << "\tPROJ4: " << proj4src << std::endl;
267
284
 
268
 
      std::cout << "Testing inverse transform" << std::endl; 
269
 
      poCT = OGRCreateCoordinateTransformation( &oTargetSRS, &myInputSpatialRefSys);
 
285
      std::cout << "Testing inverse transform" << std::endl;
 
286
      poCT = OGRCreateCoordinateTransformation( &oTarcrs, &myInputSpatialRefSys );
270
287
      x = -154.0;
271
288
      y = 50.0;
272
 
      poCT->Transform(1, &x, &y);
273
 
      CPPUNIT_ASSERT((x == 0) || (y == 0));
274
 
      std::cout << "Transformed -154,50 geographic point = " << x << ", " << y << std::endl; 
 
289
      poCT->Transform( 1, &x, &y );
 
290
      CPPUNIT_ASSERT(( x == 0 ) || ( y == 0 ) );
 
291
      std::cout << "Transformed -154,50 geographic point = " << x << ", " << y << std::endl;
275
292
 
276
293
    }
277
294
 
278
295
  private:
279
 
    // WKT for default projection hardcoded in QgsCoordinateTransform class
 
296
    // Wkt for default projection hardcoded in QgsCoordinateTransform class
280
297
    QString wkt;
281
 
    // WKT for an ESRI style GEOGCS in NAD27
 
298
    // Wkt for an ESRI style GEOGCS in NAD27
282
299
    QString wktDest;
283
 
    // WKT for an ESRI style GEOGCS in NAD83 (from states.shp shapefile)
 
300
    // Wkt for an ESRI style GEOGCS in NAD83 (from states.shp shapefile)
284
301
    QString wktDestNad83;
285
 
    // WKT for an EPSG style GEOGCS
 
302
    // Wkt for an EpsgCrsId style GEOGCS
286
303
    QString wktEpsg;
287
 
    // WKT for an ESRI style PROJCS as read from a shapefile
 
304
    // Wkt for an ESRI style PROJCS as read from a shapefile
288
305
    QString wktAkAlbers;
289
306
};
290
307