MCPcopy Create free account
hub / github.com/PDAL/PDAL / initialize

Method initialize

io/TIndexReader.cpp:181–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179
180
181void TIndexReader::initialize()
182{
183 if (!m_args->m_bounds.empty())
184 m_args->m_wkt = m_args->m_bounds.toWKT();
185 m_out_ref.reset(new gdal::SpatialRef());
186
187 log()->get(LogLevel::Debug) << "Opening file " << m_filename <<
188 std::endl;
189
190 gdal::registerDrivers();
191 m_dataset = OGROpen(m_filename.c_str(), FALSE, NULL);
192 if (!m_dataset)
193 throwError("Unable to datasource '" + m_filename + "'");
194
195 OGRGeometryH geometry(0);
196 if (m_args->m_sql.size())
197 {
198 m_layer = OGR_DS_ExecuteSQL(m_dataset, m_args->m_sql.c_str(), geometry,
199 m_args->m_dialect.c_str());
200 }
201 else
202 {
203 m_layer = OGR_DS_GetLayerByName(m_dataset, m_args->m_layerName.c_str());
204 }
205 if (!m_layer)
206 throwError("Unable to open layer '" + m_args->m_layerName +
207 "' from OGR datasource '" + m_filename + "'");
208
209 m_out_ref->setFromLayer(m_layer);
210
211 // Override the SRS if the user set one, otherwise, take it
212 // from the layer
213 if (m_args->m_tgtSrsString.size())
214 m_out_ref.reset(new gdal::SpatialRef(m_args->m_tgtSrsString));
215 else
216 m_out_ref.reset(new gdal::SpatialRef(m_out_ref->wkt()));
217
218 // Set SRS if not overridden.
219 if (getSpatialReference().empty())
220 setSpatialReference(SpatialReference(m_out_ref->wkt()));
221
222 // If an OGR specification was added, we overwrite the wkt polygon
223 // with it. If OGRSpec is going to contain non-polygon geometries
224 // in the future this method would need to be changed.
225 if (m_args->m_ogr.size())
226 {
227 Polygon ogrPoly = m_args->m_ogr.getPolygons()[0];
228 m_args->m_wkt = ogrPoly.wkt();
229 }
230 // If the user set either explicit 'polygon' or 'boundary' options
231 // we will filter by that geometry. The user can set a 'filter_srs'
232 // option to override the SRS of the input geometry and we will
233 // reproject to the output projection as needed.
234 Polygon poly;
235 if (m_args->m_wkt.size())
236 {
237 // Reproject the given wkt to the output SRS so
238 // filtering/cropping works

Callers

nothing calls this directly

Calls 15

registerDriversFunction · 0.85
handleReaderArgsFunction · 0.85
setReaderOptionsFunction · 0.85
setInputFunction · 0.85
setFromLayerMethod · 0.80
getPolygonsMethod · 0.80
inferReaderDriverMethod · 0.80
createStageMethod · 0.80
setOptionsMethod · 0.80
SpatialReferenceClass · 0.70
logFunction · 0.50
setSpatialReferenceFunction · 0.50

Tested by

no test coverage detected