MCPcopy Create free account
hub / github.com/comaps/comaps / Get100kId

Function Get100kId

libs/platform/utm_mgrs_utils.cpp:157–210  ·  view source on GitHub ↗

Build 2 chars string with MGRS 100k designator.

Source from the content-addressed store, hash-verified

155
156// Build 2 chars string with MGRS 100k designator.
157std::string Get100kId(double easting, double northing, int zoneNumber)
158{
159 int const set = zoneNumber % kSetOriginColumnLetters.size();
160 int const setColumn = easting / 100000;
161 int const setRow = static_cast<int>(northing / 100000) % 20;
162
163 int const colOrigin = kSetOriginColumnLetters[set];
164 int const rowOrigin = kSetOriginRowLetters[set];
165
166 int colInt = colOrigin + setColumn - 1;
167 int rowInt = rowOrigin + setRow;
168 bool rollover = false;
169
170 if (colInt > 'Z')
171 {
172 colInt = colInt - 'Z' + 'A' - 1;
173 rollover = true;
174 }
175
176 if (colInt == 'I' || (colOrigin < 'I' && colInt > 'I') || ((colInt > 'I' || colOrigin < 'I') && rollover))
177 colInt++;
178 if (colInt == 'O' || (colOrigin < 'O' && colInt > 'O') || ((colInt > 'O' || colOrigin < 'O') && rollover))
179 {
180 colInt++;
181 if (colInt == 'I')
182 colInt++;
183 }
184
185 if (colInt > 'Z')
186 colInt = colInt - 'Z' + 'A' - 1;
187
188 if (rowInt > 'V')
189 {
190 rowInt = rowInt - 'V' + 'A' - 1;
191 rollover = true;
192 }
193 else
194 rollover = false;
195
196 if (rowInt == 'I' || (rowOrigin < 'I' && rowInt > 'I') || ((rowInt > 'I' || rowOrigin < 'I') && rollover))
197 rowInt++;
198
199 if (rowInt == 'O' || (rowOrigin < 'O' && rowInt > 'O') || ((rowInt > 'O' || rowOrigin < 'O') && rollover))
200 {
201 rowInt++;
202 if (rowInt == 'I')
203 rowInt++;
204 }
205
206 if (rowInt > 'V')
207 rowInt = rowInt - 'V' + 'A' - 1;
208
209 return {static_cast<char>(colInt), static_cast<char>(rowInt)};
210}
211
212// Convert UTM point parameters to MGRS parameters. Additional 2 char code is deducted.
213// Easting and northing parameters are reduced to 5 digits.

Callers 1

UTMtoMgrsStrFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected