6

I was wondering what the automatic GeoZoomLevel for Mathematica was. For instance,

GeoGraphics[Entity["City", {"NewYork", "NewYork", "UnitedStates"}]]

seems to display New York City at a GeoZoomLevel of 10, but

GeoGraphics[Entity["Country", "UnitedStates"]]

seems to display the US at a GeoZoomLevel of 4. How does Mathematica decide which GeoZoomLevel to use?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

1 Answers1

5

The core of the problem seems to be that you need the two geo-positions that define the bounding box of the region you are looking at. Mathematica has two similar functions for that: GeoBounds and GeoBoundingBox

ny = Entity["City", {"NewYork", "NewYork", "UnitedStates"}];
us = Entity["Country", "UnitedStates"];

GeoBounds[ny]
GeoBoundingBox[ny]
(* {{40.4774, 40.9175}, {-74.2591, -73.7003}} *)
(* {GeoPosition[{40.4774, -74.2591}], GeoPosition[{40.9175, -73.7003}]} *)

From the GeoBounds output, the zoom-level can directly be estimated

GIS`EstimateZoom[GeoBounds[#]] & /@ {ny, us}
(* {11, 4} *)

As you see, there is a discrepancy in the zoom-level of NY because

Options[GeoGraphics[
  Entity["City", {"NewYork", "NewYork", "UnitedStates"}]], 
  GeoZoomLevel]
(* {GeoZoomLevel -> 10} *)

However, there are some more arguments to GIS`EstimateZoom and the estimation depends on other factors like the geo-server. Nevertheless, the implementation of this function is not too long and it should be easy enough to understand it for your purpose.

<< GeneralUtilities`
GIS`EstimateZoom;
PrintDefinitions[GIS`EstimateZoom]
halirutan
  • 112,764
  • 7
  • 263
  • 474