MISR Toolkit  1.5.1
MtkLatLonToLSAry.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkLatLonToLSAry =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrMapQuery.h"
18 #include "MisrCoordQuery.h"
19 #include "MisrUnitConv.h"
20 #include "MisrError.h"
21 #include "proj.h"
22 #include "gctp_prototypes.h"
23 #include "math.h"
24 
44  MTKt_MapInfo mapinfo,
45  int nelement,
46  const double *lat_dd,
47  const double *lon_dd,
48  float *line,
49  float *sample )
50 {
51  MTKt_status status_code; /* Return status of this function */
52  MTKt_status status; /* Return status */
53  int i; /* Loop index */
54  MTKt_MisrProjParam pp; /* Projection parameters */
55  int iflg; /* GCTP status flag */
56  int (*for_trans[MAXPROJ+1])(double, double, double *, double *); /* Array of function ptrs (Not used) */
57  double deg2rad = acos(-1) / 180.0;
58 
59  if (lat_dd == NULL || lon_dd == NULL || line == NULL || sample == NULL)
61 
62  if (nelement < 0)
64 
65  status_code = MTK_SUCCESS;
66 
67  status = MtkPathToProjParam(mapinfo.path, 0, &pp);
68  MTK_ERR_COND_JUMP(status);
69 
71  NULL, NULL, &iflg, for_trans);
72  if (iflg)
74 
75  for (i = 0; i < nelement; i++) {
76  double som_x; /* SOM X */
77  double som_y; /* SOM Y */
78  float tline;
79  float tsample;
80 
81  iflg = somfor(lon_dd[i]*deg2rad, lat_dd[i]*deg2rad, &som_x, &som_y);
82  if (iflg)
84 
85  tline = (float)((som_x - mapinfo.som.ulc.x) / mapinfo.resolution);
86  tsample = (float)((som_y - mapinfo.som.ulc.y) / mapinfo.resolution);
87 
88  /* Check line/sample bounds */
89  if (tline < -0.5 || tline > mapinfo.nline - 0.5) {
90  tline = -1.0;
91  tsample = -1.0;
92  status_code = MTK_OUTBOUNDS;
93  }
94 
95  if (tsample < -0.5 || tsample > mapinfo.nsample - 0.5) {
96  tline = -1.0;
97  tsample = -1.0;
98  status_code = MTK_OUTBOUNDS;
99  }
100 
101  line[i] = tline;
102  sample[i] = tsample;
103  }
104 
105  return status_code;
106 
107 ERROR_HANDLE:
108  return status_code;
109 }
#define MAXPROJ
Definition: proj.h:84
MISR Projection Parameters.
double projparam[15]
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
Map Information.
Definition: MisrMapQuery.h:65
MTKt_status MtkLatLonToLSAry(MTKt_MapInfo mapinfo, int nelement, const double *lat_dd, const double *lon_dd, float *line, float *sample)
Convert array of decimal degrees latitude and longitude to array of line, sample. ...
MTKt_status MtkPathToProjParam(int path, int resolution_meters, MTKt_MisrProjParam *pp)
Get projection parameters.
int for_init(int outsys, int outzone, const double *outparm, int outdatum, char *fn27, char *fn83, int *iflg, int(*for_trans[])(double, double, double *, double *))
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
int somfor(double lon, double lat, double *y, double *x)
MTKt_SomRegion som
Definition: MisrMapQuery.h:74
MTKt_SomCoord ulc
Definition: MisrMapQuery.h:56

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51