MISR Toolkit  1.5.1
MtkRegionPathToBlockRange.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkRegionPathToBlockRange =
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 "MisrProjParam.h"
20 #include "MisrError.h"
21 #include <stdlib.h>
22 
23 #define ULI 0 /* Upper left corner index */
24 #define LRI 1 /* Lower right corner index */
25 
39  MTKt_Region region,
40  int path,
41  int *start_block,
42  int *end_block )
43 {
44  MTKt_status status_code; /* Return status of this function */
45  MTKt_status status; /* Return status */
46  int b; /* Block */
47  int n = 0; /* Block count */
48  int sb = 0; /* Start block */
49  MTKt_SomRegion rgnsom; /* Region Som coordinates */
50  MTKt_SomCoord blksom[2]; /* Block Som coordinate */
51  MTKt_boolean found = MTK_FALSE; /* Found a corner in the region flag */
52 
53  if (start_block == NULL || end_block == NULL)
55 
56  /* -------------------------------------------------------------------- */
57  /* Determine SOM coordinates of the corners of the region for this path */
58  /* -------------------------------------------------------------------- */
59 
60  status = MtkLatLonToSomXY(path, region.geo.ctr.lat, region.geo.ctr.lon,
61  &rgnsom.ctr.x, &rgnsom.ctr.y);
62  MTK_ERR_COND_JUMP(status);
63  rgnsom.path = path;
64  rgnsom.ulc.x = rgnsom.ctr.x - region.hextent.xlat;
65  rgnsom.ulc.y = rgnsom.ctr.y - region.hextent.ylon;
66  rgnsom.lrc.x = rgnsom.ctr.x + region.hextent.xlat;
67  rgnsom.lrc.y = rgnsom.ctr.y + region.hextent.ylon;
68 
69  /* --------------------------------------------------------------- */
70  /* Loop over each block of the to find a corner inside the region */
71  /* --------------------------------------------------------------- */
72 
73  for (b = 1; b <= NBLOCK; b++) {
74 
75  /* Determine ulc and lrc som coordinates for all this block */
76  status = MtkBlsToSomXY(path, MAXRESOLUTION, b, 0.0, 0.0,
77  &blksom[ULI].x, &blksom[ULI].y);
78  MTK_ERR_COND_JUMP(status);
79 
80  status = MtkBlsToSomXY(path, MAXRESOLUTION, b, MAXNLINE-1, MAXNSAMPLE-1,
81  &blksom[LRI].x, &blksom[LRI].y);
82  MTK_ERR_COND_JUMP(status);
83 
84  /* Checks if ulc of the block is inside the region */
85  if (blksom[ULI].x >= rgnsom.ulc.x && blksom[ULI].x <= rgnsom.lrc.x &&
86  blksom[ULI].y >= rgnsom.ulc.y && blksom[ULI].y <= rgnsom.lrc.y)
87 
88  found = MTK_TRUE;
89 
90  /* Checks if urc of the block is inside the region */
91  else if (blksom[ULI].x >= rgnsom.ulc.x && blksom[ULI].x <= rgnsom.lrc.x &&
92  blksom[LRI].y >= rgnsom.ulc.y && blksom[LRI].y <= rgnsom.lrc.y)
93 
94  found = MTK_TRUE;
95 
96  /* Checks if lrc of the block is inside the region */
97  else if (blksom[LRI].x >= rgnsom.ulc.x && blksom[LRI].x <= rgnsom.lrc.x &&
98  blksom[LRI].y >= rgnsom.ulc.y && blksom[LRI].y <= rgnsom.lrc.y)
99 
100  found = MTK_TRUE;
101 
102  /* Checks if llc of the block is inside the region */
103  else if (blksom[LRI].x >= rgnsom.ulc.x && blksom[LRI].x <= rgnsom.lrc.x &&
104  blksom[ULI].y >= rgnsom.ulc.y && blksom[ULI].y <= rgnsom.lrc.y)
105 
106  found = MTK_TRUE;
107 
108  /* Checks if ulc of the region is inside this block */
109  else if (rgnsom.ulc.x >= blksom[ULI].x && rgnsom.ulc.x <= blksom[LRI].x &&
110  rgnsom.ulc.y >= blksom[ULI].y && rgnsom.ulc.y <= blksom[LRI].y)
111 
112  found = MTK_TRUE;
113 
114  /* Checks if lrc of the region is inside this block */
115  else if (rgnsom.lrc.x >= blksom[ULI].x && rgnsom.lrc.x <= blksom[LRI].x &&
116  rgnsom.lrc.y >= blksom[ULI].y && rgnsom.lrc.y <= blksom[LRI].y)
117 
118  found = MTK_TRUE;
119 
120  /* Checks if block straddles the region horizontally */
121  if (((blksom[ULI].x >= rgnsom.ulc.x && blksom[ULI].x <= rgnsom.lrc.x) ||
122  (blksom[LRI].x >= rgnsom.ulc.x && blksom[LRI].x <= rgnsom.lrc.x)) &&
123  (blksom[ULI].y < rgnsom.ulc.y && blksom[LRI].y > rgnsom.lrc.y))
124 
125  found = MTK_TRUE;
126 
127  /* Checks if region straddles the block horizontally */
128  if (((rgnsom.ulc.x >= blksom[ULI].x && rgnsom.ulc.x <= blksom[LRI].x) ||
129  (rgnsom.lrc.x >= blksom[ULI].x && rgnsom.lrc.x <= blksom[LRI].x)) &&
130  (rgnsom.ulc.y < blksom[ULI].y && rgnsom.lrc.y > blksom[LRI].y))
131 
132  found = MTK_TRUE;
133 
134  if (found) {
135  found = MTK_FALSE;
136  if (sb == 0) sb = b;
137  n++;
138  }
139  }
140 
141  *start_block = sb;
142  *end_block = sb + n - 1;
143 
144  return MTK_SUCCESS;
145 
146 ERROR_HANDLE:
147  return status_code;
148 }
SOM Coordinates.
Definition: MisrMapQuery.h:33
#define ULI
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
#define LRI
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
#define NBLOCK
Definition: MisrProjParam.h:51
HDFFCLIBAPI _fcd _fcd intf * n
#define MAXRESOLUTION
Definition: MisrProjParam.h:22
MTKt_SomCoord lrc
Definition: MisrMapQuery.h:58
SOM Region.
Definition: MisrMapQuery.h:54
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
Region of interest.
Definition: MisrSetRegion.h:41
MTKt_status MtkRegionPathToBlockRange(MTKt_Region region, int path, int *start_block, int *end_block)
Get start and end block numbers of a path over a particular region.
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.
#define MAXNLINE
Definition: MisrProjParam.h:24

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