MISR Toolkit  1.5.1
MtkSnapToGrid.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkSnapToGrid =
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 "MisrSetRegion.h"
18 #include "MisrCoordQuery.h"
19 #include "MisrMapQuery.h"
20 #include "MisrError.h"
21 #include <stdlib.h>
22 #include <math.h>
23 #include <float.h>
24 
41  int Path,
42  int Resolution,
43  MTKt_Region Region,
44  MTKt_MapInfo *Map_info )
45 {
46  MTKt_status status_code; /* Return status of this function */
47  MTKt_status status; /* Return status */
49  /* Map info structure */
50  MTKt_SomCoord som_min; /* Som coordinate */
51  MTKt_SomCoord som_max; /* Som coordinate */
52  MTKt_SomCoord corner; /* Som coordinate */
53  MTKt_SomCoord center; /* Som coordinate */
54 
55  /* ------------------------------------------------------------------ */
56  /* Argument check: mapinfo == NULL */
57  /* ------------------------------------------------------------------ */
58 
59  if (Map_info == NULL) {
61  }
62 
63  /* ----------------------- */
64  /* Set path and resolution */
65  /* ----------------------- */
66 
67  map.path = Path;
68  map.som.path = Path;
69  map.resolution = Resolution;
71  map.pixelcenter = MTK_TRUE;
72 
73  /* -------------------------------------------------------------- */
74  /* Snap center geo coordinate of region to som grid for this path */
75  /* -------------------------------------------------------------- */
76 
77  status = MtkLatLonToSomXY(Path, Region.geo.ctr.lat, Region.geo.ctr.lon,
78  &center.x, &center.y);
79  MTK_ERR_COND_JUMP(status);
80 
81  som_min.x = center.x - Region.hextent.xlat;
82  som_min.y = center.y - Region.hextent.ylon;
83  som_max.x = center.x + Region.hextent.xlat;
84  som_max.y = center.y + Region.hextent.ylon;
85 
86  status = MtkBlsToSomXY(Path, MINRESOLUTION, 1, 0, 0, &corner.x, &corner.y);
87  MTK_ERR_COND_JUMP(status);
88 
89  corner.x -= MINRESOLUTION / (double)2.0;
90  corner.y -= MINRESOLUTION / (double)2.0;
91  som_min.x = (floor((som_min.x - corner.x) / MINRESOLUTION)) * MINRESOLUTION + corner.x;
92  som_min.y = (floor((som_min.y - corner.y) / MINRESOLUTION)) * MINRESOLUTION + corner.y;
93  som_max.x = (ceil((som_max.x - corner.x) / MINRESOLUTION)) * MINRESOLUTION + corner.x;
94  som_max.y = (ceil((som_max.y - corner.y) / MINRESOLUTION)) * MINRESOLUTION + corner.y;
95 
96  map.som.ctr.x = (som_max.x + som_min.x) / 2.0;
97  map.som.ctr.y = (som_max.y + som_min.y) / 2.0;
98 
99  map.nline = (int) (som_max.x - som_min.x) / map.resolution;
100  map.nsample = (int) (som_max.y - som_min.y) / map.resolution;
101 
102  /* ------------------------- */
103  /* Compute upper left corner */
104  /* ------------------------- */
105 
106  map.som.ulc.x = som_min.x + (map.resolution / (double)2.0);
107  map.som.ulc.y = som_min.y + (map.resolution / (double)2.0);
108 
109  /* --------------------------- */
110  /* Compute lower right corner */
111  /* --------------------------- */
112 
113  map.som.lrc.x = som_max.x - (map.resolution / (double)2.0);
114  map.som.lrc.y = som_max.y - (map.resolution / (double)2.0);
115 
116  /* ------------------------------------------- */
117  /* Compute geographic coordinates for map area */
118  /* ------------------------------------------- */
119 
120  status = MtkSomXYToLatLon(map.som.path, map.som.ulc.x, map.som.ulc.y,
121  &map.geo.ulc.lat, &map.geo.ulc.lon);
122  MTK_ERR_COND_JUMP(status);
123 
124  status = MtkSomXYToLatLon(map.som.path, map.som.ulc.x, map.som.lrc.y,
125  &map.geo.urc.lat, &map.geo.urc.lon);
126  MTK_ERR_COND_JUMP(status);
127 
128  status = MtkSomXYToLatLon(map.som.path, map.som.ctr.x, map.som.ctr.y,
129  &map.geo.ctr.lat, &map.geo.ctr.lon);
130  MTK_ERR_COND_JUMP(status);
131 
132  status = MtkSomXYToLatLon(map.som.path, map.som.lrc.x, map.som.lrc.y,
133  &map.geo.lrc.lat, &map.geo.lrc.lon);
134  MTK_ERR_COND_JUMP(status);
135 
136  status = MtkSomXYToLatLon(map.som.path, map.som.lrc.x, map.som.ulc.y,
137  &map.geo.llc.lat, &map.geo.llc.lon);
138  MTK_ERR_COND_JUMP(status);
139 
140  /* --------------------------------------------------------------------- */
141  /* Set the projection parameters in mapinfo for this path and resolution */
142  /* --------------------------------------------------------------------- */
143 
144  status = MtkPathToProjParam(Path, Resolution, &(map.pp));
145  MTK_ERR_COND_JUMP(status);
146 
147  /* ----------------------------------------------------- */
148  /* Determine start block and end block of this map plane */
149  /* ----------------------------------------------------- */
150 
151  map.start_block = (int)((map.som.ulc.x - map.pp.ulc[0])/
152  (map.pp.nline * map.pp.resolution)) + 1;
153  map.end_block = (int)((map.som.lrc.x - map.pp.ulc[0])/
154  (map.pp.nline * map.pp.resolution)) + 1;
155 
156  /* ------------------------------------------------------------------ */
157  /* Return. */
158  /* ------------------------------------------------------------------ */
159 
160  *Map_info = map;
161 
162  return MTK_SUCCESS;
163 
164 ERROR_HANDLE:
165  return status_code;
166 }
SOM Coordinates.
Definition: MisrMapQuery.h:33
#define MTKT_MAPINFO_INIT
Definition: MisrMapQuery.h:79
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
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 ctr
Definition: MisrSetRegion.h:27
MTKt_GeoCoord ulc
Definition: MisrMapQuery.h:42
#define MINRESOLUTION
Definition: MisrProjParam.h:23
MTKt_GeoCoord ctr
Definition: MisrMapQuery.h:44
MTKt_MisrProjParam pp
Definition: MisrMapQuery.h:76
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
MTKt_status MtkPathToProjParam(int path, int resolution_meters, MTKt_MisrProjParam *pp)
Get projection parameters.
MTKt_GeoRegion geo
Definition: MisrMapQuery.h:75
MTKt_status MtkSnapToGrid(int Path, int Resolution, MTKt_Region Region, MTKt_MapInfo *Map_info)
Snap a region to a MISR grid based on path number and resolution.
Definition: MtkSnapToGrid.c:40
#define MAXRESOLUTION
Definition: MisrProjParam.h:22
MTKt_boolean pixelcenter
Definition: MisrMapQuery.h:73
MTKt_SomCoord lrc
Definition: MisrMapQuery.h:58
MTKt_status MtkBlsToSomXY(int path, int resolution_meters, int block, float line, float sample, double *som_x, double *som_y)
Convert from Block, Line, Sample, to SOM Coordinates.
Definition: MtkBlsToSomXY.c:33
MTKt_SomCoord ctr
Definition: MisrMapQuery.h:57
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
MTKt_SomRegion som
Definition: MisrMapQuery.h:74
Region of interest.
Definition: MisrSetRegion.h:41
MTKt_SomCoord ulc
Definition: MisrMapQuery.h:56
MTKt_status MtkLatLonToSomXY(int path, double lat_dd, double lon_dd, double *som_x, double *som_y)
Convert decimal degrees latitude and longitude to SOM X, SOM Y.

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