22 #ifndef otbPersistentImageToOGRLayerFilter_hxx
23 #define otbPersistentImageToOGRLayerFilter_hxx
34 template <
class TImage>
40 template <
class TImage>
45 template <
class TImage>
48 m_OGRLayer = ogrLayer;
52 template <
class TImage>
58 template <
class TImage>
64 template <
class TImage>
69 template <
class TImage>
74 template <
class TImage>
78 const_cast<InputImageType*
>(this->GetInput())->UpdateOutputInformation();
82 OGRSpatialReference oSRS(this->GetInput()->GetProjectionRef().c_str());
87 OGRSpatialReference oSRSESRI(this->GetInput()->GetProjectionRef().c_str());
89 oSRSESRI.morphToESRI();
90 oSRSESRI.morphFromESRI();
92 #if GDAL_VERSION_NUM >= 3000000 // importFromWkt is const-correct in GDAL 3
94 auto mappingStrategy = m_OGRLayer.GetSpatialRef()->GetAxisMappingStrategy();
95 oSRS.SetAxisMappingStrategy(mappingStrategy);
96 oSRSESRI.SetAxisMappingStrategy(mappingStrategy);
99 if (m_OGRLayer.GetSpatialRef() && (!oSRS.IsSame(m_OGRLayer.GetSpatialRef()) && !oSRSESRI.IsSame(m_OGRLayer.GetSpatialRef())))
101 if ((oSRS.Validate() != OGRERR_NONE) && (oSRSESRI.Validate() != OGRERR_NONE))
103 itkExceptionMacro(<<
"Input projection ref is not valid");
105 itkExceptionMacro(<<
"Spatial reference of input image and target layer do not match! " << std::endl
106 <<
"Input image : " << this->GetInput()->GetProjectionRef() << std::endl
107 <<
"Target layer : " << m_OGRLayer.GetProjectionRef());
111 template <
class TImage>
116 itkExceptionMacro(<<
"Output OGRLayer is null.");
119 if (this->GetStreamSize()[0] == 0 && this->GetStreamSize()[1] == 0)
121 this->m_StreamSize = this->GetInput()->GetRequestedRegion().GetSize();
126 OGRLayerType srcLayer = currentTileVD->GetLayerChecked(0);
132 itkExceptionMacro(<<
"Spatial reference of internal and target layers do not match!");
138 OGRErr err = m_OGRLayer.ogr().StartTransaction();
139 if (err != OGRERR_NONE)
141 itkExceptionMacro(<<
"Unable to start transaction for OGR layer " << m_OGRLayer.ogr().GetName() <<
".");
145 for (; featIt != srcLayer.
end(); ++featIt)
148 dstFeature.
SetFrom(*featIt, TRUE);
149 m_OGRLayer.CreateFeature(dstFeature);
152 err = m_OGRLayer.ogr().CommitTransaction();
154 if (err != OGRERR_NONE)
156 itkExceptionMacro(<<
"Unable to commit transaction for OGR layer " << m_OGRLayer.ogr().GetName() <<
".");
163 template <
class TImage>
166 Superclass::PrintSelf(os, indent);