~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to mapscript/php/php_proj.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 * $Id: php_proj.c 9937 2010-03-11 15:17:39Z aboudreault $
 
3
 *
 
4
 * Project:  MapServer
 
5
 * Purpose:  PHP wraper function to PROJ4 projection module.
 
6
 * Author:   Yewondwossen Assefa, DM Solutions Group (assefa@dmsolutions.ca)
 
7
 *
 
8
 **********************************************************************
 
9
 * Copyright (c) 2000-2005, Y. Assefa, DM Solutions Group inc.
 
10
 *
 
11
 * Permission is hereby granted, free of charge, to any person obtaining a
 
12
 * copy of this software and associated documentation files (the "Software"),
 
13
 * to deal in the Software without restriction, including without limitation
 
14
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
 * and/or sell copies of the Software, and to permit persons to whom the
 
16
 * Software is furnished to do so, subject to the following conditions:
 
17
 *
 
18
 * The above copyright notice and this permission notice shall be included in 
 
19
 * all copies of this Software or works derived from this Software.
 
20
 *
 
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
24
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
27
 * DEALINGS IN THE SOFTWARE.
 
28
 **********************************************************************
 
29
 *
 
30
 * $Log$
 
31
 * Revision 1.10  2005/06/14 16:03:36  dan
 
32
 * Updated copyright date to 2005
 
33
 *
 
34
 * Revision 1.9  2005/01/04 22:55:27  assefa
 
35
 * Add PHP5 support for windows (Bug 1100).
 
36
 *
 
37
 * Revision 1.8  2002/03/08 23:16:41  assefa
 
38
 * Add PHP4.1 support.
 
39
 *
 
40
 * Revision 1.7  2002/01/22 19:18:54  dan
 
41
 * Fixed a typo in pj_transform() docs
 
42
 *
 
43
 * Revision 1.6  2002/01/22 19:18:17  dan
 
44
 * Took pj_datum_transform() out of docs to discourage its use.
 
45
 *
 
46
 * Revision 1.5  2001/09/25 14:52:54  assefa
 
47
 * Add pj_transform function.
 
48
 *
 
49
 * Revision 1.4  2001/02/23 20:35:57  assefa
 
50
 * Free function does not work for PHP4. Disable it for now.
 
51
 *
 
52
 * Revision 1.3  2001/01/09 05:24:41  dan
 
53
 * Fixes to build with PHP 4.0.4
 
54
 *
 
55
 * Revision 1.2  2000/11/08 15:44:16  dan
 
56
 * Correct compilation errors with php4.
 
57
 *
 
58
 * Revision 1.1  2000/11/02 16:39:55  dan
 
59
 * PHP PROJ4 module.
 
60
 *
 
61
 *
 
62
 **********************************************************************/
 
63
 
 
64
/*
 
65
 *         PHP PROJ4 Module
 
66
 *
 
67
 *  This is a PHP module that gives acces to basic PROJ4 projection
 
68
 *  functionalities.
 
69
 *
 
70
 * There following functions available in this module :
 
71
 *
 
72
 * 1) pj_init : create and initializes a projection structures
 
73
 *
 
74
 *    PJ pj_init(array_of_parameters)
 
75
 *
 
76
 *    Example : $projarray[0] = "proj=lcc";
 
77
 *              $projarray[1] = "ellps=GRS80";
 
78
 *              $projarray[2] = "lat_0=49";
 
79
 *              $projarray[3] = "lon_0=-95";
 
80
 *              $projarray[4] = "lat_1=49";
 
81
 *              $projarray[5] = "lat_2=77";
 
82
 *
 
83
 *              $pj = pj_init($projarray);
 
84
 *
 
85
 * 2) pj_fwd : Performs a projection from lat/long coordinates to
 
86
 *             cartesian coordinates.
 
87
 *
 
88
 * retrun_array pj_fwd(double lat, double long, PJ pj)
 
89
 *
 
90
 *   Example :  $lat = 45.25;
 
91
 *              $long = -75.42;
 
92
 *
 
93
 *              $ret = pj_fwd($ingeox, $ingeoy, $pj);
 
94
 *              printf("geo x = %f<br>\n", $ret["u"]);
 
95
 *              printf("geo y = %f<br>\n",$ret["v"]);
 
96
 *
 
97
 * 3) pj_inv : Performs a projection from cartesian coordinates to
 
98
 *             lat/long  coordinates .
 
99
 *
 
100
 * retrun_array pj_fwd(double geox, double geoy, PJ pj)
 
101
 *
 
102
 *   Example :  $ingeox = 1537490.335842;
 
103
 *              $ingeoy = -181633.471555;
 
104
 *
 
105
 *              $ret = pj_inv($ingeox, $ingeoy, $pj);
 
106
 *              printf("lat = %f<br>\n", $ret["u"]);
 
107
 *              printf("lon = %f<br>\n",$ret["v"]);
 
108
 *
 
109
 *
 
110
 * 4) pj_transform : pj_transform(PJ pjsrc, PJ pjdst, double x, double y)
 
111
 *      transforms coordinates from source projection to
 
112
 *                   destination projection.
 
113
 *
 
114
 *   Example :  $projarray[0] = "proj=lcc";
 
115
 *              $projarray[1] = "ellps=GRS80";
 
116
 *              $projarray[2] = "lat_0=49";
 
117
 *              $projarray[3] = "lon_0=-95";
 
118
 *              $projarray[4] = "lat_1=49";
 
119
 *              $projarray[5] = "lat_2=77";
 
120
 *              $projarray[6] = "";
 
121
 *
 
122
 *              $pjlcc = pj_init($projarray);
 
123
 *              $projarray2[0] = "proj=latlong";
 
124
 *              $pjlat = pj_init($projarray2);
 
125
 *
 
126
 *              $ingeox = 1537490.335842;
 
127
 *              $ingeoy = -181633.471555;
 
128
 *
 
129
 *              $ret = pj_transform($pjlcc, $pjlat, $ingeox, $ingeoy);
 
130
 *
 
131
 * 5) pj_free : frees PJ structure
 
132
 *
 
133
 *  void pj_free(PJ pj);
 
134
 *
 
135
 **********************************************************************/
 
136
 
 
137
#ifdef USE_PROJ
 
138
#include <projects.h>
 
139
#include "php_mapscript_util.h"
 
140
 
 
141
#include "php.h"
 
142
#include "php_globals.h"
 
143
 
 
144
#include "maperror.h"
 
145
 
 
146
#include <time.h>
 
147
 
 
148
#if defined(_WIN32) && !defined(__CYGWIN__)
 
149
#include <process.h>
 
150
#else
 
151
#include <errno.h>
 
152
#endif
 
153
 
 
154
#define ZEND_DEBUG 0
 
155
 
 
156
#ifndef DLEXPORT
 
157
#define DLEXPORT ZEND_DLEXPORT
 
158
#endif
 
159
 
 
160
#define PHP_PROJ_VERSION "1.0.000 (Nov. 1, 2000)"
 
161
 
 
162
/*=====================================================================
 
163
 *                         Prototypes
 
164
 *====================================================================*/
 
165
DLEXPORT void php_proj_pj_init(INTERNAL_FUNCTION_PARAMETERS);
 
166
DLEXPORT void php_proj_pj_fwd(INTERNAL_FUNCTION_PARAMETERS);
 
167
DLEXPORT void php_proj_pj_inv(INTERNAL_FUNCTION_PARAMETERS);
 
168
DLEXPORT void php_proj_pj_transform(INTERNAL_FUNCTION_PARAMETERS);
 
169
DLEXPORT void php_proj_pj_datum_transform(INTERNAL_FUNCTION_PARAMETERS);
 
170
DLEXPORT void php_proj_pj_free(INTERNAL_FUNCTION_PARAMETERS);
 
171
 
 
172
 
 
173
DLEXPORT void php_info_proj(void);
 
174
DLEXPORT int  php_init_proj(INIT_FUNC_ARGS);
 
175
DLEXPORT int  php_end_proj(SHUTDOWN_FUNC_ARGS);
 
176
 
 
177
DLEXPORT void ttt(INTERNAL_FUNCTION_PARAMETERS);
 
178
 
 
179
#ifdef ZEND_VERSION
 
180
PHP_MINFO_FUNCTION(phpproj);
 
181
#else
 
182
DLEXPORT void php_info_proj(void);
 
183
#endif
 
184
 
 
185
static zend_class_entry *proj_class_entry_ptr;
 
186
 
 
187
#define PHPMS_GLOBAL(a) a
 
188
static int le_projobj;
 
189
 
 
190
function_entry php_proj_functions[] = {
 
191
    {"pj_fwd",  php_proj_pj_fwd,   NULL},
 
192
    {"pj_inv",  php_proj_pj_inv,   NULL},
 
193
    {"pj_init",  php_proj_pj_init,   NULL},
 
194
    {"pj_transform",  php_proj_pj_transform,   NULL},
 
195
    {"pj_datum_transform",  php_proj_pj_datum_transform,   NULL},
 
196
    {"pj_free",  php_proj_pj_free,   NULL},
 
197
    {NULL, NULL, NULL}
 
198
};
 
199
 
 
200
 
 
201
php3_module_entry php_proj_module_entry = {
 
202
#if ZEND_MODULE_API_NO >= 20010901
 
203
    STANDARD_MODULE_HEADER,
 
204
#endif
 
205
    "PHPPROJ", php_proj_functions, php_init_proj, php_end_proj,
 
206
    NULL, NULL,
 
207
#ifdef ZEND_VERSION
 
208
    PHP_MINFO(phpproj),
 
209
#else
 
210
    php_info_proj,
 
211
#endif
 
212
#if ZEND_MODULE_API_NO >= 20010901
 
213
    "phpproj, php4.1version",          /* extension version number (string) */
 
214
#endif
 
215
    STANDARD_MODULE_PROPERTIES
 
216
};
 
217
 
 
218
 
 
219
#if COMPILE_DL
 
220
DLEXPORT php3_module_entry *get_module(void)
 
221
{
 
222
    return &php_proj_module_entry;
 
223
}
 
224
#endif
 
225
 
 
226
 
 
227
function_entry php_proj_class_functions[] = {
 
228
    {"ttt",             ttt,        NULL},
 
229
    {NULL, NULL, NULL}
 
230
};
 
231
 
 
232
DLEXPORT void ttt(INTERNAL_FUNCTION_PARAMETERS)
 
233
{
 
234
}
 
235
 
 
236
#ifdef ZEND_VERSION
 
237
PHP_MINFO_FUNCTION(phpproj)
 
238
#else
 
239
DLEXPORT void php_info_proj(void)
 
240
#endif
 
241
{
 
242
    php3_printf(" Version %s<br>\n", PHP_PROJ_VERSION);
 
243
 
 
244
    php3_printf("<BR>\n");
 
245
}
 
246
 
 
247
DLEXPORT int php_init_proj(INIT_FUNC_ARGS)
 
248
{
 
249
    zend_class_entry tmp_class_entry;
 
250
 
 
251
    PHPMS_GLOBAL(le_projobj)  =
 
252
        register_list_destructors(php_proj_pj_free,
 
253
                                  NULL);
 
254
 
 
255
    INIT_CLASS_ENTRY(tmp_class_entry, "proj", php_proj_class_functions);
 
256
    proj_class_entry_ptr = zend_register_internal_class(&tmp_class_entry TSRMLS_CC);
 
257
 
 
258
    return SUCCESS;
 
259
}
 
260
 
 
261
DLEXPORT int php_end_proj(SHUTDOWN_FUNC_ARGS)
 
262
{
 
263
    return SUCCESS;
 
264
}
 
265
 
 
266
 
 
267
#if !defined  DEG_TO_RAD
 
268
#define DEG_TO_RAD      0.0174532925199432958
 
269
#endif
 
270
 
 
271
#if !defined RAD_TO_DEG
 
272
#define RAD_TO_DEG      57.29577951308232
 
273
#endif
 
274
 
 
275
/**********************************************************************
 
276
 *                       _php_proj_build_proj_object
 
277
 **********************************************************************/
 
278
static long _php_proj_build_proj_object(PJ *pj,
 
279
                                        HashTable *list, pval *return_value TSRMLS_DC)
 
280
{
 
281
    int pj_id;
 
282
 
 
283
    if (pj == NULL)
 
284
        return 0;
 
285
 
 
286
    pj_id = php3_list_insert(pj, PHPMS_GLOBAL(le_projobj));
 
287
 
 
288
    _phpms_object_init(return_value, pj_id, php_proj_class_functions,
 
289
                       PHP4_CLASS_ENTRY(proj_class_entry_ptr) TSRMLS_CC);
 
290
 
 
291
    return pj_id;
 
292
}
 
293
 
 
294
 
 
295
/************************************************************************/
 
296
/*       DLEXPORT void php_proj_pj_init(INTERNAL_FUNCTION_PARAMETERS)   */
 
297
/*                                                                      */
 
298
/*      Creates and initialize a  PJ structure that can be used with    */
 
299
/*      proj_fwd and proj_inv function.                                 */
 
300
/*                                                                      */
 
301
/*       Parameter :                                                    */
 
302
/*                                                                      */
 
303
/*          array : array of parameters                                 */
 
304
/*                                                                      */
 
305
/*       Ex :                                                           */
 
306
/*                                                                      */
 
307
/*              $projarray[0] = "proj=lcc";                             */
 
308
/*              $projarray[1] = "ellps=GRS80";                          */
 
309
/*              $projarray[2] = "lat_0=49";                             */
 
310
/*              $projarray[3] = "lon_0=-95";                            */
 
311
/*              $projarray[4] = "lat_1=49";                             */
 
312
/*              $projarray[5] = "lat_2=77";                             */
 
313
/*                                                                      */
 
314
/*              $pj = pj_init($projarray);                              */
 
315
/*                                                                      */
 
316
/************************************************************************/
 
317
DLEXPORT void php_proj_pj_init(INTERNAL_FUNCTION_PARAMETERS)
 
318
{
 
319
    pval        *pArrayOfParams = NULL;
 
320
 
 
321
    pval        **pParam = NULL;
 
322
    HashTable   *list=NULL;
 
323
 
 
324
    int         nParamCount = 0;
 
325
    int         i = 0;
 
326
    PJ          *pj = NULL;
 
327
 
 
328
    char        **papszBuf = NULL;
 
329
 
 
330
//    char        *strttt = NULL;
 
331
//    int         ttt;
 
332
 
 
333
    //ttt = strlen(strttt);
 
334
/* -------------------------------------------------------------------- */
 
335
/*      extract parameters.                                             */
 
336
/* -------------------------------------------------------------------- */
 
337
    if (getParameters(ht, 1, &pArrayOfParams) != SUCCESS)
 
338
    {
 
339
        WRONG_PARAM_COUNT;
 
340
    }
 
341
 
 
342
    if (pArrayOfParams->type == IS_ARRAY)
 
343
        nParamCount = _php3_hash_num_elements(pArrayOfParams->value.ht);
 
344
    else
 
345
      nParamCount = 0;
 
346
 
 
347
    if (nParamCount <= 0)
 
348
      RETURN_LONG(-1);
 
349
 
 
350
    papszBuf = (char **) malloc((nParamCount+2)*sizeof(char *));
 
351
 
 
352
    for (i = 0; i < nParamCount; i++)
 
353
    {
 
354
        if (_php3_hash_index_find(pArrayOfParams->value.ht, i,
 
355
                                  (void **)&pParam) != FAILURE)
 
356
        {
 
357
            convert_to_string((*pParam));
 
358
            if ((*pParam)->value.str.val != NULL)
 
359
              papszBuf[i] = strdup((*pParam)->value.str.val);
 
360
        }
 
361
    }
 
362
     papszBuf[i] = NULL;
 
363
 
 
364
    pj = pj_init(nParamCount, papszBuf);
 
365
 
 
366
    _php_proj_build_proj_object(pj, list, return_value TSRMLS_CC);
 
367
}
 
368
 
 
369
 
 
370
/************************************************************************/
 
371
/*       DLEXPORT void php_proj_pj_fwd(INTERNAL_FUNCTION_PARAMETERS)    */
 
372
/*                                                                      */
 
373
/*       Performs a projection from lat/long coordinates to             */
 
374
/*      cartesian coordinates (projection defines in the pj parameter)  */
 
375
/*      Parameters :                                                    */
 
376
/*                                                                      */
 
377
/*         - double p1 : latitude (in decimal degree )                  */
 
378
/*         - double p2 : longitude (in decimal degree )                 */
 
379
/*         - PJ pj : valid projection structure (see pj_init)           */
 
380
/*                                                                      */
 
381
/*       Ex :                                                           */
 
382
/*              $lat = 45.25;                                           */
 
383
/*              $lon = -75.42;                                          */
 
384
/*                                                                      */
 
385
/*              $ret = pj_fwd($lat, $lon, $pj);                         */
 
386
/*              printf("geo x = %f<br>\n", $ret["u"]);                  */
 
387
/*              printf("geo y = %f<br>\n",$ret["v"]);                   */
 
388
/*                                                                      */
 
389
/************************************************************************/
 
390
DLEXPORT void php_proj_pj_fwd(INTERNAL_FUNCTION_PARAMETERS)
 
391
{
 
392
    HashTable   *list=NULL;
 
393
    pval        *p1, *p2;
 
394
    pval        *pj = NULL;
 
395
    PJ          *popj = NULL;
 
396
    projUV      pnt;
 
397
    projUV      pntReturn = {0,0};
 
398
 
 
399
/* -------------------------------------------------------------------- */
 
400
/*      extract parameters.                                             */
 
401
/* -------------------------------------------------------------------- */
 
402
    if (getParameters(ht, 3, &p1, &p2, &pj) != SUCCESS)
 
403
    {
 
404
        WRONG_PARAM_COUNT;
 
405
    }
 
406
 
 
407
/* -------------------------------------------------------------------- */
 
408
/*      initilize return array.                                         */
 
409
/* -------------------------------------------------------------------- */
 
410
    if (array_init(return_value) == FAILURE)
 
411
    {
 
412
        RETURN_FALSE;
 
413
    }
 
414
 
 
415
    convert_to_double(p1);
 
416
    convert_to_double(p2);
 
417
 
 
418
    popj = (PJ *)_phpms_fetch_handle(pj,
 
419
                                     PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
420
 
 
421
    if (popj)
 
422
    {
 
423
        pnt.u = p2->value.dval * DEG_TO_RAD;
 
424
        pnt.v = p1->value.dval * DEG_TO_RAD;
 
425
 
 
426
        pntReturn = pj_fwd(pnt, popj);
 
427
    }
 
428
 
 
429
    add_assoc_double(return_value, "u", pntReturn.u);
 
430
    add_assoc_double(return_value, "v", pntReturn.v);
 
431
}
 
432
 
 
433
 
 
434
/************************************************************************/
 
435
/*       DLEXPORT void php_proj_pj_inv(INTERNAL_FUNCTION_PARAMETERS)    */
 
436
/*                                                                      */
 
437
/*       Performs a projection from cartesian  coordinates              */
 
438
/*      (projection defines in the pj parameter) to lat/long            */
 
439
/*      coordinates.                                                    */
 
440
/*                                                                      */
 
441
/*       Return vales are in decimal degrees.                           */
 
442
/*                                                                      */
 
443
/*       Parameters :                                                   */
 
444
/*                                                                      */
 
445
/*               - double p1 : projected coordinates (x)                */
 
446
/*               - double p2 : projected coordinates (y)                */
 
447
/*               - PJ pj : valid projection structure (see pj_init)     */
 
448
/*                                                                      */
 
449
/*         Ex :                                                         */
 
450
/*              $ingeox = 1537490.335842;                               */
 
451
/*              $ingeoy = -181633.471555;                               */
 
452
/*                                                                      */
 
453
/*              $ret = pj_inv($ingeox, $ingeoy, $pj);                   */
 
454
/*                                                                      */
 
455
/*              printf("latitude = %f<br>\n", $ret["u"]);               */
 
456
/*              printf("longitude = %f<br>\n",$ret["v"]);               */
 
457
/************************************************************************/
 
458
DLEXPORT void php_proj_pj_inv(INTERNAL_FUNCTION_PARAMETERS)
 
459
{
 
460
    HashTable   *list=NULL;
 
461
    pval        *p1, *p2;
 
462
    pval        *pj = NULL;
 
463
    PJ          *popj = NULL;
 
464
    projUV      pnt;
 
465
    projUV      pntReturn = {0,0};
 
466
/* -------------------------------------------------------------------- */
 
467
/*      extract parameters.                                             */
 
468
/* -------------------------------------------------------------------- */
 
469
    if (getParameters(ht, 3, &p1, &p2, &pj) != SUCCESS)
 
470
    {
 
471
        WRONG_PARAM_COUNT;
 
472
    }
 
473
 
 
474
/* -------------------------------------------------------------------- */
 
475
/*      initilize return array.                                         */
 
476
/* -------------------------------------------------------------------- */
 
477
    if (array_init(return_value) == FAILURE)
 
478
    {
 
479
        RETURN_FALSE;
 
480
    }
 
481
 
 
482
    convert_to_double(p1);
 
483
    convert_to_double(p2);
 
484
 
 
485
    popj = (PJ *)_phpms_fetch_handle(pj,
 
486
                                     PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
487
 
 
488
    if (popj)
 
489
    {
 
490
        pnt.u = p1->value.dval;
 
491
        pnt.v = p2->value.dval;
 
492
 
 
493
        pntReturn = pj_inv(pnt, popj);
 
494
        pntReturn.u *= RAD_TO_DEG;
 
495
        pntReturn.v *= RAD_TO_DEG;
 
496
    }
 
497
 
 
498
    add_assoc_double(return_value, "u", pntReturn.v);
 
499
    add_assoc_double(return_value, "v", pntReturn.u);
 
500
}
 
501
 
 
502
/************************************************************************/
 
503
/*    DLEXPORT void php_proj_pj_transform(INTERNAL_FUNCTION_PARAMETERS) */
 
504
/*                                                                      */
 
505
/*       Transform coordinates from source projection to destination    */
 
506
/*      projection.                                                     */
 
507
/*                                                                      */
 
508
/*       Parameters :                                                   */
 
509
/*                                                                      */
 
510
/*         - PJ *srcdefn,                                               */
 
511
/*         - PJ *dstdefn,                                               */
 
512
/*         - double x                                                   */
 
513
/*         - double y                                                   */
 
514
/*                                                                      */
 
515
/************************************************************************/
 
516
DLEXPORT void php_proj_pj_transform(INTERNAL_FUNCTION_PARAMETERS)
 
517
{
 
518
    HashTable   *list=NULL;
 
519
    pval        *p1, *p2;
 
520
    pval        *pjin, *pjout = NULL;
 
521
    PJ          *in = NULL;
 
522
    PJ          *out = NULL;
 
523
    projUV      pnt = {0, 0};
 
524
    double      z = 0;
 
525
    int         error = -1;
 
526
/* -------------------------------------------------------------------- */
 
527
/*      extract parameters.                                             */
 
528
/* -------------------------------------------------------------------- */
 
529
    if (getParameters(ht, 4, &pjin , &pjout, &p1, &p2) != SUCCESS)
 
530
    {
 
531
        WRONG_PARAM_COUNT;
 
532
    }
 
533
 
 
534
/* -------------------------------------------------------------------- */
 
535
/*      initilize return array.                                         */
 
536
/* -------------------------------------------------------------------- */
 
537
    if (array_init(return_value) == FAILURE)
 
538
    {
 
539
        RETURN_FALSE;
 
540
    }
 
541
 
 
542
    convert_to_double(p1);
 
543
    convert_to_double(p2);
 
544
 
 
545
    in = (PJ *)_phpms_fetch_handle(pjin,
 
546
                                   PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
547
 
 
548
    out = (PJ *)_phpms_fetch_handle(pjout,
 
549
                                    PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
550
 
 
551
    if (in && out)
 
552
    {
 
553
        pnt.u = p1->value.dval;
 
554
        pnt.v = p2->value.dval;
 
555
 
 
556
        if( pj_is_latlong(in) )
 
557
        {
 
558
            pnt.u *= DEG_TO_RAD;
 
559
            pnt.v *= DEG_TO_RAD;
 
560
        }
 
561
 
 
562
        error = pj_transform(in, out, 1, 0,
 
563
                             &(pnt.u), &(pnt.v), &z );
 
564
 
 
565
        if( pj_is_latlong(out) )
 
566
        {
 
567
            pnt.u *= RAD_TO_DEG;
 
568
            pnt.v *= RAD_TO_DEG;
 
569
        }
 
570
    }
 
571
 
 
572
    if (error)
 
573
    {
 
574
        php_error(E_ERROR,"Error in pj_transform");
 
575
 
 
576
        RETURN_LONG(-1);
 
577
    }
 
578
    else
 
579
    {
 
580
        add_assoc_double(return_value, "u", pnt.u);
 
581
        add_assoc_double(return_value, "v", pnt.v);
 
582
    }
 
583
}
 
584
 
 
585
 
 
586
 
 
587
/************************************************************************/
 
588
/*                                 DLEXPORT                             */
 
589
/*      void php_proj_pj_datum_transform(INTERNAL_FUNCTION_PARAMETERS)  */
 
590
/*                                                                      */
 
591
/*         Datum from source projection to destination                  */
 
592
/*        projection.                                                   */
 
593
/*                                                                      */
 
594
/*         Parameters :                                                 */
 
595
/*                                                                      */
 
596
/*           - PJ *srcdefn,                                             */
 
597
/*           - PJ *dstdefn,                                             */
 
598
/*           - double x                                                 */
 
599
/*           - double y                                                 */
 
600
/*                                                                      */
 
601
/************************************************************************/
 
602
DLEXPORT void php_proj_pj_datum_transform(INTERNAL_FUNCTION_PARAMETERS)
 
603
{
 
604
    HashTable   *list=NULL;
 
605
    pval        *p1, *p2;
 
606
    pval        *pjin, *pjout = NULL;
 
607
    PJ          *in = NULL;
 
608
    PJ          *out = NULL;
 
609
    projUV      pnt = {0, 0};
 
610
    double      z = 0;
 
611
    int         error = -1;
 
612
/* -------------------------------------------------------------------- */
 
613
/*      extract parameters.                                             */
 
614
/* -------------------------------------------------------------------- */
 
615
    if (getParameters(ht, 4, &pjin , &pjout, &p1, &p2) != SUCCESS)
 
616
    {
 
617
        WRONG_PARAM_COUNT;
 
618
    }
 
619
 
 
620
/* -------------------------------------------------------------------- */
 
621
/*      initilize return array.                                         */
 
622
/* -------------------------------------------------------------------- */
 
623
    if (array_init(return_value) == FAILURE)
 
624
    {
 
625
        RETURN_FALSE;
 
626
    }
 
627
 
 
628
    convert_to_double(p1);
 
629
    convert_to_double(p2);
 
630
 
 
631
    in = (PJ *)_phpms_fetch_handle(pjin,
 
632
                                   PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
633
 
 
634
    out = (PJ *)_phpms_fetch_handle(pjout,
 
635
                                    PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
636
 
 
637
    if (in && out)
 
638
    {
 
639
        pnt.u = p1->value.dval;
 
640
        pnt.v = p2->value.dval;
 
641
 
 
642
        if( pj_is_latlong(in) )
 
643
        {
 
644
            pnt.u *= DEG_TO_RAD;
 
645
            pnt.v *= DEG_TO_RAD;
 
646
        }
 
647
 
 
648
        error = pj_transform(in, out, 1, 0,
 
649
                             &(pnt.u), &(pnt.v), &z );
 
650
 
 
651
        if (!error)
 
652
        {
 
653
            if( pj_is_latlong(out) )
 
654
            {
 
655
                pnt.u *= RAD_TO_DEG;
 
656
                pnt.v *= RAD_TO_DEG;
 
657
            }
 
658
        }
 
659
    }
 
660
 
 
661
    if (error)
 
662
    {
 
663
        php_error(E_ERROR,"Error in pj_datum_transform");
 
664
 
 
665
        RETURN_LONG(-1);
 
666
    }
 
667
    else
 
668
    {
 
669
        add_assoc_double(return_value, "u", pnt.u);
 
670
        add_assoc_double(return_value, "v", pnt.v);
 
671
    }
 
672
}
 
673
 
 
674
/************************************************************************/
 
675
/*       DLEXPORT void php_proj_pj_free(INTERNAL_FUNCTION_PARAMETERS)   */
 
676
/************************************************************************/
 
677
DLEXPORT void php_proj_pj_free(INTERNAL_FUNCTION_PARAMETERS)
 
678
{
 
679
 
 
680
/* ==================================================================== */
 
681
/*      TODO : freeing does not work properly on PHP4.                  */
 
682
/* ==================================================================== */
 
683
#ifdef PHP4_BAD_FREEING
 
684
 
 
685
    HashTable   *list=NULL;
 
686
    pval        *pj = NULL;
 
687
    PJ          *popj = NULL;
 
688
/* -------------------------------------------------------------------- */
 
689
/*      extract parameters.                                             */
 
690
/* -------------------------------------------------------------------- */
 
691
    if (getParameters(ht, 1, &pj) != SUCCESS)
 
692
    {
 
693
        WRONG_PARAM_COUNT;
 
694
    }
 
695
 
 
696
    popj = (PJ *)_phpms_fetch_handle(pj,
 
697
                                     PHPMS_GLOBAL(le_projobj), list TSRMLS_CC);
 
698
 
 
699
    if (popj)
 
700
    {
 
701
        pj_free(popj);
 
702
    }
 
703
#endif
 
704
}
 
705
 
 
706
#endif /* USE_PROJ */
 
707
 
 
708
 
 
709