diff options
| author | Kristian Evers <kristianevers@gmail.com> | 2020-12-13 15:30:47 +0100 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2020-12-13 15:30:47 +0100 |
| commit | c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98 (patch) | |
| tree | a204df79f7057d7d420bf7c5358791347617b9cd /src/tests | |
| parent | 126445148d3b742c7f4e31f5f65857be59c48340 (diff) | |
| parent | 6857d1a4a8eb6fcb7b88b0339413913ba2c3351a (diff) | |
| download | PROJ-c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98.tar.gz PROJ-c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98.zip | |
Merge remote-tracking branch 'osgeo/master'
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/multistresstest.cpp | 172 | ||||
| -rw-r--r-- | src/tests/test228.cpp | 113 |
2 files changed, 73 insertions, 212 deletions
diff --git a/src/tests/multistresstest.cpp b/src/tests/multistresstest.cpp index 33d2d738..6b7099ce 100644 --- a/src/tests/multistresstest.cpp +++ b/src/tests/multistresstest.cpp @@ -30,11 +30,7 @@ #include <stdlib.h> #include <string.h> -#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H -#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H -#endif - -#include "proj_api.h" +#include "proj.h" #ifdef _WIN32 #include <windows.h> @@ -51,8 +47,8 @@ typedef struct { const char *src_def; const char *dst_def; - double src_x, src_y, src_z; - double dst_x, dst_y, dst_z; + PJ_COORD src; + PJ_COORD dst; int dst_error; int skip; @@ -62,125 +58,120 @@ static TestItem test_list[] = { { "+proj=utm +zone=11 +datum=WGS84", "+proj=latlong +datum=WGS84", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=utm +zone=11 +datum=NAD83", "+proj=latlong +datum=NAD27", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=utm +zone=11 +datum=NAD83", "+proj=latlong +nadgrids=@null +ellps=WGS84", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=utm +zone=11 +datum=WGS84", "+proj=merc +datum=potsdam", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=latlong +nadgrids=nzgd2kgrid0005.gsb", "+proj=latlong +datum=WGS84", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=latlong +nadgrids=nzgd2kgrid0005.gsb", "+proj=latlong +datum=WGS84", - 170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0, - 0.0, 0.0, 0.0, + proj_coord(170, -40, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=latlong +ellps=GRS80 +towgs84=2,3,5", "+proj=latlong +ellps=intl +towgs84=10,12,15", - 170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0, - 0.0, 0.0, 0.0, + proj_coord(170, -40, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=eqc +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", "+proj=stere +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=cea +lat_ts=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=merc +lon_0=12 +k=0.999 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=bonne +lat_1=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=cass +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=nzmg +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=gnom +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=ortho +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=laea +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=aeqd +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=eqdc +lat_1=20 +lat_2=5 +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+proj=mill +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ", "+proj=moll +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ", - 150000.0, 250000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 250000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { "+init=epsg:3309", "+init=epsg:4326", - 150000.0, 30000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 30000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 }, { /* Bad projection (invalid ellipsoid parameter +R_A=0) */ "+proj=utm +zone=11 +datum=WGS84", "+proj=merc +datum=potsdam +R_A=0", - 150000.0, 3000000.0, 0.0, - 0.0, 0.0, 0.0, + proj_coord(150000.0, 3000000.0, 0.0, 0.0), + proj_coord(0.0, 0.0, 0.0, 0.0), 0, 0 } }; static volatile int active_thread_count = 0; -static projPJ custom_pj_init_plus_ctx(projCtx ctx, const char* def) -{ - return pj_init_plus_ctx(ctx, def); -} - /************************************************************************/ /* TestThread() */ /************************************************************************/ @@ -195,11 +186,10 @@ static void TestThread() /* -------------------------------------------------------------------- */ /* Initialize coordinate system definitions. */ /* -------------------------------------------------------------------- */ - projPJ *src_pj_list, *dst_pj_list; - projCtx ctx = pj_ctx_alloc(); + PJ **pj_list; + PJ_CONTEXT *ctx = proj_context_create(); - src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); - dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); + pj_list = (PJ **) calloc(test_count,sizeof(PJ*)); if(!reinit_every_iteration) { @@ -207,8 +197,9 @@ static void TestThread() { TestItem *test = test_list + i; - src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def ); - dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def ); + pj_list[i] = proj_create_crs_to_crs( + ctx, test->src_def, test->dst_def, nullptr + ); } } @@ -221,28 +212,23 @@ static void TestThread() for( i = 0; i < test_count; i++ ) { TestItem *test = test_list + i; - double x, y, z; - int error; - - x = test->src_x; - y = test->src_y; - z = test->src_z; if( reinit_every_iteration ) { - src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def ); - dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def ); + proj_context_use_proj4_init_rules(nullptr, true); + pj_list[i] = proj_create_crs_to_crs( + ctx, test->src_def, test->dst_def, nullptr + ); { - int skipTest = (src_pj_list[i] == nullptr || dst_pj_list[i] == nullptr); + int skipTest = (pj_list[i] == nullptr); if ( skipTest != test->skip ) fprintf( stderr, "Threaded projection initialization does not match unthreaded initialization\n" ); if (skipTest) { - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); + proj_destroy( pj_list[i] ); continue; } } @@ -251,31 +237,32 @@ static void TestThread() if ( test->skip ) continue; - error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0, - &x, &y, &z ); + PJ_COORD out = proj_trans(pj_list[i], PJ_FWD, test->src); + int error = proj_errno(pj_list[i]); if( error != test->dst_error ) { fprintf( stderr, "Got error %d, expected %d\n", error, test->dst_error ); } + proj_errno_reset(pj_list[i]); - if( x != test->dst_x || y != test->dst_y || z != test->dst_z ) + if ( out.xyz.x != test->dst.xyz.x || out.xyz.y != test->dst.xyz.y || out.xyz.z != test->dst.xyz.z) + //if( x != test->dst_x || y != test->dst_y || z != test->dst_z ) { fprintf( stderr, "Got %.15g,%.15g,%.15g\n" "Expected %.15g,%.15g,%.15g\n" "Diff %.15g,%.15g,%.15g\n", - x, y, z, - test->dst_x, test->dst_y, test->dst_z, - x-test->dst_x, y-test->dst_y, z-test->dst_z); + out.xyz.x, out.xyz.y, out.xyz.z, + test->dst.xyz.x, test->dst.xyz.y, test->dst.xyz.z, + out.xyz.x-test->dst.xyz.x, out.xyz.y-test->dst.xyz.y, out.xyz.z-test->dst.xyz.z); } if( reinit_every_iteration ) { - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); + proj_destroy( pj_list[i] ); } } } @@ -287,15 +274,13 @@ static void TestThread() { for( i = 0; i < test_count; i++ ) { - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); + proj_destroy( pj_list[i] ); } } - free( src_pj_list ); - free( dst_pj_list ); + free( pj_list ); - pj_ctx_free( ctx ); + proj_context_destroy( ctx ); printf( "%d iterations of the %d tests complete in thread X\n", repeat_count, test_count ); @@ -349,43 +334,32 @@ static int do_main(void) { TestItem *test = test_list + i; - projPJ src_pj, dst_pj; + PJ *pj; - src_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->src_def ); - dst_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->dst_def ); - - if( src_pj == nullptr ) - { - printf( "Unable to translate:\n%s\n", test->src_def ); - test->skip = 1; - pj_free (dst_pj); - continue; - } + proj_context_use_proj4_init_rules(nullptr, true); + pj = proj_create_crs_to_crs( + nullptr, test->src_def, test->dst_def, nullptr + ); - if( dst_pj == nullptr ) + if( pj == nullptr ) { - printf( "Unable to translate:\n%s\n", test->dst_def ); + printf( "Unable to translate:\n%s\n or\n%s\n", test->src_def, test->dst_def ); test->skip = 1; - pj_free (src_pj); + proj_destroy(pj); continue; } - test->dst_x = test->src_x; - test->dst_y = test->src_y; - test->dst_z = test->src_z; - test->dst_error = pj_transform( src_pj, dst_pj, 1, 0, - &(test->dst_x), - &(test->dst_y), - &(test->dst_z) ); + PJ_COORD out = proj_trans(pj, PJ_FWD, test->src); + test->dst = out; + test->dst_error = proj_errno(pj); - pj_free( src_pj ); - pj_free( dst_pj ); + proj_destroy(pj); test->skip = 0; -#ifdef notdef - printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst_x, test->dst_y, test->dst_z ); +#ifdef nodef + printf( "Test %d - output %.14g,%.14g,%g\n", i, test->dst.xyz.x, test->dst.xyz.y, test->dst.xyz.z ); #endif } diff --git a/src/tests/test228.cpp b/src/tests/test228.cpp deleted file mode 100644 index 8ae17c87..00000000 --- a/src/tests/test228.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/****************************************************************************** - * - * Project: PROJ - * Purpose: Test - * Author: Even Rouault <even dot rouault at spatialys dot com> - * - ****************************************************************************** - * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys dot com> - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - ****************************************************************************/ - -#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H -#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H -#endif - -#include "proj_api.h" -#include <stdio.h> /* for printf declaration */ - - -#ifdef _WIN32 - -int main(int argc, char* argv[]) -{ - printf("Test not yet ported on Win32\n"); - return 0; -} - -#else - -#include <pthread.h> -#include <stdio.h> -#include <assert.h> -#include <unistd.h> - -static volatile int run = 0; -static volatile int started = 0; - -static void* thread_main(void* unused) -{ - projCtx p_proj_ctxt; - projPJ p_WGS84_proj; - projPJ p_OSGB36_proj; - (void)unused; - - __sync_add_and_fetch(&started, 1); - while(run == 0); - - p_proj_ctxt=pj_ctx_alloc(); - p_WGS84_proj=pj_init_plus_ctx(p_proj_ctxt,"+proj=longlat " - "+ellps=WGS84 +datum=WGS84"); - p_OSGB36_proj=pj_init_plus_ctx(p_proj_ctxt, - "+proj=longlat +ellps=airy +datum=OSGB36 +nadgrids=OSTN15_NTv2_OSGBtoETRS.gsb"); - - while(run) - { - double x, y; - int proj_ret; - - x = -5.2*DEG_TO_RAD; - y = 50*DEG_TO_RAD; - proj_ret = pj_transform(p_WGS84_proj, - p_OSGB36_proj, 1, 1, &x, &y, nullptr ); - x *= RAD_TO_DEG; - y *= RAD_TO_DEG; - /*printf("%.18f %.18f\n", x, y); */ - assert(proj_ret == 0); - assert(fabs(x - -5.198965207267856492) < 1e-15); - assert(fabs(y - 49.999396074140378232) < 1e-15); - } - - pj_free (p_OSGB36_proj); - pj_free (p_WGS84_proj); - return nullptr; -} - -int main() -{ - int i; - - pthread_t tid1, tid2; - pthread_attr_t attr1, attr2; - - pthread_attr_init(&attr1); - pthread_attr_init(&attr2); - - pthread_create(&tid1, &attr1, thread_main, nullptr); - pthread_create(&tid2, &attr2, thread_main, nullptr); - while(started != 2); - run = 1; - for(i=0;i<2;i++) - sleep(1); - run = 0; - return 0; -} - -#endif /* _WIN32 */ |
