22 #ifndef otbPersistentImageToOGRDataFilter_hxx
23 #define otbPersistentImageToOGRDataFilter_hxx
34 template <
class TImage>
36 : m_FieldName(
"DN"), m_LayerName(
"Layer"), m_GeometryType(wkbMultiPolygon), m_FieldType(OFTInteger)
38 this->SetNumberOfRequiredInputs(2);
39 this->SetNumberOfRequiredInputs(2);
43 template <
class TImage>
48 template <
class TImage>
51 this->itk::ProcessObject::SetNthInput(1, ogrDS);
54 template <
class TImage>
60 template <
class TImage>
63 m_OGRLayerCreationOptions.push_back(option);
67 template <
class TImage>
70 m_OGRLayerCreationOptions.clear();
74 template <
class TImage>
77 m_OGRLayerCreationOptions = options;
81 template <
class TImage>
84 return m_OGRLayerCreationOptions;
87 template <
class TImage>
93 template <
class TImage>
98 template <
class TImage>
103 template <
class TImage>
106 std::string projectionRefWkt = this->GetInput()->GetProjectionRef();
107 bool projectionInformationAvailable = !projectionRefWkt.empty();
108 OGRSpatialReference* oSRS = NULL;
109 if (projectionInformationAvailable)
111 oSRS =
static_cast<OGRSpatialReference*
>(OSRNewSpatialReference(projectionRefWkt.c_str()));
115 OGRLayerType outLayer = ogrDS->CreateLayer(m_LayerName, oSRS, m_GeometryType, m_OGRLayerCreationOptions);
116 OGRFieldDefn field(m_FieldName.c_str(), m_FieldType);
121 template <
class TImage>
125 if (this->GetStreamSize()[0] == 0 && this->GetStreamSize()[1] == 0)
127 this->m_StreamSize = this->GetInput()->GetRequestedRegion().GetSize();
132 OGRLayerType srcLayer = currentTileVD->GetLayerChecked(0);
135 OGRLayerType dstLayer = ogrDS->GetLayersCount() == 1 ? ogrDS->GetLayer(0) : ogrDS->GetLayer(m_LayerName);
141 OGRErr err = dstLayer.
ogr().StartTransaction();
142 if (err != OGRERR_NONE)
144 itkExceptionMacro(<<
"Unable to start transaction for OGR layer " << dstLayer.
ogr().GetName() <<
".");
148 for (; featIt != srcLayer.
end(); ++featIt)
151 dstFeature.
SetFrom(*featIt, TRUE);
155 err = dstLayer.
ogr().CommitTransaction();
157 if (err != OGRERR_NONE)
159 itkExceptionMacro(<<
"Unable to commit transaction for OGR layer " << dstLayer.
ogr().GetName() <<
".");
166 template <
class TImage>
169 Superclass::PrintSelf(os, indent);