MISR Toolkit  1.5.1
MtkGenericMapInfo.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkGenericMapInfo =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2008, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrMapQuery.h"
18 #include "MisrUtil.h"
19 #include <stdlib.h>
20 #include <math.h>
21 
59  double Min_x,
60  double Min_y,
61  double Resolution_x,
62  double Resolution_y,
63  int Number_pixel_x,
64  int Number_pixel_y,
65  MTKt_OriginCode Origin_code,
66  MTKt_PixRegCode Pix_reg_code,
67  MTKt_GenericMapInfo *Map_info
68 )
69 {
70  MTKt_status status_code; /* Return status of this function */
72  /* Map information */
73 
74  /* ------------------------------------------------------------------ */
75  /* Argument check: Resolution_x <= 0.0 */
76  /* Resolution_y <= 0.0 */
77  /* ------------------------------------------------------------------ */
78 
79  if (Resolution_x <= 0.0) {
80  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Resolution_x <= 0.0");
81  }
82  if (Resolution_y <= 0.0) {
83  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Resolution_y <= 0.0");
84  }
85 
86  /* ------------------------------------------------------------------ */
87  /* Argument check: Number_pixel_x < 1 */
88  /* Number_pixel_y < 1 */
89  /* ------------------------------------------------------------------ */
90 
91  if (Number_pixel_x < 1) {
92  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Number_pixel_x < 1");
93  }
94  if (Number_pixel_y < 1) {
95  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Number_pixel_y < 1");
96  }
97 
98  /* ------------------------------------------------------------------ */
99  /* Argument check: Map_info == NULL */
100  /* ------------------------------------------------------------------ */
101 
102  if (Map_info == NULL) {
103  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Map_info == NULL");
104  }
105 
106  /* ------------------------------------------------------------------ */
107  /* Initialize map information. */
108  /* ------------------------------------------------------------------ */
109 
110  map_info_tmp.min_x = Min_x;
111  map_info_tmp.min_y = Min_y;
112  map_info_tmp.max_x = Min_x + Number_pixel_x * Resolution_x;
113  map_info_tmp.max_y = Min_y + Number_pixel_y * Resolution_y;
114  map_info_tmp.resolution_x = Resolution_x;
115  map_info_tmp.resolution_y = Resolution_y;
116  map_info_tmp.pix_reg_code = Pix_reg_code;
117  map_info_tmp.origin_code = Origin_code;
118 
119  /* ------------------------------------------------------------------ */
120  /* Setup transform coefficients for converting between map */
121  /* coordinates and pixel coordinates. */
122  /* */
123  /* Argument_check: Unsupported Origin_code */
124  /* Argument_check: Unsupported Pix_reg_code */
125  /* ------------------------------------------------------------------ */
126 
127  switch(Origin_code) {
128  case MTKe_ORIGIN_UL:
129  map_info_tmp.size_line = Number_pixel_y;
130  map_info_tmp.size_sample = Number_pixel_x;
131  map_info_tmp.tsample[0] = 1;
132  map_info_tmp.tsample[1] = -map_info_tmp.min_x;
133  map_info_tmp.tline[0] = -1;
134  map_info_tmp.tline[1] = map_info_tmp.max_y;
135  map_info_tmp.tline[3] = map_info_tmp.resolution_y;
136  map_info_tmp.tsample[3] = map_info_tmp.resolution_x;
137  break;
138  case MTKe_ORIGIN_UR:
139  map_info_tmp.size_line = Number_pixel_x;
140  map_info_tmp.size_sample = Number_pixel_y;
141  map_info_tmp.tline[0] = -1;
142  map_info_tmp.tline[1] = map_info_tmp.max_x;
143  map_info_tmp.tsample[0] = -1;
144  map_info_tmp.tsample[1] = map_info_tmp.max_y;
145  map_info_tmp.tline[3] = map_info_tmp.resolution_x;
146  map_info_tmp.tsample[3] = map_info_tmp.resolution_y;
147  break;
148  case MTKe_ORIGIN_LL:
149  map_info_tmp.size_line = Number_pixel_x;
150  map_info_tmp.size_sample = Number_pixel_y;
151  map_info_tmp.tline[0] = 1;
152  map_info_tmp.tline[1] = -map_info_tmp.min_x;
153  map_info_tmp.tsample[0] = 1;
154  map_info_tmp.tsample[1] = -map_info_tmp.min_y;
155  map_info_tmp.tline[3] = map_info_tmp.resolution_x;
156  map_info_tmp.tsample[3] = map_info_tmp.resolution_y;
157  break;
158  case MTKe_ORIGIN_LR:
159  map_info_tmp.size_line = Number_pixel_y;
160  map_info_tmp.size_sample = Number_pixel_x;
161  map_info_tmp.tsample[0] = -1;
162  map_info_tmp.tsample[1] = map_info_tmp.max_x;
163  map_info_tmp.tline[0] = 1;
164  map_info_tmp.tline[1] = -map_info_tmp.min_y;
165  map_info_tmp.tline[3] = map_info_tmp.resolution_y;
166  map_info_tmp.tsample[3] = map_info_tmp.resolution_x;
167  break;
168  default:
169  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Unsupported Origin_code");
170  }
171 
172  switch(Pix_reg_code) {
173  case MTKe_PIX_REG_CORNER:
174  map_info_tmp.tline[2] = map_info_tmp.tsample[2] = 0.0;
175  break;
176  case MTKe_PIX_REG_CENTER:
177  map_info_tmp.tline[2] = map_info_tmp.tsample[2] = -0.5;
178  break;
179  default:
180  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Unsupported Pix_reg_code");
181  }
182 
183  /* ------------------------------------------------------------------ */
184  /* Return. */
185  /* ------------------------------------------------------------------ */
186 
187  *Map_info = map_info_tmp;
188  return MTK_SUCCESS;
189 
190 ERROR_HANDLE:
191  return status_code;
192 }
193 
194 
MTKt_PixRegCode pix_reg_code
Definition: MisrMapQuery.h:116
MTKt_OriginCode
Origin code.
Definition: MisrMapQuery.h:84
MTKt_OriginCode origin_code
Definition: MisrMapQuery.h:115
Generic map information.
Definition: MisrMapQuery.h:98
MTKt_status MtkGenericMapInfo(double Min_x, double Min_y, double Resolution_x, double Resolution_y, int Number_pixel_x, int Number_pixel_y, MTKt_OriginCode Origin_code, MTKt_PixRegCode Pix_reg_code, MTKt_GenericMapInfo *Map_info)
Initialize a MTKt_GenericMapInfo structure.
MTKt_PixRegCode
Pixel registration code.
Definition: MisrMapQuery.h:92
#define MTK_ERR_CODE_MSG_JUMP(code, msg)
Definition: MisrError.h:181
MTKt_status
Definition: MisrError.h:11
#define MTKT_GENERICMAPINFO_INIT
Definition: MisrMapQuery.h:120

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