Debian Codegraph @

ogr/ogrsf_frmts/ili/ogrili1datasource.cpp

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Project: Interlis 1 Translator
4 * Purpose: Implements OGRILI1DataSource class.
5 * Author: Pirmin Kalberer, Sourcepole AG
6 *
7 ******************************************************************************
8 * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG
9 * Copyright (c) 2007-2008, Even Rouault <even dot rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14 #include "cpl_conv.h"cxx . . $ `<file>/port/cpl_conv.h`/
15 #include "cpl_string.h"cxx . . $ `<file>/port/cpl_string.h`/
16
17 #include "ili1reader.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ili/ili1reader.h`/
18 #include "ogr_ili1.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ili/ogr_ili1.h`/
19
20 #include <string>
21
22 /************************************************************************/
23 /* OGRILI1DataSource() */
24 /************************************************************************/
25
26 OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::OGRILI1DataSourcecxx . . $ OGRILI1DataSource#OGRILI1DataSource(49f6e7a06ebc5aa8).()
27 : poImdReadercxx . . $ OGRILI1DataSource#poImdReader.(new ImdReadercxx . . $ ImdReader#(1)), poReadercxx . . $ OGRILI1DataSource#poReader.(nullptr), nLayerscxx . . $ OGRILI1DataSource#nLayers.(0),
28 papoLayerscxx . . $ OGRILI1DataSource#papoLayers.(nullptr)
29 {
30 }
31
32 /************************************************************************/
33 /* ~OGRILI1DataSource() */
34 /************************************************************************/
35
36 OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::~cxx . . $ OGRILI1DataSource#`~OGRILI1DataSource`(ced63f7c635d850d).OGRILI1DataSourcecxx . . $ OGRILI1DataSource#()
37
38 {
39 for (int i = 0; i < nLayerscxx . . $ OGRILI1DataSource#nLayers.; i++)
40 {
41 delete papoLayerscxx . . $ OGRILI1DataSource#papoLayers.[i];
42 }
43 CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(papoLayerscxx . . $ OGRILI1DataSource#papoLayers.);
44
45 DestroyILI1Readercxx . . $ DestroyILI1Reader(88f0b5f69f39fc5).(poReadercxx . . $ OGRILI1DataSource#poReader.);
46 delete poImdReadercxx . . $ OGRILI1DataSource#poImdReader.;
47 }
48
49 /************************************************************************/
50 /* Open() */
51 /************************************************************************/
52
53 int OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::Opencxx . . $ OGRILI1DataSource#Open(db37ecbbd998ad97).(const char *pszNewName, char **papszOpenOptionsIn,
54 int bTestOpen)
55
56 {
57 if (strlen(pszNewName) == 0)
58 {
59 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
60 }
61
62 stdcxx . . $ std/::string osBasename;
63 stdcxx . . $ std/::string osModelFilename;
64 if (CSLFetchNameValue(papszOpenOptionsIn, "MODEL") != nullptr)
65 {
66 osBasename = pszNewName;
67 osModelFilename = CSLFetchNameValue(papszOpenOptionsIn, "MODEL");
68 }
69 else
70 {
71 char **filenames = CSLTokenizeString2(pszNewName, ",", 0);
72 int nCount = CSLCount(filenames);
73 if (nCount == 0)
74 {
75 CSLDestroy(filenames);
76 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
77 }
78 osBasename = filenames[0];
79
80 if (nCount > 1)
81 osModelFilename = filenames[1];
82
83 CSLDestroy(filenames);
84 }
85
86 /* -------------------------------------------------------------------- */
87 /* Open the source file. */
88 /* -------------------------------------------------------------------- */
89 VSILFILE *fp = VSIFOpenL(osBasename.c_str(), "r");
90 if (fp == nullptr)
91 {
92 if (!bTestOpen)
93 CPLError(CE_Failure, CPLE_OpenFailedcxx . . $ `port/cpl_error.h:114:9`!,
94 "Failed to open ILI1 file `%s'.", pszNewName);
95
96 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
97 }
98
99 /* -------------------------------------------------------------------- */
100 /* If we aren't sure it is ILI1, load a header chunk and check */
101 /* for signs it is ILI1 */
102 /* -------------------------------------------------------------------- */
103 char szHeader[1000];
104
105 if (bTestOpen)
106 {
107 int nLen = (int)VSIFReadL(szHeader, 1, sizeof(szHeader), fp);
108 if (nLen == sizeof(szHeader))
109 szHeader[sizeof(szHeader) - 1] = '\0';
110 else
111 szHeader[nLen] = '\0';
112
113 if (strstr(szHeader, "SCNT") == nullptr)
114 {
115 VSIFCloseL(fp);
116 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
117 }
118 }
119
120 /* -------------------------------------------------------------------- */
121 /* We assume now that it is ILI1. Close and instantiate a */
122 /* ILI1Reader on it. */
123 /* -------------------------------------------------------------------- */
124 VSIFCloseL(fp);
125
126 poReadercxx . . $ OGRILI1DataSource#poReader. = CreateILI1Readercxx . . $ CreateILI1Reader(e90e5c52490b1096).();
127 if (poReadercxx . . $ OGRILI1DataSource#poReader. == nullptr)
128 {
129 CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!,
130 "File %s appears to be ILI1 but the ILI1 reader cannot\n"
131 "be instantiated, likely because Xerces support was not\n"
132 "configured in.",
133 pszNewName);
134 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
135 }
136
137 poReadercxx . . $ OGRILI1DataSource#poReader.->OpenFilecxx . . $ IILI1Reader#OpenFile(5c4306d8553b3696).(osBasename.c_str());
138
139 if (osModelFilename.length() > 0)
140 poReadercxx . . $ OGRILI1DataSource#poReader.->ReadModelcxx . . $ IILI1Reader#ReadModel(d6025bc83d52e724).(poImdReadercxx . . $ OGRILI1DataSource#poImdReader., osModelFilename.c_str(), this);
141
142 CPLConfigOptionSetter oSetter("OGR_ARC_STEPSIZE", "0.96",
143 /* bSetOnlyIfUndefined = */ true);
144
145 // Parse model and read data - without surface join and area polygonizing.
146 poReadercxx . . $ OGRILI1DataSource#poReader.->ReadFeaturescxx . . $ IILI1Reader#ReadFeatures(b126dc7c1de90089).();
147
148 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
149 }
150
151 /************************************************************************/
152 /* TestCapability() */
153 /************************************************************************/
154
155 int OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::TestCapabilitycxx . . $ OGRILI1DataSource#TestCapability(78f035161ffa9fe2).(const char *pszCap) const
156
157 {
158 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, ODsCCurveGeometriescxx . . $ `ogr/ogr_core.h:1048:9`!))
159 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
160 else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, ODsCZGeometriescxx . . $ `ogr/ogr_core.h:1058:9`!))
161 return TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
162
163 return FALSEcxx . . $ `port/cpl_port.h:1180:9`!;
164 }
165
166 /************************************************************************/
167 /* GetLayer() */
168 /************************************************************************/
169
170 const OGRLayercxx . . $ OGRLayer# *OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::GetLayercxx . . $ OGRILI1DataSource#GetLayer(3ead67c79a3185c4).(int iLayer) const
171 {
172 if (!poReadercxx . . $ OGRILI1DataSource#poReader.)
173 {
174 if (iLayer < 0 || iLayer >= nLayerscxx . . $ OGRILI1DataSource#nLayers.)
175 return nullptr;
176 return papoLayerscxx . . $ OGRILI1DataSource#papoLayers.[iLayer];
177 }
178 return poReadercxx . . $ OGRILI1DataSource#poReader.->GetLayercxx . . $ IILI1Reader#GetLayer(3ead67c79a3185c4).(iLayer);
179 }
180
181 /************************************************************************/
182 /* GetLayerByName() */
183 /************************************************************************/
184
185 OGRILI1Layercxx . . $ OGRILI1Layer# *OGRILI1DataSourcecxx . . $ OGRILI1DataSource#::GetLayerByNamecxx . . $ OGRILI1DataSource#GetLayerByName(22769fe554addabe).(const char *pszLayerName)
186 {
187 if (!poReadercxx . . $ OGRILI1DataSource#poReader.)
188 {
189 return cpl::down_cast<OGRILI1Layercxx . . $ OGRILI1Layer# *>(
190 GDALDatasetcxx . . $ GDALDataset#::GetLayerByNamecxx . . $ GDALDataset#GetLayerByName(5ddf27af0841fa5b).(pszLayerName));
191 }
192
193 return cpl::down_cast<OGRILI1Layercxx . . $ OGRILI1Layer# *>(
194 poReadercxx . . $ OGRILI1DataSource#poReader.->GetLayerByNamecxx . . $ IILI1Reader#GetLayerByName(5ddf27af0841fa5b).(pszLayerName));
195 }