-
Notifications
You must be signed in to change notification settings - Fork 7
/
sosi.cpp
152 lines (127 loc) · 5.52 KB
/
sosi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <string.h>
#include "sosi2osm.h"
LC_BASEADM* base = NULL;
LC_FILADM* fileadm = NULL;
int openSOSI(const char* input_filename) {
LC_Init();
// Is this a valid file
UT_INT64 end = 0;
if (HO_TestSOSI(input_filename, &end) == UT_FALSE) {
fprintf(stderr, "Not a SOSI file: %s\n", input_filename);
return 0;
}
// Open the file for reading
LC_BASEADM* base = LC_OpenBase(LC_BASE);
LC_FILADM* fileadm;
short status = 0;
LC_OpenSos(input_filename, LC_BASE_FRAMGR, LC_GML_IDX, LC_VIS_STATUS, &fileadm, &status);
if (status != 0) {
fprintf(stderr, "Could not open SOSI file: %s (%d)\n", input_filename, status);
return 0;
}
return 1;
}
void closeSOSI() {
if (fileadm) LC_CloseSos(fileadm, RESET_IDX);
if (base) LC_CloseBase(base, RESET_IDX);
LC_Close();
}
LC_BGR group = {NULL, 0};
int nextSOSIObject() {
if (group.pFil == NULL) {
LC_InitNextBgr(&group);
}
if (LC_NextBgr(&group, LC_FRAMGR | LC_BAKGR)) {
short lines;
long coordinates;
unsigned short info;
LC_RxGr(&group, LES_OPTIMALT, &lines, &coordinates, &info);
return 1;
}
return 0;
}
short getSOSIType() {
short lines;
long coordinates;
unsigned short info;
return LC_GetGrPara(&lines, &coordinates, &info);
}
long getSOSIId() {
return LC_GetSn();
}
const char* getCoordinateSystem() {
unsigned short mask = LC_TR_ALLT;
LC_TRANSPAR trans;
if (LC_GetTransEx(&mask,&trans) == UT_FALSE) {
fprintf(stderr, "TRANSPAR section not found - No reference system information available.");
return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
}
switch (trans.sKoordsys) {
/* NGO 1984 Axis I-VIII */
case 1: return "+proj=tmerc +lat_0=58 +lon_0=-4.666666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 2: return "+proj=tmerc +lat_0=58 +lon_0=-2.333333333333333 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 3: return "+proj=tmerc +lat_0=58 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 4: return "+proj=tmerc +lat_0=58 +lon_0=2.5 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 5: return "+proj=tmerc +lat_0=58 +lon_0=6.166666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 6: return "+proj=tmerc +lat_0=58 +lon_0=10.16666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 7: return "+proj=tmerc +lat_0=58 +lon_0=14.16666666666667 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
case 8: return "+proj=tmerc +lat_0=58 +lon_0=18.33333333333333 +k=1 +x_0=0 +y_0=0 +a=6377492.018 +b=6356173.508712696 +towgs84=278.3,93,474.5,7.889,0.05,-6.61,6.21 +pm=oslo +units=m +no_defs ";
/* UTM ZONE 31-36 */
case 21: return "+proj=utm +zone=31 +ellps=GRS80 +units=m +no_defs ";
case 22: return "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs ";
case 23: return "+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs ";
case 24: return "+proj=utm +zone=34 +ellps=GRS80 +units=m +no_defs ";
case 25: return "+proj=utm +zone=35 +ellps=GRS80 +units=m +no_defs ";
case 26: return "+proj=utm +zone=36 +ellps=GRS80 +units=m +no_defs ";
/* UTM ZONE 31-36 / ED50 */
case 31: return "+proj=utm +zone=31 +ellps=intl +units=m +no_defs ";
case 32: return "+proj=utm +zone=32 +ellps=intl +units=m +no_defs ";
case 33: return "+proj=utm +zone=33 +ellps=intl +units=m +no_defs ";
case 34: return "+proj=utm +zone=34 +ellps=intl +units=m +no_defs ";
case 35: return "+proj=utm +zone=35 +ellps=intl +units=m +no_defs ";
case 36: return "+proj=utm +zone=36 +ellps=intl +units=m +no_defs ";
/* WSG84 */
case 84: return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
default: {
fprintf(stderr, "(Yet) unsupported coodinate system in SOSI-file: %i. Defaulting to EPSG:4326.", trans.sKoordsys);
return "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ";
}
}
}
void getSOSICoord(long i, double* x, double* y) {
LC_GetTK(i+1, x, y);
}
long getSOSICoordsSize() {
short lines;
long coordinates;
unsigned short info;
LC_GetGrPara(&lines, &coordinates, &info);
return coordinates;
}
char* getSOSILine(long i) {
char* r = LC_GetGi(i+1);
if (r[0] == ':' || r[0] == '(' || r[0] == '!')
return NULL;
char* tmp = r;
while (tmp[0] == '.') tmp++;
if (strncmp(tmp, "REF", 3) == 0)
return NULL;
return r;
}
long getSOSILinesLength() {
short lines;
long coordinates;
unsigned short info;
LC_GetGrPara(&lines, &coordinates, &info);
return lines;
}
long* getSOSIRefs() {
long size = LC_InqAntRef();
long* ret = (long*)malloc(sizeof(long) * size);
short line = 1, pos = 1;
LC_GetRef(ret, size, &line, &pos);
return ret;
}
long getSOSIRefsSize() {
return LC_InqAntRef();
}