48#include "gdal/ogr_api.h"
49#include "gdal/cpl_conv.h"
50#include "gdal/cpl_string.h"
56OGRFeatureDefn *S57GenerateGeomFeatureDefn(OGRwkbGeometryType eGType,
60 OGRFeatureDefn *poFDefn = NULL;
62 if (eGType == wkbPoint) {
63 poFDefn =
new OGRFeatureDefn(
"Point");
64 poFDefn->SetGeomType(eGType);
65 }
else if (eGType == wkbLineString) {
66 poFDefn =
new OGRFeatureDefn(
"Line");
67 poFDefn->SetGeomType(eGType);
68 }
else if (eGType == wkbPolygon) {
69 poFDefn =
new OGRFeatureDefn(
"Area");
70 poFDefn->SetGeomType(eGType);
71 }
else if (eGType == wkbNone) {
72 poFDefn =
new OGRFeatureDefn(
"Meta");
73 poFDefn->SetGeomType(eGType);
74 }
else if (eGType == wkbUnknown) {
75 poFDefn =
new OGRFeatureDefn(
"Generic");
76 poFDefn->SetGeomType(eGType);
80 S57GenerateStandardAttributes(poFDefn, nOptionFlags);
89OGRFeatureDefn *S57GenerateVectorPrimitiveFeatureDefn(
int nRCNM,
93 OGRFeatureDefn *poFDefn = NULL;
95 if (nRCNM == RCNM_VI) {
96 poFDefn =
new OGRFeatureDefn(OGRN_VI);
97 poFDefn->SetGeomType(wkbPoint);
98 }
else if (nRCNM == RCNM_VC) {
99 poFDefn =
new OGRFeatureDefn(OGRN_VC);
100 poFDefn->SetGeomType(wkbPoint);
101 }
else if (nRCNM == RCNM_VE) {
102 poFDefn =
new OGRFeatureDefn(OGRN_VE);
103 poFDefn->SetGeomType(wkbLineString);
104 }
else if (nRCNM == RCNM_VF) {
105 poFDefn =
new OGRFeatureDefn(OGRN_VF);
106 poFDefn->SetGeomType(wkbPolygon);
113 OGRFieldDefn oField(
"", OFTInteger);
115 oField.Set(
"RCNM", OFTInteger, 3, 0);
116 poFDefn->AddFieldDefn(&oField);
118 oField.Set(
"RCID", OFTInteger, 8, 0);
119 poFDefn->AddFieldDefn(&oField);
121 oField.Set(
"RVER", OFTInteger, 2, 0);
122 poFDefn->AddFieldDefn(&oField);
124 oField.Set(
"RUIN", OFTInteger, 2, 0);
125 poFDefn->AddFieldDefn(&oField);
131 if (nRCNM == RCNM_VE) {
132 oField.Set(
"NAME_RCNM_0", OFTInteger, 3, 0);
133 poFDefn->AddFieldDefn(&oField);
135 oField.Set(
"NAME_RCID_0", OFTInteger, 8, 0);
136 poFDefn->AddFieldDefn(&oField);
138 oField.Set(
"ORNT_0", OFTInteger, 3, 0);
139 poFDefn->AddFieldDefn(&oField);
141 oField.Set(
"USAG_0", OFTInteger, 3, 0);
142 poFDefn->AddFieldDefn(&oField);
144 oField.Set(
"TOPI_0", OFTInteger, 1, 0);
145 poFDefn->AddFieldDefn(&oField);
147 oField.Set(
"MASK_0", OFTInteger, 3, 0);
148 poFDefn->AddFieldDefn(&oField);
150 oField.Set(
"NAME_RCNM_1", OFTInteger, 3, 0);
151 poFDefn->AddFieldDefn(&oField);
153 oField.Set(
"NAME_RCID_1", OFTInteger, 8, 0);
154 poFDefn->AddFieldDefn(&oField);
156 oField.Set(
"ORNT_1", OFTInteger, 3, 0);
157 poFDefn->AddFieldDefn(&oField);
159 oField.Set(
"USAG_1", OFTInteger, 3, 0);
160 poFDefn->AddFieldDefn(&oField);
162 oField.Set(
"TOPI_1", OFTInteger, 1, 0);
163 poFDefn->AddFieldDefn(&oField);
165 oField.Set(
"MASK_1", OFTInteger, 3, 0);
166 poFDefn->AddFieldDefn(&oField);
180 OGRFeatureDefn *poFDefn = NULL;
181 char **papszGeomPrim;
183 if (!poCR->SelectClass(nOBJL))
return NULL;
189 poFDefn =
new OGRFeatureDefn(poCR->GetAcronym());
194 poFDefn->SetOBJL(nOBJL);
200 papszGeomPrim = poCR->GetPrimitives();
201 if (CSLCount(papszGeomPrim) == 0) {
202 poFDefn->SetGeomType(wkbNone);
203 }
else if (CSLCount(papszGeomPrim) > 1) {
205 }
else if (EQUAL(papszGeomPrim[0],
"Point")) {
206 if (EQUAL(poCR->GetAcronym(),
"SOUNDG")) {
207 if (nOptionFlags & S57M_SPLIT_MULTIPOINT)
208 poFDefn->SetGeomType(wkbPoint25D);
210 poFDefn->SetGeomType(wkbMultiPoint);
212 poFDefn->SetGeomType(wkbPoint);
213 }
else if (EQUAL(papszGeomPrim[0],
"Area")) {
214 poFDefn->SetGeomType(wkbPolygon);
215 }
else if (EQUAL(papszGeomPrim[0],
"Line")) {
216 poFDefn->SetGeomType(wkbLineString);
222 S57GenerateStandardAttributes(poFDefn, nOptionFlags);
227 char **papszAttrList = poCR->GetAttributeList();
229 for (
int iAttr = 0; papszAttrList != NULL && papszAttrList[iAttr] != NULL;
231 int iAttrIndex = poCR->FindAttrByAcronym(papszAttrList[iAttr]);
233 if (iAttrIndex == -1) {
234 CPLDebug(
"S57",
"Can't find attribute %s from class %s:%s.\n",
235 papszAttrList[iAttr], poCR->GetAcronym(),
236 poCR->GetDescription());
240 OGRFieldDefn oField(papszAttrList[iAttr], OFTInteger);
242 switch (poCR->GetAttrType(iAttrIndex)) {
245 oField.SetType(OFTInteger);
249 oField.SetType(OFTReal);
252 case SAT_CODE_STRING:
254 oField.SetType(OFTString);
258 oField.SetType(OFTString);
262 poFDefn->AddFieldDefn(&oField);
268 if (EQUAL(poCR->GetAcronym(),
"SOUNDG") &&
269 (nOptionFlags & S57M_ADD_SOUNDG_DEPTH)) {
270 OGRFieldDefn oField(
"DEPTH", OFTReal);
271 poFDefn->AddFieldDefn(&oField);
283void S57GenerateStandardAttributes(OGRFeatureDefn *poFDefn,
int nOptionFlags)
286 OGRFieldDefn oField(
"", OFTInteger);
291 oField.Set(
"RCID", OFTInteger, 10, 0);
292 poFDefn->AddFieldDefn(&oField);
297 oField.Set(
"PRIM", OFTInteger, 3, 0);
298 poFDefn->AddFieldDefn(&oField);
303 oField.Set(
"GRUP", OFTInteger, 3, 0);
304 poFDefn->AddFieldDefn(&oField);
309 oField.Set(
"OBJL", OFTInteger, 5, 0);
310 poFDefn->AddFieldDefn(&oField);
315 oField.Set(
"RVER", OFTInteger, 3, 0);
316 poFDefn->AddFieldDefn(&oField);
321 oField.Set(
"AGEN", OFTInteger, 5, 0);
322 poFDefn->AddFieldDefn(&oField);
327 oField.Set(
"FIDN", OFTInteger, 10, 0);
328 poFDefn->AddFieldDefn(&oField);
333 oField.Set(
"FIDS", OFTInteger, 5, 0);
334 poFDefn->AddFieldDefn(&oField);
339 if (nOptionFlags & S57M_LNAM_REFS) {
340 oField.Set(
"LNAM", OFTString, 16, 0);
341 poFDefn->AddFieldDefn(&oField);
343 oField.Set(
"LNAM_REFS", OFTStringList, 16, 0);
344 poFDefn->AddFieldDefn(&oField);
346 oField.Set(
"FFPT_RIND", OFTIntegerList, 1, 0);
347 poFDefn->AddFieldDefn(&oField);
355 if (nOptionFlags & S57M_RETURN_LINKAGES) {
356 oField.Set(
"NAME_RCNM", OFTIntegerList, 3, 0);
357 poFDefn->AddFieldDefn(&oField);
359 oField.Set(
"NAME_RCID", OFTIntegerList, 10, 0);
360 poFDefn->AddFieldDefn(&oField);
362 oField.Set(
"ORNT", OFTIntegerList, 1, 0);
363 poFDefn->AddFieldDefn(&oField);
365 oField.Set(
"USAG", OFTIntegerList, 1, 0);
366 poFDefn->AddFieldDefn(&oField);
368 oField.Set(
"MASK", OFTIntegerList, 3, 0);
369 poFDefn->AddFieldDefn(&oField);