Turbo87 / utm

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

38U 37U boundaries issue #44

Closed senyai closed 7 months ago

senyai commented 5 years ago

Hi! I have this polygon:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
        [42.0175123214722,52.3537568545561],
        [41.9911193847656,52.3522365310418],
        [42.0013117790222,52.352714914338],
        [42.0175123214722,52.3537568545561]
          ]
        ]
      }
    }
  ]
}

It looks all right on https://geojson.io, but when I use from_latlon the coordinates aren't looking good:

for lon, lat in (
        [42.0175123214722,52.3537568545561],
        [41.9911193847656,52.3522365310418],
        [42.0013117790222,52.352714914338],
        [42.0175123214722,52.3537568545561],
    ):
    res = utm.from_latlon(lat, lon)
    print(res)

(296891.7091715876, 5804572.595912797, 38, 'U') (703702.9711657077, 5804427.828889267, 37, 'U') (295783.8970581499, 5804502.368612623, 38, 'U') (296891.7091715876, 5804572.595912797, 38, 'U')

Is this expected behavior?

bartvanandel commented 7 months ago

Yes, this is expected behavior. If you provide the points individually, the algorithm will determine the zone for each point individually. You can actually see this in the results you've pasted, which contain zone numbers 38 and 37.

To have the results all in the same zone, you can either force the zone, or provide the latitudes and longitudes as lists. In the latter case, the first point will determine the zone, and all other points will be put into that zone as well.

This will currently only work if all points are on the same side of the equator, but there are some requests to change or work around this.

senyai commented 7 months ago

Thank you for your explanation.