Turbo87 / utm

Bidirectional UTM-WGS84 converter for python
http://pypi.python.org/pypi/utm
MIT License
486 stars 101 forks source link

Feature Request: LatLng Boundaries from UTM Zone & latitude band #42

Open fprott opened 5 years ago

fprott commented 5 years ago

I would like to request that there is a function that returns the four corners of each UTM zone as a list of latitude, longitude tuples.

Use-case: I want to distribute a bigger mapping task onto each UTM zone. Many of my task can be parallelized. But the web-service I use needs clearly defined latitude,longitude tuples for bounding boxes.

These tuples are tedious to be calculated by hand since the latitude is based of the UTM latitude band characters and those are missing the I & O and have special cases for Z,A,B & X.

Short example implementation:

    def cacl_UTM_zone_boundary(self, zone_number: int, zone_band: str):
        lng = ((zone_number - 1) * 6) - 180  # each zone is 6 degree wide and we want the western part
        # Tricky, there is no Zone I or O, Zone Z, A,B are wrong and Zone X is strange. So we map that stuff :D
        zone_band = zone_band.upper()
        lat_look_up = {"Z": 90, "X": 84, "W": 72, "V": 56, "U": 48, "T": 40, "S": 32, "R": 24, "Q": 16, "P": 8,
                       "N": 0, "M": -8, "L": -16, "K": -24, "J": -32, "H": -40, "G": -48, "F": -56, "E": -64,
                       "D": -72, "C": -80}  # Note: no special case for A,B,Z
        # I do not need A,B,Z yet. If I never need it I have to find a better way to calc that.
        lat = lat_look_up[zone_band]
        # NW, NO, SO, SW
        return [(lat, lng), (lat - 6, lng), (lat - 6, lng - 8), (lat, lng - 8)]
Turbo87 commented 5 years ago

pull requests are welcome 😉