I've built a small interface for project because it's been a bit disorienting for me and others to quickly change the range on the plots. Eventually we'll tie different features of the data to colors but, beforehand, I was hoping to improve the performance of the interface which leads me to ask for a review of my code.
The way to input the data might be improved? And I'm wondering if there is a more natural way to check the range is valid before rendering the plot? Right now the data is being parsed numerically instead of using the built in GeoWithinQ
which I've been happy with but assume it could be better perhaps?
geoFilter[org_, coords_List] :=
Module[{var, filtered, bounds, l, t} ,
(* Numberically filters points which fall inside bounds from parcel \
data *)
(* Set up *)
bounds = coordassoc[coords];
l = Length@org;
(* Main Filtering Sequence *)
filtered = org[
Select[
#lat > bounds[["lat", "min"]] &&
#lat < bounds[["lat", "max"]] &&
#lng >
bounds[["lng", "min"]] &&
#lng <
bounds[["lng", "max"]] &
]
];
(* Final Check *)
If[Length@filtered >= 1, filtered,
Throw["No Points in Selected Area"]]
]
checks[{{minlat_, maxlat_}, {minlng_, maxlng_}}] :=
minlat < maxlat && minlng < maxlng
boundedAreaGraphic[ds_, coords_] := Module[{var, pts, g},
(* Input bounded region list :
Apply bounds and returns dataset with required features *)
(*
Checks bounds of coordinates *)
var = geoFilter[ds, coords];
pts = GeoPosition[{#lat, #lng}] & /@ var;
(* Output Graphics *)
g = GeoGraphics[
{AbsolutePointSize[4], Point /@ pts},
GeoProjection -> "Mercator",
GeoGridLines -> Automatic,
GeoRangePadding -> None,
ImageSize -> Large,
Frame -> True,
ImagePadding -> 40,
PlotLabel ->
Style["Number of Existing Buildings in Bounds: " <>
ToString@Length@pts, "CodeText"],
GeoBackground -> "StreetMapNoLabels"
];
Print["Debug | GeoRange Plot: " <>
ToString@First@Values@Options[g, GeoRange]];
g
]
Manipulate[
If[
checks[{{minlat, maxlat}, {minlng, maxlng}}],
Catch[boundedAreaGraphic[
data, {{minlat, maxlat}, {minlng, maxlng}}]],
Nothing
],
{{minlat, 49.24, "Min Latitude"}, 49.18, 49.41, 0.00001},
{{maxlat, 49.292, "Max Latitude"}, 49.18, 49.41, 0.00001},
{{minlng, -123.15, "Min Longitude"}, -123.2, -123.0, 0.00001},
{{maxlng, -123.05, "Max Longitude"}, -123.2, -123.0, 0.00001},
ContinuousAction -> False
]
