Turbo87 / utm

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

Conversion from Lat/Long with forced zone letter and number not working. #34

Closed zplett closed 6 years ago

zplett commented 6 years ago

I'm trying to use the library to convert a lat / long coordinate to utm specifying the zone letter and zone number. An instance of this can be taken from one of the unit tests:

def test_force_zone(self):
        # test forcing zone ranges
        # NYC should be zone 18T
        self.assert_zone_equal(UTM.from_latlon(40.71435, -74.00597, 19, 'T'), 19, 'T')
        self.assert_zone_equal(UTM.from_latlon(40.71435, -74.00597, 17, 'T'), 17, 'T')
        self.assert_zone_equal(UTM.from_latlon(40.71435, -74.00597, 18, 'u'), 18, 'U')
        self.assert_zone_equal(UTM.from_latlon(40.71435, -74.00597, 18, 'S'), 18, 'S')

Locally running the line: UTM.from_latlon(40.71435, -74.00597, 19, 'T')

Gives the error:

Traceback (most recent call last):
  File "blank.py", line 8, in <module>
    print(utm.from_latlon(40.71435, -74.00597, 19, 'T'))
TypeError: from_latlon() takes at most 3 arguments (4 given)
zplett commented 6 years ago

I downloaded the current repository locally which fixed the above issue but forcing a lat/lon pair from one zone to another isn't changing the outcome of the UTM easting/northing values as it should. For instance: lat: 0.0222750053229278 lon: -79.9609177347527 Is inherently in zone 17 N, forcing it into 17 M (crossing from the northern to southern hemisphere) should change the output UTM values but that doesn't seem to be happening.

astrojuanlu commented 6 years ago

Hi @zplett! Did you close the issue because you solved your problem?

zplett commented 6 years ago

I believe I solved the issue by changing line 243 (in conversion.py): elif negative(latitude): northing += 10000000 to: elif zone_letter <= 'M': northing += 10000000 However I wanted to review this on my own to make sure it is correct before trying to merge.