MISR Toolkit  1.5.1
MtkRegionToPathList.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkRegionToPathList =
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 "MisrOrbitPath.h"
18 #include "MisrCoordQuery.h"
19 #include "MisrError.h"
20 #include "MisrProjParam.h"
21 #include <stdlib.h>
22 
39  MTKt_Region region,
40  int *pathcnt,
41  int **pathlist )
42 {
43  MTKt_status status_code; /* Return code of this function */
44  MTKt_status status; /* Return status */
45  int b; /* Block */
46  float l; /* Line */
47  float s; /* Sample */
48  int path; /* Loop index */
49  int pathlist_tmp[NPATH]; /* Temp pathlist */
50  int *list = NULL; /* Temp list */
51  int cnt = 0; /* Path count */
52  int i; /* Corner index */
53  float lines[4]; /* Block corner lines */
54  float samples[4]; /* Block corner samples */
55  MTKt_boolean found = MTK_FALSE; /* Found a corner in the region flag */
56  double lat_hextent_deg; /* Lat extent in degrees */
57  double lon_hextent_deg; /* Lon exten in degrees */
58  double ulclat; /* Lat of ULC of Region */
59  double ulclon; /* Lon of ULC of Region */
60  double lrclat; /* Lat of LRC of Region */
61  double lrclon; /* Lon of LRC of Region */
62  double blocklat = 0.0; /* Lat of block */
63  double blocklon = 0.0; /* Lon of block */
64  double deg_per_meter = 360.0 / 40007821.0; /* Average earth circumference (40075004m + 39940638m) / 2.0 = 40007821m */
65 
66  if (pathcnt == NULL || pathlist == NULL)
68 
69  /* -------------------------------------------- */
70  /* Set lines and samples for four block corners */
71  /* -------------------------------------------- */
72 
73  lines[0] = 0.0;
74  samples[0] = 0.0;
75  lines[1] = 0.0;
76  samples[1] = MAXNSAMPLE - 1;
77  lines[2] = MAXNLINE - 1 ;
78  samples[2] = MAXNSAMPLE - 1;
79  lines[3] = MAXNLINE - 1;
80  samples[3] = 0.0;
81 
82  for (path = 1; path <= NPATH; path++) {
83 
84  /* ------------------------------------------------------------------- */
85  /* If center of region is in a block then we have found a path - done. */
86  /* ------------------------------------------------------------------- */
87 
88  status = MtkLatLonToBls(path, MAXRESOLUTION, region.geo.ctr.lat,
89  region.geo.ctr.lon, &b, &l, &s);
90 
91  if (status == MTK_SUCCESS) { /* --- Center coordinate is in a block in this path --- */
92 
93  found = MTK_TRUE;
94 
95  } else { /* --- Search block corners for a coordinate in this region --- */
96  lat_hextent_deg = (region.hextent.xlat * deg_per_meter);
97  lon_hextent_deg = (region.hextent.ylon * deg_per_meter);
98  ulclat = region.geo.ctr.lat - lat_hextent_deg;
99  ulclon = region.geo.ctr.lon - lon_hextent_deg;
100  lrclat = region.geo.ctr.lat + lat_hextent_deg;
101  lrclon = region.geo.ctr.lon + lon_hextent_deg;
102 
103  /* ------------------------------------------------------------------------ */
104  /* Determine Lat/Lon coordinates of the corners of the region for this path */
105  /* ------------------------------------------------------------------------ */
106  status = MtkLatLonToBls(path, MAXRESOLUTION,
107  region.geo.ctr.lat - lat_hextent_deg,
108  region.geo.ctr.lon - lon_hextent_deg,
109  &b, &l, &s);
110 
111  /* --------------------------------------------------------------- */
112  /* Loop over each block of the to find a corner inside the region */
113  /* --------------------------------------------------------------- */
114 
115  for (b = 1; b <= NBLOCK; b++) {
116  for (i = 0; i < 4; i++) {
117  status = MtkBlsToLatLon(path, MAXRESOLUTION,b, lines[i], samples[i],
118  &blocklat, &blocklon);
119  if (blocklat >= ulclat && blocklat <= lrclat && blocklon >= ulclon && blocklon <= lrclon) {
120  found = MTK_TRUE;
121  // printf("Found block: %i in path: %i\n",b,path);
122  }
123  }
124  if (found) break;
125  }
126  } /* --- End of block corner search --- */
127 
128  /* -------------------------------------------------- */
129  /* Add path to pathlist only if it crosses the region */
130  /* -------------------------------------------------- */
131 
132  if (found) {
133  pathlist_tmp[cnt++] = path;
134  found = MTK_FALSE;
135  } // else { printf("No block found for path: %i\n", path); }
136  } /* --- End of path loop --- */
137 
138  if (cnt == 0) MTK_ERR_CODE_JUMP(MTK_NOT_FOUND);
139 
140  list = (int *)malloc(cnt * sizeof(int));
141  if (list == NULL)
143 
144  for (path = 0; path < cnt; path++) {
145  list[path] = pathlist_tmp[path];
146  }
147 
148  *pathcnt = cnt;
149  *pathlist = list;
150 
151  return MTK_SUCCESS;
152  ERROR_HANDLE:
153  return status_code;
154 }
MTKt_status MtkBlsToLatLon(int path, int resolution_meters, int block, float line, float sample, double *lat_dd, double *lon_dd)
Convert from Block, Line, Sample, to Latitude and Longitude in decimal degrees.
MTKt_status MtkLatLonToBls(int path, int resolution_meters, double lat_dd, double lon_dd, int *block, float *line, float *sample)
Convert decimal degrees latitude and longitude to block, line, sample.
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MAXNSAMPLE
Definition: MisrProjParam.h:25
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_boolean
Definition: MisrError.h:6
long b
Definition: jpegint.h:371
MTKt_GeoCoord ctr
Definition: MisrSetRegion.h:27
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
#define NBLOCK
Definition: MisrProjParam.h:51
#define MAXRESOLUTION
Definition: MisrProjParam.h:22
#define NPATH
Definition: MisrProjParam.h:31
MTKt_status MtkRegionToPathList(MTKt_Region region, int *pathcnt, int **pathlist)
Get list of paths that cover a particular region.
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41
#define MAXNLINE
Definition: MisrProjParam.h:24

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