@@ -112,74 +112,74 @@ internal class UTMCoordConverter {
112112 *
113113 * @return error code
114114 */
115- fun convertGeodeticToUTM (Latitude : Double , Longitude : Double ): Long {
116- var Longitude = Longitude
117- val Lat_Degrees : Long
118- val Long_Degrees : Long
119- var temp_zone : Long
120- var Error_Code = UTM_NO_ERROR .toLong()
121- val Origin_Latitude = 0.0
122- val False_Easting = 500000.0
123- var False_Northing = 0.0
124- val Scale = 0.9996
115+ fun convertGeodeticToUTM (latitude : Double , longitude : Double ): Long {
116+ var lon = longitude
117+ val latDegrees : Long
118+ val longDegrees : Long
119+ var tempZone : Long
120+ var errorCode = UTM_NO_ERROR .toLong()
121+ val originLatitude = 0.0
122+ val falseEasting = 500000.0
123+ var falseNorthing = 0.0
124+ val scale = 0.9996
125125
126- if ((Latitude < MIN_LAT ) || (Latitude > MAX_LAT )) { /* Latitude out of range */
127- Error_Code = Error_Code or UTM_LAT_ERROR .toLong()
126+ if ((latitude < MIN_LAT ) || (latitude > MAX_LAT )) { /* Latitude out of range */
127+ errorCode = errorCode or UTM_LAT_ERROR .toLong()
128128 }
129- if ((Longitude < - PI ) || (Longitude > (2 * PI ))) { /* Longitude out of range */
130- Error_Code = Error_Code or UTM_LON_ERROR .toLong()
129+ if ((lon < - PI ) || (lon > (2 * PI ))) { /* Longitude out of range */
130+ errorCode = errorCode or UTM_LON_ERROR .toLong()
131131 }
132- if (Error_Code == UTM_NO_ERROR .toLong()) { /* no errors */
133- if (Longitude < 0 ) Longitude + = (2 * PI ) + 1 .0e- 10
134- Lat_Degrees = (Latitude * 180.0 / PI ).toLong()
135- Long_Degrees = (Longitude * 180.0 / PI ).toLong()
132+ if (errorCode == UTM_NO_ERROR .toLong()) { /* no errors */
133+ if (lon < 0 ) lon + = (2 * PI ) + 1 .0e- 10
134+ latDegrees = (latitude * 180.0 / PI ).toLong()
135+ longDegrees = (lon * 180.0 / PI ).toLong()
136136
137- if (Longitude < PI ) temp_zone = (31 + ((Longitude * 180.0 / PI ) / 6.0 )).toLong()
138- else temp_zone = (((Longitude * 180.0 / PI ) / 6.0 ) - 29 ).toLong()
139- if (temp_zone > 60 ) temp_zone = 1
137+ tempZone = if (lon < PI ) (31 + ((lon * 180.0 / PI ) / 6.0 )).toLong()
138+ else (((lon * 180.0 / PI ) / 6.0 ) - 29 ).toLong()
139+ if (tempZone > 60 ) tempZone = 1
140140 /* UTM special cases */
141- if ((Lat_Degrees > 55 ) && (Lat_Degrees < 64 ) && (Long_Degrees > - 1 ) && (Long_Degrees < 3 )) temp_zone = 31
142- if ((Lat_Degrees > 55 ) && (Lat_Degrees < 64 ) && (Long_Degrees > 2 ) && (Long_Degrees < 12 )) temp_zone = 32
143- if ((Lat_Degrees > 71 ) && (Long_Degrees > - 1 ) && (Long_Degrees < 9 )) temp_zone = 31
144- if ((Lat_Degrees > 71 ) && (Long_Degrees > 8 ) && (Long_Degrees < 21 )) temp_zone = 33
145- if ((Lat_Degrees > 71 ) && (Long_Degrees > 20 ) && (Long_Degrees < 33 )) temp_zone = 35
146- if ((Lat_Degrees > 71 ) && (Long_Degrees > 32 ) && (Long_Degrees < 42 )) temp_zone = 37
141+ if ((latDegrees > 55 ) && (latDegrees < 64 ) && (longDegrees > - 1 ) && (longDegrees < 3 )) tempZone = 31
142+ if ((latDegrees > 55 ) && (latDegrees < 64 ) && (longDegrees > 2 ) && (longDegrees < 12 )) tempZone = 32
143+ if ((latDegrees > 71 ) && (longDegrees > - 1 ) && (longDegrees < 9 )) tempZone = 31
144+ if ((latDegrees > 71 ) && (longDegrees > 8 ) && (longDegrees < 21 )) tempZone = 33
145+ if ((latDegrees > 71 ) && (longDegrees > 20 ) && (longDegrees < 33 )) tempZone = 35
146+ if ((latDegrees > 71 ) && (longDegrees > 32 ) && (longDegrees < 42 )) tempZone = 37
147147
148148 if (UTM_Override != 0L ) {
149- if ((temp_zone == 1L ) && (UTM_Override == 60L )) temp_zone = UTM_Override
150- else if ((temp_zone == 60L ) && (UTM_Override == 1L )) temp_zone = UTM_Override
151- else if (((temp_zone - 1 ) <= UTM_Override ) && (UTM_Override <= (temp_zone + 1 ))) temp_zone =
149+ if ((tempZone == 1L ) && (UTM_Override == 60L )) tempZone = UTM_Override
150+ else if ((tempZone == 60L ) && (UTM_Override == 1L )) tempZone = UTM_Override
151+ else if (((tempZone - 1 ) <= UTM_Override ) && (UTM_Override <= (tempZone + 1 ))) tempZone =
152152 UTM_Override
153- else Error_Code = UTM_ZONE_OVERRIDE_ERROR .toLong()
153+ else errorCode = UTM_ZONE_OVERRIDE_ERROR .toLong()
154154 }
155- if (Error_Code == UTM_NO_ERROR .toLong()) {
156- if (temp_zone >= 31 ) this .centralMeridian = (6 * temp_zone - 183 ) * PI / 180.0
157- else this .centralMeridian = (6 * temp_zone + 177 ) * PI / 180.0
158- this .zone = temp_zone .toInt()
159- if (Latitude < 0 ) {
160- False_Northing = 10000000.0
155+ if (errorCode == UTM_NO_ERROR .toLong()) {
156+ if (tempZone >= 31 ) this .centralMeridian = (6 * tempZone - 183 ) * PI / 180.0
157+ else this .centralMeridian = (6 * tempZone + 177 ) * PI / 180.0
158+ this .zone = tempZone .toInt()
159+ if (latitude < 0 ) {
160+ falseNorthing = 10000000.0
161161 this .hemisphere = AVKey .SOUTH
162162 } else this .hemisphere = AVKey .NORTH
163163
164164 try {
165165 val TM = fromLatLon(
166- Angle .fromRadians(Latitude ), Angle .fromRadians(Longitude ),
167- this .UTM_a , this .UTM_f , Angle .fromRadians(Origin_Latitude ),
168- Angle .fromRadians(this .centralMeridian), False_Easting , False_Northing , Scale
166+ Angle .fromRadians(latitude ), Angle .fromRadians(lon ),
167+ this .UTM_a , this .UTM_f , Angle .fromRadians(originLatitude ),
168+ Angle .fromRadians(this .centralMeridian), falseEasting, falseNorthing, scale
169169 )
170170 this .easting = TM .easting
171171 this .northing = TM .northing
172172
173- if ((this .easting < MIN_EASTING ) || (this .easting > MAX_EASTING )) Error_Code =
173+ if ((this .easting < MIN_EASTING ) || (this .easting > MAX_EASTING )) errorCode =
174174 UTM_EASTING_ERROR .toLong()
175- if ((this .northing < MIN_NORTHING ) || (this .northing > MAX_NORTHING )) Error_Code =
176- Error_Code or UTM_NORTHING_ERROR .toLong()
175+ if ((this .northing < MIN_NORTHING ) || (this .northing > MAX_NORTHING )) errorCode =
176+ errorCode or UTM_NORTHING_ERROR .toLong()
177177 } catch (e: Exception ) {
178- Error_Code = UTM_TM_ERROR .toLong()
178+ errorCode = UTM_TM_ERROR .toLong()
179179 }
180180 }
181181 }
182- return (Error_Code )
182+ return (errorCode )
183183 }
184184
185185 /* *
0 commit comments