MISR Toolkit  1.5.1
MtkSetRegionByLatLonExtent.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkSetRegionByLatLonExtent =
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 "MisrError.h"
19 #include "MisrUtil.h"
20 #include <string.h>
21 #ifndef _MSC_VER
22 #include <strings.h>
23 #endif
24 #include <stdlib.h>
25 
78  double ctr_lat_dd,
79  double ctr_lon_dd,
80  double lat_extent,
81  double lon_extent,
82  const char *extent_units,
83  MTKt_Region *region )
84 {
85  MTKt_status status_code; /* Return code of this function */
86  MTKt_Region rgn; /* Region structure */
87  double resolution; /* Resolution */
88  char *endptr; /* End ptr for strod */
89 
90  if (region == NULL)
92 
93  /* Check extent_units */
94  if (extent_units == NULL)
96 
97  /* Check latitude bounds */
98  if (ctr_lat_dd > 90.0 || ctr_lat_dd < -90.0)
100  if (lat_extent <= 0.0)
102 
103  /* Check longitude bounds */
104  if (ctr_lon_dd > 180.0 || ctr_lon_dd < -180.0)
106  if (lon_extent <= 0.0)
108 
109  /* Set center of region */
110  rgn.geo.ctr.lat = ctr_lat_dd;
111  rgn.geo.ctr.lon = ctr_lon_dd;
112 
113  /* Set half of the overall extent of region in specified units measured from center */
114  if (strncasecmp(extent_units, "degrees", strlen(extent_units)) == 0 ||
115  strncasecmp(extent_units, "deg", strlen(extent_units)) == 0 ||
116  strncasecmp(extent_units, "dd", strlen(extent_units)) == 0) {
117 
118  /* Average earth circumference (40075004m + 39940638m) / 2.0 = 40007821m */
119  double meters_per_deg = 40007821.0 / 360.0;
120  rgn.hextent.xlat = (lat_extent * meters_per_deg) / 2.0;
121  rgn.hextent.ylon = (lon_extent * meters_per_deg) / 2.0;
122 
123  } else if (strncasecmp(extent_units, "meters", strlen(extent_units)) == 0 ||
124  strncasecmp(extent_units, "m", strlen(extent_units)) == 0) {
125 
126  rgn.hextent.xlat = lat_extent / 2.0;
127  rgn.hextent.ylon = lon_extent / 2.0;
128 
129  } else if (strncasecmp(extent_units, "kilometers", strlen(extent_units)) == 0 ||
130  strncasecmp(extent_units, "km", strlen(extent_units)) == 0) {
131 
132  rgn.hextent.xlat = (lat_extent * 1000) / 2.0;
133  rgn.hextent.ylon = (lon_extent * 1000) / 2.0;
134 
135  } else if ((resolution = strtod(extent_units, &endptr)) != 0) {
136 
137  if (strncasecmp(endptr, "meters", strlen(endptr)) == 0 ||
138  strncasecmp(endptr, "m", strlen(endptr)) == 0 ||
139  strncasecmp(endptr, " meters", strlen(endptr)) == 0 ||
140  strncasecmp(endptr, " m", strlen(endptr)) == 0) {
141 
142  rgn.hextent.xlat = (lat_extent * resolution) / 2.0;
143  rgn.hextent.ylon = (lon_extent * resolution) / 2.0;
144 
145  } else if (strncasecmp(endptr, "kilometers", strlen(endptr)) == 0 ||
146  strncasecmp(endptr, "km", strlen(endptr)) == 0 ||
147  strncasecmp(endptr, " kilometers", strlen(endptr)) == 0 ||
148  strncasecmp(endptr, " km", strlen(endptr)) == 0) {
149 
150  rgn.hextent.xlat = (lat_extent * resolution * 1000) / 2.0;
151  rgn.hextent.ylon = (lon_extent * resolution * 1000) / 2.0;
152 
153  } else {
154 
156 
157  }
158 
159  } else {
160 
162 
163  }
164 
165  *region = rgn;
166 
167  return MTK_SUCCESS;
168 
169 ERROR_HANDLE:
170  return status_code;
171 }
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_GeoCoord ctr
Definition: MisrSetRegion.h:27
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
MTKt_status MtkSetRegionByLatLonExtent(double ctr_lat_dd, double ctr_lon_dd, double lat_extent, double lon_extent, const char *extent_units, MTKt_Region *region)
Select region by latitude, longitude in decimal degrees, and extent in specified units of degrees...
int strncasecmp(const char *s1, const char *s2, size_t n)
Definition: strncasecmp.c:18
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41

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