def _infer_geometry(value):
 if isinstance(value, dict):
  if ('$geometry' in value):
   return value
  elif (('coordinates' in value) and ('type' in value)):
   return {'$geometry': value}
  raise InvalidQueryError('Invalid $geometry dictionary should have type and coordinates keys')
 elif isinstance(value, (list, set)):
  try:
   value[0][0][0]
   return {'$geometry': {'type': 'Polygon', 'coordinates': value}}
  except (TypeError, IndexError):
   pass
  try:
   value[0][0]
   return {'$geometry': {'type': 'LineString', 'coordinates': value}}
  except (TypeError, IndexError):
   pass
  try:
   value[0]
   return {'$geometry': {'type': 'Point', 'coordinates': value}}
  except (TypeError, IndexError):
   pass
 raise InvalidQueryError('Invalid $geometry data. Can be either a dictionary or (nested) lists of coordinate(s)')

def _infer_geometry ( value ) : if isinstance ( value , dict ) : if ( '$geometry' in value ) : return value elif ( ( 'coordinates' in value ) and ( 'type' in value ) ) : return { '$geometry' : value } raise InvalidQueryError ( 'Invalid $geometry dictionary should have type and coordinates keys' ) elif isinstance ( value , ( list , set ) ) : try : value [ 0 ] [ 0 ] [ 0 ] return { '$geometry' : { 'type' : 'Polygon' , 'coordinates' : value } } except ( TypeError , IndexError ) : pass try : value [ 0 ] [ 0 ] return { '$geometry' : { 'type' : 'LineString' , 'coordinates' : value } } except ( TypeError , IndexError ) : pass try : value [ 0 ] return { '$geometry' : { 'type' : 'Point' , 'coordinates' : value } } except ( TypeError , IndexError ) : pass raise InvalidQueryError ( 'Invalid $geometry data. Can be either a dictionary or (nested) lists of coordinate(s)' )
helper method that tries to infer the $geometry shape for a given value .