def lonlat_intersect(lonlat1, lonlat2):
      """
      Check if two lonlat boxes intersect
      :lonlat1: list, [leftlon, rightlon, botlat, toplat]
      :lonlat2: list, [leftlon, rightlon, botlat, toplat]
      :return: true if lonlat boxes overlap, false otherwise
      """
      # Before continuing, note that a common way to check if two intervals [a,b] and [x,y] overlap
      # is to check b > x AND a < y. In this function we're checking if two BOXes overlap
      # which only happens if there's a vertical overlap AND a horizontal overlap.

      # if the latitude intervals don't overlap we have nothing further to discuss
      if not (lonlat1[2] < lonlat2[3] and lonlat1[3] > lonlat2[2]):
            return False

      # Now all we have to do is determine if the longitude intervals intersect

      # if both cross dateline, then the longitude intervals intersect at the dateline
      if lonlat1[0] > lonlat1[1] and lonlat2[0] > lonlat2[1]:
            return True

      # if only lonlat1 crosses dateline, check intervals from lonlat1[0] to 180 and -180 to lonlat1[1].
      # the computation simplifies because 180 will always be greater than lonlat2[1] and -180 always smaller than lonlat2[0]
      elif lonlat1[0] > lonlat1[1]:
            return lonlat1[0] < lonlat2[1] or lonlat1[1] > lonlat2[0]

      elif lonlat2[0] > lonlat2[1]:
            return lonlat2[0] < lonlat1[1] or lonlat2[1] > lonlat1[0]

      # neither cross dateline, check if longitudes overlap like normal
      else:
            return lonlat1[0] < lonlat2[1] and lonlat1[1] > lonlat2[0]