def coordinates_to_geo_json(coordinates)
      coordinates = swap_lat_lon(coordinates)
      outer_coords, *inner_coords = coordinates
      factory = RGeo::Cartesian.simple_factory
      exterior = factory.linear_ring(outer_coords.map { |lon, lat| factory.point(lon, lat) })
      interior_rings = inner_coords.map do |polygon|
        factory.linear_ring(polygon.map { |lon, lat| factory.point(lon, lat) })
      end
      polygon = factory.polygon(exterior, interior_rings)
      RGeo::GeoJSON.encode(polygon).to_json
    rescue RGeo::Error::InvalidGeometry, NoMethodError
      invalid_coordinates!
    end
def coordinates_to_geo_json(coordinates)
      coordinates = swap_lat_lon(coordinates)
      outer_coords, *inner_coords = coordinates
      factory = RGeo::Cartesian.simple_factory
      exterior = factory.linear_ring(outer_coords.map { |lon, lat| factory.point(lon, lat) })
      interior_rings = inner_coords.map do |polygon|
        factory.linear_ring(polygon.map { |lon, lat| factory.point(lon, lat) })
      end
      polygon = factory.polygon(exterior, interior_rings)
      RGeo::GeoJSON.encode(polygon).to_json
    rescue RGeo::Error::InvalidGeometry, NoMethodError
      invalid_coordinates!
    end
Convert a nested array of coordinates to a GeoJSON document

 @param [Array<Array<Array>>] coordinates Nested array of coordinates.

 @example Convert a set of nested coordinates of Banbury to a GeoJSON document.
   coordinates = [
     [
       [52.24630137198303, -1.7358398437499998], [52.05249047600099, -1.8923950195312498],
       [51.891749018068246, -1.56829833984375], [51.91208502557545, -1.27716064453125],
       [52.032218104145294, -1.19476318359375], [52.19413974159753, -1.24420166015625],
       [52.24125614966341, -1.5902709960937498], [52.24630137198303, -1.7358398437499998]
     ],
     [
       [52.12590076522272, -1.58203125], [52.12590076522272, -1.476287841796875],
       [52.075285904832334, -1.46392822265625], [52.06937709602395, -1.58203125],
       [52.12590076522272, -1.58203125]
     ],
     [
       [52.01531743663362, -1.4556884765625], [51.97642166216334, -1.483154296875],
       [51.96626938051444, -1.3677978515625], [52.0102459910103, -1.3568115234375],
       [52.01531743663362, -1.4556884765625]
     ]
   ]
   H3.coordinates_to_geo_json(coordinates)
   "{\"type\":\"Polygon\",\"coordinates\":[
     [
       [-1.7358398437499998,52.24630137198303], [-1.8923950195312498,52.05249047600099],
       [-1.56829833984375,51.891749018068246], [-1.27716064453125,51.91208502557545],
       [-1.19476318359375,52.032218104145294], [-1.24420166015625,52.19413974159753],
       [-1.5902709960937498,52.24125614966341], [-1.7358398437499998,52.24630137198303]
     ],
     [
       [-1.58203125,52.12590076522272], [-1.476287841796875,52.12590076522272],
       [-1.46392822265625,52.075285904832334], [-1.58203125,52.06937709602395],
       [-1.58203125,52.12590076522272]
     ],
     [
       [-1.4556884765625,52.01531743663362], [-1.483154296875,51.97642166216334],
       [-1.3677978515625,51.96626938051444], [-1.3568115234375,52.0102459910103],
       [-1.4556884765625,52.01531743663362]
     ]
   ]}"

 @raise [ArgumentError] Failed to parse the given coordinates.

 @return [String] GeoJSON document.