Skip to content

Commit a40520a

Browse files
committed
Ready for release 2.0
1 parent e200f6d commit a40520a

File tree

6 files changed

+96
-136
lines changed

6 files changed

+96
-136
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ of how to use the library.
3737
To build the original Mapcode tool, execute:
3838

3939
cd utility
40-
gcc mapcode.cpp -o mapcode
40+
gcc -Wall -O mapcode.cpp -o mapcode
4141

4242
For help, simply execute the binary file 'mapcode' without no arguments.
4343
This tool provides a rather extensive command-line interface to encode and
@@ -48,9 +48,9 @@ decode Mapcodes.
4848

4949
* 2.0
5050

51-
Support for up to 8 character extensions (10 micron accuracy).
51+
Support for high-precision mapcodes, with up to 8 character extensions (up to 10 micron accuracy).
5252

53-
Fixes to the data rectangles for ISO proposal, see Word document for details.
53+
Fixes to the data rectangles (primarily intended for ISO proposal), see Word document for details.
5454

5555
* 1.50.1
5656

mapcode_library_c.doc

34 KB
Binary file not shown.

mapcodelib/basics.h

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
@@ -16,11 +16,11 @@
1616

1717
#define UWORD unsigned short int // 2-byte unsigned integer
1818

19-
#define mapcode_cversion "1.81"
19+
#define mapcode_cversion "1.85"
2020
#define MAXWIDE 10
2121
#define BASEX 31
2222
#define MAXFITLONG 6
23-
#define XSIDE3 168
23+
#define XSIDE3 168
2424
#define YSIDE3 176
2525

2626
#define ALIASES "2UK=2UT,2CG=2CT,1GU=GUM,1UM=UMI,1VI=VIR,1PR=PRI,1AS=ASM,1MP=MNP,4CX=CXR,4CC=CCK,4NF=NFK,4HM=HMD,COL=5CL,5ME=5MX,MEX=5MX,5TM=TAM,5AG=AGU,5BC=BCN,5BS=BCS,5CM=CAM,5CS=CHP,5CH=CHH,5CO=COA,5DF=DIF,5DG=DUR,5GT=GUA,5GR=GRO,5HG=HID,5JA=JAL,5MI=MIC,5MO=MOR,5NA=NAY,5NL=NLE,5OA=OAX,5PB=PUE,5QE=QUE,5QR=ROO,5SL=SLP,5SI=SIN,5SO=SON,5TB=TAB,5TL=TLA,5VE=VER,5YU=YUC,5ZA=ZAC,811=8BJ,812=8TJ,813=8HE,814=8SX,815=8NM,821=8LN,822=8JL,823=8HL,831=8SH,832=8JS,833=8ZJ,834=8AH,835=8FJ,836=8JX,837=8SD,841=8HA,842=8HB,843=8HN,844=8GD,845=8GX,846=8HI,850=8CQ,851=8SC,852=8GZ,853=8YN,854=8XZ,861=8SN,862=8GS,863=8QH,864=8NX,865=8XJ,871=TWN,891=HKG,892=MAC,8TW=TWN,8HK=HKG,8MC=MAC,BEL=7BE,KIR=7KI,PRI=7PO,CHE=7CH,KHM=7KM,PER=7PM,TAM=7TT,0US=USA,0AU=AUS,0RU=RUS,0CN=CHN,TAA=SHN,ASC=SHN,DGA=IOT,WAK=MHL,JTN=UMI,MID=1HI,2OD=2OR,"
@@ -168,59 +168,59 @@ static const char encode_chars[34] = {
168168

169169

170170
static const UWORD data_start[MAX_CCODE+1] = {
171-
0, 3, 6, 10, 14, 17, 19, 20, 31, 32,
172-
34, 36, 38, 43, 45, 48, 52, 59, 63, 65,
173-
67, 71, 73, 81, 87, 95, 97, 132, 139, 149,
174-
151, 153, 156, 161, 173, 181, 188, 190, 192, 197,
175-
200, 207, 212, 214, 216, 220, 222, 229, 235, 239,
176-
243, 246, 250, 252, 281, 283, 290, 292, 297, 317,
177-
325, 329, 333, 335, 340, 348, 353, 364, 368, 373,
178-
377, 386, 400, 404, 409, 413, 429, 435, 440, 448,
179-
456, 472, 476, 480, 487, 498, 535, 539, 565, 571,
180-
589, 601, 637, 703, 738, 777, 789, 798, 826, 842,
181-
876, 892, 926, 962, 991, 1015, 1026, 1081, 1139, 1153,
182-
1215, 1239, 1268, 1336, 1414, 1467, 1546, 1631, 1683, 1758,
183-
1834, 1895, 1937, 1962, 2010, 2053, 2098, 2159, 2245, 2332,
184-
2383, 2446, 2531, 2622, 2707, 2766, 2881, 2984, 3077, 3161,
185-
3259, 3321, 3425, 3491, 3586, 3682, 3768, 3856, 3946, 4053,
186-
4199, 4301, 4405, 4436, 4473, 4550, 4586, 4620, 4656, 4708,
187-
4772, 4823, 4838, 4873, 5020, 5106, 5156, 5232, 5257, 5325,
188-
5382, 5417, 5499, 5550, 5623, 5716, 5751, 5829, 5888, 5954,
189-
6011, 6064, 6121, 6158, 6249, 6380, 6430, 6460, 6512, 6608,
190-
6641, 6722, 6770, 6850, 6893, 6987, 7021, 7066, 7173, 7177,
191-
7249, 7293, 7379, 7419, 7446, 7503, 7589, 7663, 7702, 7789,
192-
7865, 7973, 8051, 8125, 8195, 8252, 8334, 8416, 8475, 8502,
193-
8540, 8594, 8670, 8783, 8863, 8927, 8984, 9038, 9118, 9189,
194-
9275, 9325, 9389, 9533, 9537, 9542, 9547, 9552, 9558, 9563,
195-
9571, 9579, 9590, 9598, 9613, 9622, 9633, 9666, 9675, 9683,
196-
9698, 9708, 9718, 9726, 9734, 9750, 9758, 9768, 9779, 9789,
197-
9799, 9808, 9817, 9828, 9869, 9910, 9928, 10025, 10176, 10267,
198-
10349, 10544, 10547, 10550, 10553, 10563, 10568, 10571, 10583, 10596,
199-
10607, 10623, 10632, 10638, 10672, 10700, 10719, 10787, 10879, 10894,
200-
10898, 10934, 11021, 11032, 11050, 11067, 11131, 11163, 11204, 11224,
201-
11329, 11409, 11473, 11527, 11586, 11642, 11702, 11709, 11751, 11755,
202-
11758, 11768, 11783, 11794, 11832, 11895, 11941, 11946, 11953, 11958,
203-
11977, 11987, 11994, 12002, 12016, 12032, 12039, 12047, 12056, 12104,
204-
12113, 12124, 12174, 12185, 12195, 12214, 12230, 12243, 12255, 12274,
205-
12308, 12317, 12329, 12341, 12345, 12351, 12357, 12369, 12380, 12389,
206-
12395, 12409, 12429, 12440, 12482, 12533, 12583, 12639, 12652, 12665,
207-
12728, 12788, 12849, 12914, 12985, 13050, 13119, 13194, 13262, 13341,
208-
13418, 13432, 13447, 13492, 13505, 13533, 13547, 13560, 13576, 13592,
209-
13604, 13646, 13658, 13669, 13704, 13719, 13731, 13748, 13756, 13794,
210-
13807, 13822, 13942, 13988, 14032, 14072, 14096, 14137, 14176, 14196,
211-
14212, 14230, 14242, 14256, 14264, 14275, 14292, 14305, 14360, 14361,
212-
14362, 14363, 14403, 14409, 14414, 14419, 14424, 14430, 14437, 14443,
213-
14452, 14458, 14466, 14472, 14479, 14488, 14496, 14505, 14517, 14526,
214-
14534, 14545, 14556, 14565, 14575, 14582, 14632, 14666, 14675, 14687,
215-
14698, 14737, 14748, 14762, 14779, 14791, 14804, 14818, 14833, 14846,
216-
14867, 14875, 14894, 14903, 14915, 14926, 14940, 14955, 14968, 14982,
217-
14995, 15009, 15024, 15042, 15062, 15074, 15094, 15107, 15122, 15136,
218-
15154, 15170, 15184, 15197, 15214, 15234, 15251, 15269, 15284, 15298,
219-
15314, 15325, 15341, 15354, 15369, 15384, 15430, 15444, 15453, 15463,
220-
15476, 15490, 15501, 15514, 15530, 15545, 15546, 15573, 15579, 15587,
221-
15593, 15609, 15646, 15663, 15687, 15710, 15727, 15747, 15773, 15799,
222-
15818, 15835, 15888, 15929, 15951, 15978, 15998, 16019, 16037, 16068,
223-
16094, 16114, 16135, 16153, 16171, 16190, 16206, 16222, 16276, 16302,
171+
0, 3, 6, 10, 14, 17, 19, 20, 31, 32,
172+
34, 36, 38, 43, 45, 48, 52, 59, 63, 65,
173+
67, 71, 73, 81, 87, 95, 97, 132, 139, 149,
174+
151, 153, 156, 161, 173, 181, 188, 190, 192, 197,
175+
200, 207, 212, 214, 216, 220, 222, 229, 235, 239,
176+
243, 246, 250, 252, 281, 283, 290, 292, 297, 317,
177+
325, 329, 333, 335, 340, 348, 353, 364, 368, 373,
178+
377, 386, 400, 404, 409, 413, 429, 435, 440, 448,
179+
456, 472, 476, 480, 487, 498, 535, 539, 565, 571,
180+
589, 601, 637, 703, 738, 777, 789, 798, 826, 842,
181+
876, 892, 926, 962, 991, 1015, 1026, 1081, 1139, 1153,
182+
1215, 1239, 1268, 1336, 1414, 1467, 1546, 1631, 1683, 1758,
183+
1834, 1895, 1937, 1962, 2010, 2053, 2098, 2159, 2245, 2332,
184+
2383, 2446, 2531, 2622, 2707, 2766, 2881, 2984, 3077, 3161,
185+
3259, 3321, 3425, 3491, 3586, 3682, 3768, 3856, 3946, 4053,
186+
4199, 4301, 4405, 4436, 4473, 4550, 4586, 4620, 4656, 4708,
187+
4772, 4823, 4838, 4873, 5020, 5106, 5156, 5232, 5257, 5325,
188+
5382, 5417, 5499, 5550, 5623, 5716, 5751, 5829, 5888, 5954,
189+
6011, 6064, 6121, 6158, 6249, 6380, 6430, 6460, 6512, 6608,
190+
6641, 6722, 6770, 6850, 6893, 6987, 7021, 7066, 7173, 7177,
191+
7249, 7293, 7379, 7419, 7446, 7503, 7589, 7663, 7702, 7789,
192+
7865, 7973, 8051, 8125, 8195, 8252, 8334, 8416, 8475, 8502,
193+
8540, 8594, 8670, 8783, 8863, 8927, 8984, 9038, 9118, 9189,
194+
9275, 9325, 9389, 9533, 9537, 9542, 9547, 9552, 9558, 9563,
195+
9571, 9579, 9590, 9598, 9613, 9622, 9633, 9666, 9675, 9683,
196+
9698, 9708, 9718, 9726, 9734, 9750, 9758, 9768, 9779, 9789,
197+
9799, 9808, 9817, 9828, 9869, 9910, 9928, 10025, 10176, 10267,
198+
10349, 10544, 10547, 10550, 10553, 10563, 10568, 10571, 10583, 10596,
199+
10607, 10623, 10632, 10638, 10672, 10700, 10719, 10787, 10879, 10894,
200+
10898, 10934, 11021, 11032, 11050, 11067, 11131, 11163, 11204, 11224,
201+
11329, 11409, 11473, 11527, 11586, 11642, 11702, 11709, 11751, 11755,
202+
11758, 11768, 11783, 11794, 11832, 11895, 11941, 11946, 11953, 11958,
203+
11977, 11987, 11994, 12002, 12016, 12032, 12039, 12047, 12056, 12104,
204+
12113, 12124, 12174, 12185, 12195, 12214, 12230, 12243, 12255, 12274,
205+
12308, 12317, 12329, 12341, 12345, 12351, 12357, 12369, 12380, 12389,
206+
12395, 12409, 12429, 12440, 12482, 12533, 12583, 12639, 12652, 12665,
207+
12728, 12788, 12849, 12914, 12985, 13050, 13119, 13194, 13262, 13341,
208+
13418, 13432, 13447, 13492, 13505, 13533, 13547, 13560, 13576, 13592,
209+
13604, 13646, 13658, 13669, 13704, 13719, 13731, 13748, 13756, 13794,
210+
13807, 13822, 13942, 13988, 14032, 14072, 14096, 14137, 14176, 14196,
211+
14212, 14230, 14242, 14256, 14264, 14275, 14292, 14305, 14360, 14361,
212+
14362, 14363, 14403, 14409, 14414, 14419, 14424, 14430, 14437, 14443,
213+
14452, 14458, 14466, 14472, 14479, 14488, 14496, 14505, 14517, 14526,
214+
14534, 14545, 14556, 14565, 14575, 14582, 14632, 14666, 14675, 14687,
215+
14698, 14737, 14748, 14762, 14779, 14791, 14804, 14818, 14833, 14846,
216+
14867, 14875, 14894, 14903, 14915, 14926, 14940, 14955, 14968, 14982,
217+
14995, 15009, 15024, 15042, 15062, 15074, 15094, 15107, 15122, 15136,
218+
15154, 15170, 15184, 15197, 15214, 15234, 15251, 15269, 15284, 15298,
219+
15314, 15325, 15341, 15354, 15369, 15384, 15430, 15444, 15453, 15463,
220+
15476, 15490, 15501, 15514, 15530, 15545, 15546, 15573, 15579, 15587,
221+
15593, 15609, 15646, 15663, 15687, 15710, 15727, 15747, 15773, 15799,
222+
15818, 15835, 15888, 15929, 15951, 15978, 15998, 16019, 16037, 16068,
223+
16094, 16114, 16135, 16153, 16171, 16190, 16206, 16222, 16276, 16302,
224224
16309, 16311, 16312, 16344
225225
};
226226

@@ -14634,7 +14634,7 @@ static const mminforec mminfo[NR_RECS+1] = {
1463414634
{-95321564, 16074172, -92551001, 18755362, 0x0a9e891},
1463514635
{-94351867, 14531918, -91611095, 17213108, 0x0a9f091},
1463614636
{-118403860, 14531918, -86600000, 32719000, 0x0010217},
14637-
{37538141, 55705730, 37690940, 55792220, 0x001000a},
14637+
{37538581, 55705755, 37691380, 55792245, 0x001000a},
1463814638
{37174200, 55508961, 37975000, 56000000, 0x001000c},
1463914639
{37159175, 55614980, 37987247, 56106020, 0x001688c},
1464014640
{37166258, 55123940, 37983914, 55614980, 0x001b08c},

mapcodelib/mapcoder.c

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
#include <stdlib.h> // atof
1919
#include <ctype.h> // toupper
2020
#include "mapcoder.h"
21-
22-
#undef SUPPORT_HIGH_PRECISION
23-
24-
/*
25-
no threadsafe:
26-
disambiguate_iso3
27-
*/
28-
29-
30-
#ifndef RELEASENEAT
31-
#else
32-
3321
#include "basics.h"
3422

3523
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -148,7 +136,6 @@ static const char *get_entity_iso3(char *entity_iso3_result,int ccode)
148136
return entity_iso3_result;
149137
}
150138

151-
// static char disambiguate_iso3[4] = { '1','?','?',0 } ; // cache for disambiguation
152139
static int disambiguate_str( const char *s, int len ) // returns disambiguation >=1, or negative if error
153140
{
154141
int res;
@@ -1039,9 +1026,6 @@ static int stateletter(int ccode) // parent
10391026
}
10401027

10411028

1042-
1043-
1044-
10451029
// returns -1 (error), or m (also returns *result!=0 in case of success)
10461030
static int encodeNameless( char *result, const encodeRec* enc, int input_ctry, int codexm, int extraDigits, int m )
10471031
{
@@ -1417,6 +1401,11 @@ static void encoderEngine( int ccode, const encodeRec *enc, int stop_with_one_re
14171401
}
14181402

14191403

1404+
1405+
1406+
1407+
1408+
14201409
// returns nonzero if error
14211410
static int decoderEngine( decodeRec *dec )
14221411
{
@@ -1668,7 +1657,6 @@ static int decoderEngine( decodeRec *dec )
16681657
}
16691658

16701659

1671-
16721660
#ifdef SUPPORT_FOREIGN_ALPHABETS
16731661

16741662
// WARNING - these alphabets have NOT yet been released as standard! use at your own risk! check www.mapcode.com for details.
@@ -1949,21 +1937,15 @@ static int encodeLatLonToMapcodes_internal( char **v, Mapcodes *mapcodes, double
19491937
}
19501938

19511939

1952-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1953-
//
1954-
// Wrapper for LBS team
1955-
//
1956-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1957-
19581940
// threadsafe
1959-
char* getTerritoryIsoName(char *result, int tc, int format) // formats: 0=full 1=short (returns empty string in case of error)
1941+
char* getTerritoryIsoName(char *result, int territoryCode, int format) // formats: 0=full 1=short (returns empty string in case of error)
19601942
{
1961-
if (tc<1 || tc>MAX_MAPCODE_TERRITORY_CODE)
1943+
if (territoryCode<1 || territoryCode>MAX_MAPCODE_TERRITORY_CODE)
19621944
*result=0;
19631945
else {
1964-
int p=stateletter(tc-1);
1946+
int p=stateletter(territoryCode-1);
19651947
char iso3[4];
1966-
const char *ei = get_entity_iso3(iso3,tc-1);
1948+
const char *ei = get_entity_iso3(iso3,territoryCode-1);
19671949
if (*ei>='0' && *ei<='9') ei++;
19681950
if (format==0 && p)
19691951
{
@@ -1980,7 +1962,6 @@ char* getTerritoryIsoName(char *result, int tc, int format) // formats: 0=full 1
19801962
}
19811963

19821964

1983-
19841965
int getParentCountryOf(int tc) // returns negative if tc is not a code that has a parent country
19851966
{
19861967
int parentccode=ParentTerritoryOf(tc-1); // returns parent ccode or -1
@@ -2022,7 +2003,6 @@ int convertTerritoryIsoNameToCode(const char *string,int optional_tc) // optiona
20222003
}
20232004

20242005

2025-
20262006
// decode string into lat,lon; returns negative in case of error
20272007
int decodeMapcodeToLatLon( double *lat, double *lon, const char *input, int context_tc ) // context_tc is used to disambiguate ambiguous short mapcode inputs; pass 0 or negative if not available
20282008
{
@@ -2066,21 +2046,20 @@ UWORD* convertToAlphabet(UWORD* unibuf, int maxlength, const char *mapcode,int a
20662046
}
20672047

20682048

2049+
// Legacy: NOT threadsafe
20692050
static char asciibuf[MAX_MAPCODE_RESULT_LEN];
20702051
const char *decodeToRoman(const UWORD* s)
20712052
{
20722053
return convertToRoman(asciibuf,MAX_MAPCODE_RESULT_LEN,s);
20732054
}
20742055

2056+
// Legacy: NOT threadsafe
20752057
static UWORD unibuf[MAX_MAPCODE_RESULT_LEN];
20762058
const UWORD* encodeToAlphabet(const char *mapcode,int alphabet) // 0=roman, 2=cyrillic
20772059
{
20782060
return convertToAlphabet(unibuf,MAX_MAPCODE_RESULT_LEN,mapcode,alphabet);
20792061
}
20802062

2081-
2082-
2083-
20842063
#endif
20852064

20862065
int encodeLatLonToSingleMapcode( char *result, double lat, double lon, int tc, int extraDigits )
@@ -2100,17 +2079,17 @@ int encodeLatLonToSingleMapcode( char *result, double lat, double lon, int tc, i
21002079
return 1;
21012080
}
21022081

2103-
// encodeLatLonToMapcodes is not threadsafe!
2104-
int encodeLatLon( Mapcodes *results, double lat, double lon, int tc, int extraDigits )
2082+
// Threadsafe
2083+
int encodeLatLonToMapcodes( Mapcodes *results, double lat, double lon, int territoryCode, int extraDigits )
21052084
{
2106-
return encodeLatLonToMapcodes_internal(NULL,results,lat,lon,tc,0,extraDigits);
2085+
return encodeLatLonToMapcodes_internal(NULL,results,lat,lon,territoryCode,0,extraDigits);
21072086
}
21082087

21092088
// Legacy: NOT threadsafe
21102089
Mapcodes rglobal;
2111-
int encodeLatLonToMapcodes( char **v, double lat, double lon, int tc, int extraDigits )
2090+
int encodeLatLonToMapcodes_Deprecated( char **v, double lat, double lon, int territoryCode, int extraDigits )
21122091
{
2113-
return encodeLatLonToMapcodes_internal(v,&rglobal,lat,lon,tc,0,extraDigits);
2092+
return encodeLatLonToMapcodes_internal(v,&rglobal,lat,lon,territoryCode,0,extraDigits);
21142093
}
21152094

21162095
// Legacy: NOT threadsafe
@@ -2121,6 +2100,3 @@ const char *convertTerritoryCodeToIsoName(int tc,int format)
21212100
if (makeiso_buf==makeiso_bufbytes) makeiso_buf=makeiso_bufbytes+8; else makeiso_buf=makeiso_bufbytes;
21222101
return (const char*)getTerritoryIsoName(makeiso_buf,tc,format);
21232102
}
2124-
2125-
2126-
#endif // RELEASENEAT

0 commit comments

Comments
 (0)