MISR Toolkit  1.5.1
MtkChangeMapResolution.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkChangeMapResolution =
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 "MisrCoordQuery.h"
20 #include <stdlib.h>
21 #include <math.h>
22 
44  const MTKt_MapInfo *Map_info_in,
45  int New_resolution,
46  MTKt_MapInfo *Map_info_out
47 )
48 {
49  MTKt_status status; /* Return status of called routines. */
50  MTKt_status status_code; /* Return status of this function */
51  MTKt_MapInfo map_info_out_tmp = MTKT_MAPINFO_INIT;
52  /* Map information */
53  int size_x; /* Size of map in meters. */
54  int size_y; /* Size of map in meters. */
55  double center_offset; /* Offset to shift pixel center at corners. */
56 
57  /* ------------------------------------------------------------------ */
58  /* Argument check: Map_info_in = NULL */
59  /* Map_info_in->nline < 1 */
60  /* Map_info_in->nsample < 1 */
61  /* Map_info_in->resolution < 1 */
62  /* ------------------------------------------------------------------ */
63 
64  if (Map_info_in == NULL) {
65  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Map_info_in");
66  }
67  if (Map_info_in->nline < 1) {
68  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Map_info_in->nline < 1");
69  }
70  if (Map_info_in->nsample < 1) {
71  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Map_info_in->nsample < 1");
72  }
73  if (Map_info_in->resolution < 1) {
74  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"Map_info_in->resolution < 1");
75  }
76 
77  /* ------------------------------------------------------------------ */
78  /* Argument check: */
79  /* New_resolution < 1 */
80  /* New_resolution % MAXRESOLUTION != 0 */
81  /* ------------------------------------------------------------------ */
82 
83  if (New_resolution < 1) {
84  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"New_resolution < 1");
85  }
86  if (New_resolution % MAXRESOLUTION != 0) {
87  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"New_resolution % MAXRESOLUTION != 0");
88  }
89 
90  /* ------------------------------------------------------------------ */
91  /* Argument check: Map_info_out = NULL */
92  /* ------------------------------------------------------------------ */
93 
94  if (Map_info_out == NULL) {
95  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Map_info_out == NULL");
96  }
97 
98  /* ------------------------------------------------------------------ */
99  /* Initialize output map info to value of the input map info. */
100  /* ------------------------------------------------------------------ */
101 
102  map_info_out_tmp = *Map_info_in;
103 
104  /* ------------------------------------------------------------------ */
105  /* Calculate the size of the ouput map. */
106  /* */
107  /* Argument check: size_x % New_resolution != 0 */
108  /* size_y % New_resolution != 0 */
109  /* ------------------------------------------------------------------ */
110 
111  size_x = ( Map_info_in->nline * Map_info_in->resolution );
112  size_y = ( Map_info_in->nsample * Map_info_in->resolution );
113 
114  if (size_x % New_resolution != 0) {
115  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"size_x % New_resolution != 0");
116  }
117  if (size_y % New_resolution != 0) {
118  MTK_ERR_CODE_MSG_JUMP(MTK_OUTBOUNDS,"size_y % New_resolution != 0");
119  }
120 
121  map_info_out_tmp.nline = size_x / New_resolution;
122  map_info_out_tmp.nsample = size_y / New_resolution;
123 
124  /* ------------------------------------------------------------------ */
125  /* Calculate output map resolution factor. */
126  /* ------------------------------------------------------------------ */
127 
128  map_info_out_tmp.resfactor = New_resolution / MAXRESOLUTION;
129 
130  /* ------------------------------------------------------------------ */
131  /* Set output map resolution. */
132  /* ------------------------------------------------------------------ */
133 
134  map_info_out_tmp.resolution = New_resolution;
135 
136  /* ------------------------------------------------------------------ */
137  /* Recalculate pixel centers at map corners. */
138  /* ------------------------------------------------------------------ */
139 
140  center_offset = (Map_info_in->resolution - New_resolution) / (double)2.0;
141  map_info_out_tmp.som.ulc.x -= center_offset;
142  map_info_out_tmp.som.ulc.y -= center_offset;
143  map_info_out_tmp.som.lrc.x += center_offset;
144  map_info_out_tmp.som.lrc.y += center_offset;
145 
146  status = MtkSomXYToLatLon(map_info_out_tmp.path,
147  map_info_out_tmp.som.ulc.x,
148  map_info_out_tmp.som.ulc.y,
149  &map_info_out_tmp.geo.ulc.lat,
150  &map_info_out_tmp.geo.ulc.lon);
151  MTK_ERR_COND_JUMP(status);
152 
153  status = MtkSomXYToLatLon(map_info_out_tmp.path,
154  map_info_out_tmp.som.lrc.x,
155  map_info_out_tmp.som.lrc.y,
156  &map_info_out_tmp.geo.lrc.lat,
157  &map_info_out_tmp.geo.lrc.lon);
158  MTK_ERR_COND_JUMP(status);
159 
160  status = MtkSomXYToLatLon(map_info_out_tmp.path,
161  map_info_out_tmp.som.ulc.x,
162  map_info_out_tmp.som.lrc.y,
163  &map_info_out_tmp.geo.urc.lat,
164  &map_info_out_tmp.geo.urc.lon);
165  MTK_ERR_COND_JUMP(status);
166 
167  status = MtkSomXYToLatLon(map_info_out_tmp.path,
168  map_info_out_tmp.som.lrc.x,
169  map_info_out_tmp.som.ulc.y,
170  &map_info_out_tmp.geo.llc.lat,
171  &map_info_out_tmp.geo.llc.lon);
172  MTK_ERR_COND_JUMP(status);
173 
174  /* --------------------------------------------------------------------- */
175  /* Set the projection parameters in mapinfo for this path and resolution */
176  /* --------------------------------------------------------------------- */
177 
178  status = MtkPathToProjParam(map_info_out_tmp.path, New_resolution, &(map_info_out_tmp.pp));
179  MTK_ERR_COND_JUMP(status);
180 
181  /* ------------------------------------------------------------------ */
182  /* Return. */
183  /* ------------------------------------------------------------------ */
184 
185  *Map_info_out = map_info_out_tmp;
186  return MTK_SUCCESS;
187 
188 ERROR_HANDLE:
189  return status_code;
190 }
191 
192 
#define MTKT_MAPINFO_INIT
Definition: MisrMapQuery.h:79
MTKt_GeoCoord urc
Definition: MisrMapQuery.h:43
Map Information.
Definition: MisrMapQuery.h:65
MTKt_status MtkSomXYToLatLon(int path, double som_x, double som_y, double *lat_dd, double *lon_dd)
Convert SOM X, SOM Y to decimal degrees latitude and longitude.
MTKt_GeoCoord lrc
Definition: MisrMapQuery.h:45
MTKt_GeoCoord llc
Definition: MisrMapQuery.h:46
MTKt_GeoCoord ulc
Definition: MisrMapQuery.h:42
MTKt_MisrProjParam pp
Definition: MisrMapQuery.h:76
MTKt_status MtkPathToProjParam(int path, int resolution_meters, MTKt_MisrProjParam *pp)
Get projection parameters.
MTKt_GeoRegion geo
Definition: MisrMapQuery.h:75
#define MTK_ERR_CODE_MSG_JUMP(code, msg)
Definition: MisrError.h:181
#define MAXRESOLUTION
Definition: MisrProjParam.h:22
MTKt_SomCoord lrc
Definition: MisrMapQuery.h:58
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
MTKt_SomRegion som
Definition: MisrMapQuery.h:74
MTKt_SomCoord ulc
Definition: MisrMapQuery.h:56
MTKt_status MtkChangeMapResolution(const MTKt_MapInfo *Map_info_in, int New_resolution, MTKt_MapInfo *Map_info_out)
Change resolution of an MTKt_MapInfo structure.

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