| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: Hierarchical Data Format Release 4 (HDF4) |
| 4 | * Purpose: This is the wrapper code to use OGR Coordinate Transformation |
| 5 | * services instead of GCTP library |
| 6 | * Author: Andrey Kiselev, [email protected] |
| 7 | * |
| 8 | ****************************************************************************** |
| 9 | * Copyright (c) 2004, Andrey Kiselev <[email protected]> |
| 10 | * |
| 11 | * SPDX-License-Identifier: MIT |
| 12 | ****************************************************************************/ |
| 13 | |
| 14 | #include "ogr_srs_api.h"cxx . . $ `<file>/ogr/ogr_srs_api.h`/ |
| 15 | #include <stdlib.h> |
| 16 | |
| 17 | #include "mfhdf.h" |
| 18 | |
| 19 | #include <math.h> |
| 20 | |
| 21 | #ifndef PI |
| 22 | #ifndef M_PIcxx . . $ `<external>/11263917310783833665/math.h:1289:10`! |
| 23 | #define PI (3.141592653589793238) |
| 24 | #else |
| 25 | #define PIcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:25:9`! (M_PIcxx . . $ `<external>/11263917310783833665/math.h:1289:10`!) |
| 26 | #endif |
| 27 | #endif |
| 28 | |
| 29 | #define DEGcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:29:9`! (180.0 / PIcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:25:9`!) |
| 30 | #define RADcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:30:9`! (PIcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:25:9`! / 180.0) |
| 31 | |
| 32 | void for_initcxx . . $ for_init(eab1b9a0b405fd2d).( |
| 33 | int32cxx . . $ int32# outsys, /* output system code */ |
| 34 | int32cxx . . $ int32# outzone, /* output zone number */ |
| 35 | float64cxx . . $ float64# *outparm, /* output array of projection parameters */ |
| 36 | int32cxx . . $ int32# outdatum, /* output datum */ |
| 37 | char *fn27, /* NAD 1927 parameter file */ |
| 38 | char *fn83, /* NAD 1983 parameter file */ |
| 39 | int32cxx . . $ int32# *iflg, /* status flag */ |
| 40 | int32cxx . . $ int32# (*for_trans[])(double, double, double *, double *)); |
| 41 | |
| 42 | void inv_initcxx . . $ inv_init(eab1b9a0b405fd2d).( |
| 43 | int32cxx . . $ int32# insys, /* input system code */ |
| 44 | int32cxx . . $ int32# inzone, /* input zone number */ |
| 45 | float64cxx . . $ float64# *inparm, /* input array of projection parameters */ |
| 46 | int32cxx . . $ int32# indatum, /* input datum code */ |
| 47 | char *fn27, /* NAD 1927 parameter file */ |
| 48 | char *fn83, /* NAD 1983 parameter file */ |
| 49 | int32cxx . . $ int32# *iflg, /* status flag */ |
| 50 | int32cxx . . $ int32# (*inv_trans[])(double, double, double*, double*)); |
| 51 | |
| 52 | /***** static vars to store the transformers in *****/ |
| 53 | /***** this is not thread safe *****/ |
| 54 | |
| 55 | static OGRCoordinateTransformationHcxx . . $ OGRCoordinateTransformationH# hForCTcxx . . $ hForCT., hInvCTcxx . . $ hInvCT.; |
| 56 | |
| 57 | /****************************************************************************** |
| 58 | function for forward gctp transformation |
| 59 | |
| 60 | gctp expects Longitude and Latitude values to be in radians |
| 61 | ******************************************************************************/ |
| 62 | |
| 63 | static int32cxx . . $ int32# osr_forcxx . . $ osr_for(7e13fe78331b9d07).( |
| 64 | double lon, /* (I) Longitude */ |
| 65 | double lat, /* (I) Latitude */ |
| 66 | double *x, /* (O) X projection coordinate */ |
| 67 | double *y) /* (O) Y projection coordinate */ |
| 68 | { |
| 69 | |
| 70 | double dfX, dfY, dfZ = 0.0; |
| 71 | |
| 72 | dfX = lon * DEGcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:29:9`!; |
| 73 | dfY = lat * DEGcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:29:9`!; |
| 74 | |
| 75 | OCTTransformcxx . . $ OCTTransform(3a52f68619c6ba14).( hForCTcxx . . $ hForCT., 1, &dfX, &dfY, &dfZ); |
| 76 | |
| 77 | *x = dfX; |
| 78 | *y = dfY; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | /****************************************************************************** |
| 84 | function to init a forward gctp transformer |
| 85 | ******************************************************************************/ |
| 86 | |
| 87 | void for_initcxx . . $ for_init(eab1b9a0b405fd2d).( |
| 88 | int32cxx . . $ int32# outsys, /* output system code */ |
| 89 | int32cxx . . $ int32# outzone, /* output zone number */ |
| 90 | float64cxx . . $ float64# *outparm, /* output array of projection parameters */ |
| 91 | int32cxx . . $ int32# outdatum, /* output datum */ |
| 92 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! char *fn27, /* NAD 1927 parameter file */ |
| 93 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! char *fn83, /* NAD 1983 parameter file */ |
| 94 | int32cxx . . $ int32# *iflg, /* status flag */ |
| 95 | int32cxx . . $ int32# (*for_trans[])(double, double, double *, double *)) |
| 96 | /* forward function pointer */ |
| 97 | { |
| 98 | OGRSpatialReferenceHcxx . . $ OGRSpatialReferenceH# hOutSourceSRS, hLatLong = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 99 | |
| 100 | *iflg = 0; |
| 101 | |
| 102 | hOutSourceSRS = OSRNewSpatialReferencecxx . . $ OSRNewSpatialReference(42228c1987407501).( NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! ); |
| 103 | OSRSetAxisMappingStrategycxx . . $ OSRSetAxisMappingStrategy(fb96ebcac7ade334).(hOutSourceSRS, OAMS_TRADITIONAL_GIS_ORDERcxx . . $ OAMS_TRADITIONAL_GIS_ORDER.); |
| 104 | |
| 105 | OSRImportFromUSGScxx . . $ OSRImportFromUSGS(e4e67612ecf5be04).( hOutSourceSRS, outsys, outzone, outparm, outdatum ); |
| 106 | hLatLong = OSRNewSpatialReferencecxx . . $ OSRNewSpatialReference(42228c1987407501). ( SRS_WKT_WGS84_LAT_LONGcxx . . $ `ogr/ogr_srs_api.h:63:9`! ); |
| 107 | OSRSetAxisMappingStrategycxx . . $ OSRSetAxisMappingStrategy(fb96ebcac7ade334).(hLatLong, OAMS_TRADITIONAL_GIS_ORDERcxx . . $ OAMS_TRADITIONAL_GIS_ORDER.); |
| 108 | |
| 109 | hForCTcxx . . $ hForCT. = OCTNewCoordinateTransformationcxx . . $ OCTNewCoordinateTransformation(1328c93ee22f3bc1).( hLatLong, hOutSourceSRS ); |
| 110 | |
| 111 | OSRDestroySpatialReferencecxx . . $ OSRDestroySpatialReference(5d22bdacc48458e8).( hOutSourceSRS ); |
| 112 | OSRDestroySpatialReferencecxx . . $ OSRDestroySpatialReference(5d22bdacc48458e8).( hLatLong ); |
| 113 | |
| 114 | for_trans[outsys] = osr_forcxx . . $ osr_for(7e13fe78331b9d07).; |
| 115 | } |
| 116 | |
| 117 | /****************************************************************************** |
| 118 | function for inverse gctp transformation |
| 119 | |
| 120 | gctp returns Longitude and Latitude values in radians |
| 121 | ******************************************************************************/ |
| 122 | |
| 123 | static int32cxx . . $ int32# osr_invcxx . . $ osr_inv(7e13fe78331b9d07).( |
| 124 | double x, /* (I) X projection coordinate */ |
| 125 | double y, /* (I) Y projection coordinate */ |
| 126 | double *lon, /* (O) Longitude */ |
| 127 | double *lat) /* (O) Latitude */ |
| 128 | { |
| 129 | |
| 130 | double dfX, dfY, dfZ = 0.0; |
| 131 | |
| 132 | dfX = x; |
| 133 | dfY = y; |
| 134 | |
| 135 | OCTTransformcxx . . $ OCTTransform(3a52f68619c6ba14).( hInvCTcxx . . $ hInvCT., 1, &dfX, &dfY, &dfZ ); |
| 136 | |
| 137 | *lon = dfX * RADcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:30:9`!; |
| 138 | *lat = dfY * RADcxx . . $ `frmts/hdf4/hdf-eos/gctp_wrap.c:30:9`!; |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /****************************************************************************** |
| 144 | function to init a inverse gctp transformer |
| 145 | ******************************************************************************/ |
| 146 | |
| 147 | void inv_initcxx . . $ inv_init(eab1b9a0b405fd2d).( |
| 148 | int32cxx . . $ int32# insys, /* input system code */ |
| 149 | int32cxx . . $ int32# inzone, /* input zone number */ |
| 150 | float64cxx . . $ float64# *inparm, /* input array of projection parameters */ |
| 151 | int32cxx . . $ int32# indatum, /* input datum code */ |
| 152 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! char *fn27, /* NAD 1927 parameter file */ |
| 153 | CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! char *fn83, /* NAD 1983 parameter file */ |
| 154 | int32cxx . . $ int32# *iflg, /* status flag */ |
| 155 | int32cxx . . $ int32# (*inv_trans[])(double, double, double*, double*)) |
| 156 | /* inverse function pointer */ |
| 157 | { |
| 158 | |
| 159 | OGRSpatialReferenceHcxx . . $ OGRSpatialReferenceH# hInSourceSRS, hLatLong = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 160 | *iflg = 0; |
| 161 | |
| 162 | hInSourceSRS = OSRNewSpatialReferencecxx . . $ OSRNewSpatialReference(42228c1987407501).( NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! ); |
| 163 | OSRSetAxisMappingStrategycxx . . $ OSRSetAxisMappingStrategy(fb96ebcac7ade334).(hInSourceSRS, OAMS_TRADITIONAL_GIS_ORDERcxx . . $ OAMS_TRADITIONAL_GIS_ORDER.); |
| 164 | OSRImportFromUSGScxx . . $ OSRImportFromUSGS(e4e67612ecf5be04).( hInSourceSRS, insys, inzone, inparm, indatum ); |
| 165 | |
| 166 | hLatLong = OSRNewSpatialReferencecxx . . $ OSRNewSpatialReference(42228c1987407501). ( SRS_WKT_WGS84_LAT_LONGcxx . . $ `ogr/ogr_srs_api.h:63:9`! ); |
| 167 | OSRSetAxisMappingStrategycxx . . $ OSRSetAxisMappingStrategy(fb96ebcac7ade334).(hLatLong, OAMS_TRADITIONAL_GIS_ORDERcxx . . $ OAMS_TRADITIONAL_GIS_ORDER.); |
| 168 | |
| 169 | hInvCTcxx . . $ hInvCT. = OCTNewCoordinateTransformationcxx . . $ OCTNewCoordinateTransformation(1328c93ee22f3bc1).( hInSourceSRS, hLatLong ); |
| 170 | |
| 171 | OSRDestroySpatialReferencecxx . . $ OSRDestroySpatialReference(5d22bdacc48458e8).( hInSourceSRS ); |
| 172 | OSRDestroySpatialReferencecxx . . $ OSRDestroySpatialReference(5d22bdacc48458e8).( hLatLong ); |
| 173 | |
| 174 | inv_trans[insys] = osr_invcxx . . $ osr_inv(7e13fe78331b9d07).; |
| 175 | } |
| 176 | |
| 177 | /****************************************************************************** |
| 178 | function to cleanup the transformers |
| 179 | |
| 180 | note: gctp does not have a function that does this |
| 181 | ******************************************************************************/ |
| 182 | #ifndef GDAL_COMPILATIONcxx . . $ `<built-in>:412:9`! |
| 183 | void gctp_destroy(void) { |
| 184 | OCTDestroyCoordinateTransformation ( hForCT ); |
| 185 | OCTDestroyCoordinateTransformation ( hInvCT ); |
| 186 | } |
| 187 | #endif |