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()));
82 OGRLayer* ogrCurrentLayer =
nullptr;
83 std::vector<OGRLayer*> ogrLayerVector;
89 m_OGRDataSourcePointer =
nullptr;
90 ogrLayerVector = IOConversion->ConvertDataTreeNodeToOGRLayers(vd,root, m_OGRDataSourcePointer, ogrCurrentLayer, oSRS);
93 for (
unsigned int idx2 = 0; idx2 < ogrLayerVector.size(); ++idx2)
95 m_SrcDataSetLayers.push_back((OGRLayerH)(ogrLayerVector[idx2]));
110 if (m_BurnValues.size() != m_BandsToBurn.size() * m_SrcDataSetLayers.size())
112 std::ostringstream oss;
113 oss <<
"Inconsistency detected : expected burn vector size to be equal to( bandToBurn * nb layers = " << m_BandsToBurn.size() * m_SrcDataSetLayers.size()
114 <<
" ), got : " << m_BurnValues.size() << std::endl;
115 itkWarningMacro(<< oss.str());
119 for (
unsigned int idx = 0; idx < m_SrcDataSetLayers.size(); ++idx)
121 for (
unsigned int burnidx = 0; burnidx < m_BurnValues.size(); ++burnidx)
123 m_FullBurnValues.push_back(m_BurnValues[burnidx]);
128 template <
class TVectorData,
class TInputImage,
class TOutputImage>
132 Superclass::GenerateData();
138 unsigned int nbBands = this->GetOutput()->GetNumberOfComponentsPerPixel();
143 std::ostringstream stream;
145 <<
"DATAPOINTER=" << (uintptr_t)(this->GetOutput()->GetBufferPointer()) <<
","
146 <<
"PIXELS=" << bufferedRegion.GetSize()[0] <<
","
147 <<
"LINES=" << bufferedRegion.GetSize()[1] <<
","
148 <<
"BANDS=" << nbBands <<
","
149 <<
"DATATYPE=" << GDALGetDataTypeName(GdalDataTypeBridge::GetGDALDataType<OutputImageInternalPixelType>()) <<
","
154 GDALDatasetH dataset = GDALOpen(stream.str().c_str(), GA_Update);
157 GDALSetProjection(dataset, this->GetOutput()->GetProjectionRef().c_str());
160 itk::VariableLengthVector<double> geoTransform(6);
166 this->GetOutput()->TransformIndexToPhysicalPoint(bufferIndexOrigin, bufferOrigin);
167 geoTransform[0] = bufferOrigin[0] - 0.5 * this->GetOutput()->GetSignedSpacing()[0];
168 geoTransform[3] = bufferOrigin[1] - 0.5 * this->GetOutput()->GetSignedSpacing()[1];
169 geoTransform[1] = this->GetOutput()->GetSignedSpacing()[0];
170 geoTransform[5] = this->GetOutput()->GetSignedSpacing()[1];
173 geoTransform[2] = 0.;
174 geoTransform[4] = 0.;
175 GDALSetGeoTransform(dataset,
const_cast<double*
>(geoTransform.GetDataPointer()));
177 char** options =
nullptr;
178 if (m_AllTouchedMode)
180 options = CSLSetNameValue(options,
"ALL_TOUCHED",
"TRUE");
184 if (dataset !=
nullptr)
186 GDALRasterizeLayers(dataset, m_BandsToBurn.size(), &(m_BandsToBurn[0]), m_SrcDataSetLayers.size(), &(m_SrcDataSetLayers[0]),
nullptr,
nullptr,
187 &(m_FullBurnValues[0]), options, GDALDummyProgress,
nullptr);
196 template <
class TVectorData,
class TInputImage,
class TOutputImage>
199 Superclass::PrintSelf(os, indent);
itk::SmartPointer< Self > Pointer
void GenerateData() override
OutputImageType::RegionType OutputImageRegionType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
TVectorData VectorDataType
RasterizeVectorDataFilter()
VectorDataType::DataNodePointerType DataNodePointerType
OutputImageType::InternalPixelType OutputImageInternalPixelType
InputImageType::PointType InputPointType
InputImageType::IndexType InputIndexType
virtual void AddVectorData(const VectorDataType *vd)
void GenerateOutputInformation() override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbMsgDevMacro(x)