@@ -182,23 +182,22 @@ function setup_tile_routes(config, auth)
182
182
reg = qp[" region" ]
183
183
rtype = qp[" rtype" ]
184
184
185
- criteria_names, lbs, ubs = remove_rugosity (reg, parse_criteria_query (qp)... )
186
-
187
185
# Calculate tile bounds
188
186
lon_min, lon_max, lat_max, lat_min = _tile_bounds (z, x, y)
187
+ lons, lats = (lon_min, lon_max), (lat_max, lat_min)
189
188
@debug " Thread $(thread_id) - $(now ()) : Calculated bounds (z/x/y, lon bounds, lat bounds): $z $x $y | $(_tile_to_lon_lat (z, x, y)) | ($(lon_min) , $(lon_max) ), ($(lat_min) , $(lat_max) )"
190
189
191
- # Extract relevant data based on tile coordinates
192
- @debug " Thread $(thread_id) - $( now ()) : Extracting tile data "
193
- mask_data = threshold_mask (
194
- reg_assess_data[reg],
195
- Symbol (rtype),
196
- CriteriaBounds .(criteria_names, lbs, ubs),
197
- (lon_min, lon_max),
198
- (lat_min, lat_max )
190
+ # Check if request is within target region
191
+ # return empty tile if not.
192
+ lookup = getfield (reg_assess_data[reg], Symbol ( :valid_ , rtype))
193
+ lat1, lat2 = lats[ 1 ] > lats[ 2 ] ? (lats[ 2 ], lats[ 1 ]) : (lats[ 1 ], lats[ 2 ])
194
+
195
+ within_search = (
196
+ (lons[ 1 ] .<= lookup . lons .<= lons[ 2 ]) .&
197
+ (lat1 .<= lookup . lats .<= lat2 )
199
198
)
200
199
201
- if any (size (mask_data) .== 0 )
200
+ if ! any (within_search )
202
201
no_data_path = cache_filename (
203
202
Dict (" no_data" => " none" ), config, " no_data" , " png"
204
203
)
@@ -207,6 +206,34 @@ function setup_tile_routes(config, auth)
207
206
return file (no_data_path; headers= TILE_HEADERS)
208
207
end
209
208
209
+ # TODO : Re-use pre-existing cache for entire region if available
210
+ # Get mask data if available
211
+ # assessed_fn = cache_filename(
212
+ # extract_criteria(qp, suitability_criteria()), config, "$(reg)_suitable", "tiff"
213
+ # )
214
+
215
+ # TODO : Use previously generated results
216
+ # assessed_fn = assess_region(config, qp, reg, rtype, reg_assess_data)
217
+ # if isfile(assessed_fn)
218
+ # # assessed = Raster(assessed_fn; lazy=true)
219
+ # # Load regional data, subset to area of interest and assess
220
+ # mask_data =
221
+ # else
222
+ # # Otherwise, assess the target area directly
223
+ # end
224
+
225
+ criteria_names, lbs, ubs = remove_rugosity (reg, parse_criteria_query (qp)... )
226
+
227
+ # Extract relevant data based on tile coordinates
228
+ @debug " Thread $(thread_id) - $(now ()) : Extracting tile data"
229
+ mask_data = threshold_mask (
230
+ reg_assess_data[reg],
231
+ Symbol (rtype),
232
+ CriteriaBounds .(criteria_names, lbs, ubs),
233
+ (lon_min, lon_max),
234
+ (lat_min, lat_max)
235
+ )
236
+
210
237
@debug " Thread $(thread_id) - Extracted data size: $(size (mask_data)) "
211
238
212
239
@debug " Thread $(thread_id) - $(now ()) : Creating PNG (with transparency)"
0 commit comments