21 #ifndef otbRasterizeVectorDataFilter_hxx
22 #define otbRasterizeVectorDataFilter_hxx
30 template <
class TVectorData,
class TInputImage,
class TOutputImage>
33 this->SetNumberOfRequiredInputs(1);
36 template <
class TVectorData,
class TInputImage,
class TOutputImage>
41 if (this->GetNumberOfInputs() < 1)
43 this->itk::ProcessObject::SetNthInput(1,
const_cast<VectorDataType*
>(vd));
47 this->itk::ProcessObject::PushBackInput(vd);
52 template <
class TVectorData,
class TInputImage,
class TOutputImage>
55 Superclass::GenerateOutputInformation();
59 for (
unsigned int idx = 1; idx < this->GetNumberOfInputs(); ++idx)
64 std::string projectionRefWkt = vd->GetProjectionRef();
65 bool projectionInformationAvailable = !projectionRefWkt.empty();
66 OGRSpatialReference* oSRS =
nullptr;
68 if (projectionInformationAvailable)
70 oSRS =
static_cast<OGRSpatialReference*
>(OSRNewSpatialReference(projectionRefWkt.c_str()));
85 OGRLayer* ogrCurrentLayer =
nullptr;
86 std::vector<OGRLayer*> ogrLayerVector;
92 m_OGRDataSourcePointer =
nullptr;
93 ogrLayerVector = IOConversion->ConvertDataTreeNodeToOGRLayers(inputRoot, m_OGRDataSourcePointer, ogrCurrentLayer, oSRS);
96 for (
unsigned int idx2 = 0; idx2 < ogrLayerVector.size(); ++idx2)
98 m_SrcDataSetLayers.push_back((OGRLayerH)(ogrLayerVector[idx2]));
113 if (m_BurnValues.size() != m_BandsToBurn.size() * m_SrcDataSetLayers.size())
115 std::ostringstream oss;
116 oss <<
"Inconsistency detected : expected burn vector size to be equal to( bandToBurn * nb layers = " << m_BandsToBurn.size() * m_SrcDataSetLayers.size()
117 <<
" ), got : " << m_BurnValues.size() << std::endl;
118 itkWarningMacro(<< oss.str());
122 for (
unsigned int idx = 0; idx < m_SrcDataSetLayers.size(); ++idx)
124 for (
unsigned int burnidx = 0; burnidx < m_BurnValues.size(); ++burnidx)
126 m_FullBurnValues.push_back(m_BurnValues[burnidx]);
131 template <
class TVectorData,
class TInputImage,
class TOutputImage>
135 Superclass::GenerateData();
141 unsigned int nbBands = this->GetOutput()->GetNumberOfComponentsPerPixel();
146 std::ostringstream stream;
148 <<
"DATAPOINTER=" << (uintptr_t)(this->GetOutput()->GetBufferPointer()) <<
","
149 <<
"PIXELS=" << bufferedRegion.GetSize()[0] <<
","
150 <<
"LINES=" << bufferedRegion.GetSize()[1] <<
","
151 <<
"BANDS=" << nbBands <<
","
152 <<
"DATATYPE=" << GDALGetDataTypeName(GdalDataTypeBridge::GetGDALDataType<OutputImageInternalPixelType>()) <<
","
157 GDALDatasetH dataset = GDALOpen(stream.str().c_str(), GA_Update);
160 GDALSetProjection(dataset, this->GetOutput()->GetProjectionRef().c_str());
163 itk::VariableLengthVector<double> geoTransform(6);
169 this->GetOutput()->TransformIndexToPhysicalPoint(bufferIndexOrigin, bufferOrigin);
170 geoTransform[0] = bufferOrigin[0] - 0.5 * this->GetOutput()->GetSignedSpacing()[0];
171 geoTransform[3] = bufferOrigin[1] - 0.5 * this->GetOutput()->GetSignedSpacing()[1];
172 geoTransform[1] = this->GetOutput()->GetSignedSpacing()[0];
173 geoTransform[5] = this->GetOutput()->GetSignedSpacing()[1];
176 geoTransform[2] = 0.;
177 geoTransform[4] = 0.;
178 GDALSetGeoTransform(dataset,
const_cast<double*
>(geoTransform.GetDataPointer()));
180 char** options =
nullptr;
181 if (m_AllTouchedMode)
183 options = CSLSetNameValue(options,
"ALL_TOUCHED",
"TRUE");
187 if (dataset !=
nullptr)
189 GDALRasterizeLayers(dataset, m_BandsToBurn.size(), &(m_BandsToBurn[0]), m_SrcDataSetLayers.size(), &(m_SrcDataSetLayers[0]),
nullptr,
nullptr,
190 &(m_FullBurnValues[0]), options, GDALDummyProgress,
nullptr);
199 template <
class TVectorData,
class TInputImage,
class TOutputImage>
202 Superclass::PrintSelf(os, indent);