function florida_sample (  )

%*****************************************************************************80
%
%% florida_sample() randomly samples points in Florida.
%
%  Discussion:
%
%    The MATLAB Mapping toolbox includes a representation of Florida as
%    a polygonal sequence of longitudes and latitudes.
%
%    The MATLAB function inpolygon() can report wheter a point (x,y)
%    is inside a polygon (X,Y).  We will replace Cartesian coordinates
%    by longitude and latitude.  Mathematically, this will not be exactly
%    correct, because we are working now on the surface of a sphere, but
%    we will accept the errors that occur, expecting them to be small when
%    we are working on a relatively flat patch.
%
%    The MATLAB Mapping toolbox includes a bounding box for Florida, in
%    terms of longitude and latitude.
%
%    To get N random sample points in Florida, repeatedly request a random
%    point in the bounding box, but only accept such a point if it is
%    inside the Florida polygon.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 June 2016
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FLORIDA_SAMPLE:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Seek sample points within Florida.\n' );
%
%  Open a graphics figure.
%
  figure
%
%  Construct a map axis suitable for displaying Florida.
%
  ax = usamap ( 'Florida' );
%
%  SHAPEREAD() reads the shapes of the US states.
%  We will use the "low resolution" data.
%  We will ask for "geo coords", that is, longitude and latitude.
%  Because of our bounding box, only Florida will be set up.
%
%  By the way, for no discernible or sensible reason, the following command
%  will not be be understood if I write "strcmpi (" instead of "strcmpi(".
%  A language in which spacing between tokens matters?  Just that one particular
%  space?  Please explain!  No, please don't!.
%
  florida_lo = shaperead ( 'usastatelo', ...
    'UseGeoCoords', true,...
    'Selector', { @ ( name ) strcmpi( name, 'Florida' ), 'Name' } );
%
%  For our random sampling box, create shorthand names for the limits.
%
  lon_min = florida_lo(1).BoundingBox(1,1);
  lon_max = florida_lo(1).BoundingBox(2,1);
  lat_min = florida_lo(1).BoundingBox(1,2);
  lat_max = florida_lo(1).BoundingBox(2,2);
%
%  Display the outline of Florida, and fill it with a green with some blue.
%
  geoshow ( florida_lo, 'FaceColor', [ 0.3, 1.0, 0.675 ] );
%
%  Choose random LL points in the bounding box.
%  Accept them only if they are containined in the Florida polygon.
%
  for i = 1 : 100

    inside = 0;

    while ( ~ inside )

      lat = lat_min + ( lat_max - lat_min ) * rand ( );
      lon = lon_min + ( lon_max - lon_min ) * rand ( );

      inside = inpolygon ( lon, lat, florida_lo(1).Lon, florida_lo(1).Lat );

      if ( inside )
        plotm ( lat, lon, 'r.', 'MarkerSize', 15 );
        break
      end

    end

  end
%
%  Save a copy of the plot.
%
  print ( '-dpng', 'florida_sample.png' )

  return
end
