2

I am currently working on a project where we have to figure out the position of one point based on the known position of two (user-input) points.

Now the problem is that the users could provide two points in different UTM zones, so we have to project one of the points to the other system (at least that is how we do it.)

I coded a reference implementation in Python to test it, and now we want to use this feature in production on iOS. It seems as if the only swift proj library here is out of date and can not be used.

We looked around for a bit, but did not find a description of how to project a point from one zone to the other one without additional software.

Do you know whether this is possible, or whether there is an up-to-date proj library for swift?

Luiz Fernando Salvaterra
  • 4,192
  • 2
  • 24
  • 42

1 Answers1

2

Project point from one UTM zone to other

As you may well know, since you've coded a reference implementation in Python, this is accomplished in two steps:

1. Unproject one point from UTM to Geographic Coordinates, that is from [E, N, Zone, Hemisphere] to latitude, longitude (φ, λ);

and then,

2. Project the resulting Geographic Coordinates to UTM (another Zone, different from 1), that is from latitude, longitude (φ, λ) to UTM coordinates (E, N).

Since you haven't mentioned any Datum conversion, PROJ library becomes overkill to accomplish this task. Besides, the question is not about How to call C from Swift.

Even more because there are plenty of UTM implementations, even here on SO, for the majority of the mainstream languages (Java, Javascript, Python, C#), or at least Transverse Mercator implementations that can be easily adapted to UTM (UTM system uses Transverse Mercator as Cartographic Projection).

For Swift I couldn't find any on SO, but on GitHub I could.

https://github.com/wtw-software/UTMConversion

The conversion happens between a custom struct UTMCoordinate and CoreLocation's CLLocationCoordinate2D and CLLocation.

And it is even possible to specify a custom Datum provided you are not using the default value WGS84 used by the library.

import CoreLocation
import UTMConversion

let utmCoordinate = UTMCoordinate(northing: 7034313, easting: 569612, zone: 32, hemisphere: .northern)
let datum = UTMDatum(equitorialRadius: 6378137, polarRadius: 6356752.3142)
let coordinate = utmCoordinate.coordinate(datum: datum)

Accuracy can be accessed by comparing the library output with the results from your Python implementation.

In case you are not satisfied with the results you can always modify the source code particularly the following file where the Transverse Mercator projection (the hard math) is:

https://github.com/wtw-software/UTMConversion/blob/master/UTMConversion/TMCoordinate.swift

LuisTavares
  • 2,146
  • 2
  • 12
  • 18
  • If I understand well, the DATUM I use could be a default DATUM right? Can I take this data from the firs UTM coordinate? Or is this a default DATUM for UTM coordinates? – Luiz Fernando Salvaterra Dec 11 '19 at 11:37
  • The library's default datum is WGS84. That can be customized, for example, for SAD69 (that's what can be done with `UTMDatum`) . Note that points in different zones of the same UTM system they all use the same Datum. But UTM can be used with different data: UTM/WGS84, UTM/NAD83, UTM/SiRGAS2000, and so on.. – LuisTavares Dec 11 '19 at 19:03
  • So all I need to do is project it using UTM library setting another zone number and the library will take care of everything? – Luiz Fernando Salvaterra Dec 11 '19 at 22:48
  • For Latitude, longitude (φ, λ) to UTM coordinates (E, N) you don't declare any zone. For that you'll have to dive into the code and figure it out for yourself. No one will do that for you because the `at least that is how we do it` premise is wrong: when you project a point into a UTM Zone that is not the standard Zone, that will introduce distortions derived from the distance from the Central Meridian of the correct Zone, that's why we have UTM Zones. UTM is a well thought standard. – LuisTavares Dec 11 '19 at 23:05
  • I get this point, but the main question is, to project one UTM location for one zone to another we just have to project the second one using the zone of the new one while using the library? – Luiz Fernando Salvaterra Dec 12 '19 at 21:33
  • Yes, correct. Provide I know the numbering of the adjacent Zones and the Datum to be used, that's feasible. A generic solution for any two adjacent Zones on the globe, it isn't. – LuisTavares Dec 12 '19 at 22:08