MCPcopy Create free account
hub / github.com/OSGeo/gdal / RunStep

Method RunStep

apps/gdalalg_vector_create.cpp:121–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119/************************************************************************/
120
121bool GDALVectorCreateAlgorithm::RunStep(GDALPipelineStepRunContext &)
122{
123
124 const std::string &datasetName = m_outputDataset.GetName();
125 const std::string outputLayerName =
126 m_outputLayerName.empty() ? CPLGetBasenameSafe(datasetName.c_str())
127 : m_outputLayerName;
128
129 std::unique_ptr<GDALDataset> poDstDS;
130 poDstDS.reset(GDALDataset::Open(datasetName.c_str(),
131 GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr,
132 nullptr, nullptr));
133
134 if (poDstDS && !m_update)
135 {
136 ReportError(CE_Failure, CPLE_AppDefined,
137 "Dataset %s already exists. Specify the "
138 "--%s option to open it in update mode.",
139 datasetName.c_str(), GDAL_ARG_NAME_UPDATE);
140 return false;
141 }
142
143 GDALDataset *poSrcDS = m_inputDataset.empty()
144 ? nullptr
145 : m_inputDataset.front().GetDatasetRef();
146
147 OGRSchemaOverride oSchemaOverride;
148
149 const auto loadJSON = [this,
150 &oSchemaOverride](const std::string &source) -> bool
151 {
152 // This error count is necessary because LoadFromJSON tries to load
153 // the content as a file first (and set an error it if fails) then tries
154 // to load as a JSON string but even if it succeeds an error is still
155 // set and not cleared.
156 const auto nErrorCount = CPLGetErrorCounter();
157 if (!oSchemaOverride.LoadFromJSON(source,
158 /* allowGeometryFields */ true))
159 {
160 // Get the last error message and report it, since LoadFromJSON doesn't do it itself.
161 if (nErrorCount != CPLGetErrorCounter())
162 {
163 const std::string lastErrorMsg = CPLGetLastErrorMsg();
164 CPLErrorReset();
165 ReportError(CE_Failure, CPLE_AppDefined,
166 "Cannot parse OGR_SCHEMA: %s.",
167 lastErrorMsg.c_str());
168 }
169 else
170 {
171 ReportError(CE_Failure, CPLE_AppDefined,
172 "Cannot parse OGR_SCHEMA (unknown error).");
173 }
174 return false;
175 }
176 else if (nErrorCount != CPLGetErrorCounter())
177 {
178 CPLErrorReset();

Callers

nothing calls this directly

Calls 15

CPLGetBasenameSafeFunction · 0.85
GDALVectorInfoOptionsNewFunction · 0.85
GDALVectorInfoFunction · 0.85
GetGDALDriverManagerFunction · 0.85
CreateLayerFunction · 0.85
OGRFromOGCGeomTypeFunction · 0.85
moveFunction · 0.85
frontMethod · 0.80
LoadFromJSONMethod · 0.80
ListMethod · 0.80

Tested by

no test coverage detected