-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathS57gv.c
177 lines (126 loc) · 4.92 KB
/
S57gv.c
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// S57gv.c: OpenEV (GV) S57 geo data
//
// Project: OpENCview/OpenEV
/*
This file is part of the OpENCview project, a viewer of ENC.
Copyright (C) 2000-2018 Sylvain Duclos [email protected]
OpENCview is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpENCview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with OpENCview. If not, see <http://www.gnu.org/licenses/>.
*/
// Note: use the actual data of GV (witch is a copy of OGR data)
#include "S57gv.h"
#include "S57data.h" // S57_geo
#include "S52utils.h" // PRINTF()
#include "gvproperties.h" // gv_properties_*()
#include "gvshapes.h" // GvShapes, GvShape, gv_shape_get_extents()
#include "gvshapeslayer.h" // GvShapesLayer,
// this is more 'computed and get' then a getter
#define gv_shape_compute_extents gv_shape_get_extents
typedef struct GvShape _srcData;
static int _loadAtt(S57_geo *geo, GvShape *shape)
{
GvProperties *props = gv_shape_get_properties(shape);
int nProp = gv_properties_count(props);
for (int i=0; i<nProp; ++i) {
const char *propName = gv_properties_get_name_by_index (props, i);
const char *propValue = gv_properties_get_value_by_index(props, i);
if (NULL == propValue) {
PRINTF("gv_properties_value = null \n");
g_assert(0);
return FALSE;
}
S57_setAtt(geo, propName, propValue);
}
return TRUE;
}
int S57_gvLoadCell (const char *filename, S52_loadLayer_cb cb)
{
GvData *raw_data = NULL;
int i = 0;
// call 'cb' for each layer
while (NULL != (raw_data = gv_shapes_from_ogr(filename, i))) {
cb(filename, raw_data);
++i;
}
return TRUE;
}
//int S57_gvLoadLayer(const char *layername, GvShapesLayer *layer, _loadObj_cb cb)
int S57_gvLoadLayer(const char *layername, void *layer, S52_loadObj_cb cb)
{
GvShapesLayer *l = (GvShapesLayer*) layer;
int nShapes = gv_shapes_num_shapes(l->data);
// check that geometric data type are in sync with OpenGL
g_assert(sizeof(geocoord) == sizeof(double));
for (int i=0; i<nShapes; ++i) {
GvShape *shape = gv_shapes_get_shape(GV_SHAPES_LAYER(layer)->data, i);
cb(layername, shape);
}
return TRUE;
}
S57_geo *S57_gvLoadObject(const char *objname, void *shape)
// get object geo data from openev GvShape
// Note: caller responsible to free mem for the moment
{
S57_geo *geo = NULL;
int shapetype = 0;
GvRect rect;
// return empty shape --for pick & Mariners' object
if (NULL==shape) {
geo = S57_set_META();
if (NULL != objname)
S57_setName(geo, objname);
return geo;
}
gv_shape_compute_extents((GvShape*)shape, &rect);
// mariners' object
shapetype = gv_shape_type((GvShape*)shape);
// get geo data
switch (shapetype) {
case GVSHAPE_POINT: {
GvPointShape *point = (GvPointShape *) shape;
geocoord *pt = &point->x;
geo = S57_setPOINT(pt);
break;
}
case GVSHAPE_LINE: {
GvLineShape *line = (GvLineShape *) shape;
geo = S57_setLINES(line->num_nodes, line->xyz_nodes);
break;
}
case GVSHAPE_AREA: {
// FIXME: check if winding is OK (at load time)
GvAreaShape *area = (GvAreaShape *) shape;
geo = S57_setAREAS((guint)area->num_rings, (guint*)area->num_ring_nodes, area->xyz_ring_nodes, S57_AW_NONE);
break;
}
case GVSHAPE_COLLECTION: {
// ogr SPLIT_MULTIPOINT prob !!
//GvCollectionShape *collection = (GvCollectionShape *) shape;
//int nCollection = gv_shape_collection_get_count(shape);
//PRINTF("nCollection = %i\n", nCollection);
PRINTF("FIXME: wkbMultiLineString found ???\n");
g_assert_not_reached(); // MultiLineString (need this for line removal)
geo = S57_set_META();
break;
}
default: {
// FIXME: find a decent default (see openev/gvshapes.h)!!!
PRINTF("WARNING: invalid object type GVSHAPE_??? = %i\n", shapetype);
g_assert(0);
}
}
S57_setName(geo, objname);
S57_setGeoExt(geo, rect.x, rect.y, rect.x+rect.width, rect.y+rect.height);
_loadAtt(geo, (GvShape*)shape);
// debug
//_dumpData(geo);
return geo;
}