# RandomPoint in geographic region from Polygon[region_]?

How do you generate a RandomPoint in a geographic region?

state = Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}];
GeoGraphics[{EdgeForm[Red], Opacity[0.1], Polygon[state]}]


This produces the polygon outline of the state. I would like to get a random point (location coordinates) in the geographic region. I tried -

RandomPoint[Polygon[state]]


but this gives the error

RandomPoint::creg: The first argument Polygon[Illinois, United States] is expected to be a parameter-free region. >>


How do you use RandomPoint for geographic regions?

• GeoPosition[ RandomPoint[ EntityValue[state, EntityProperty["AdministrativeDivision", "Polygon"]] /. GeoPosition -> Identity]] Commented Aug 18, 2015 at 22:30
• @ilian So, it seems that Polygon is doing something special with a geographic object. Thanks for the workaround. Commented Aug 18, 2015 at 22:48
• @ilian I had been puzzled by this as well. Is the usage you suggest reported anywhere in the docs? If not, it would be great if you could convert your comment into an answer and possibly expand upon what is going on here. Commented Aug 18, 2015 at 22:55
• @MarcoB Converted into an answer, though this usage is just a kludge. Commented Aug 18, 2015 at 23:18

The polygon of interest is

state = Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}];
(polygon = state["Polygon"]) // Short

(* Polygon[GeoPosition[{{{36.9821, -89.1329}, <<187>> ,{36.9821, -89.1329}}}]] *)


however that expression is not a valid region

 RegionQ[polygon]

(* False *)


because the argument of Polygon[] is not a list of point coordinates. Nevertheless RandomPoint can be used after GeoPosition is stripped

RandomPoint[polygon /. GeoPosition -> Identity]

(* {39.7605, -89.8648} *)


Arguably the region functionality could be extended to support GeoPositions, but as of now this is not implemented.

• Just a side note: this distribution is a bit non-uniform on the Earth surface. It is uniform only in equal-area projections (e.g. Gall–Peters projection). Commented Nov 29, 2015 at 2:25