22 #ifndef otbPersistentImageToOGRDataFilter_txx
23 #define otbPersistentImageToOGRDataFilter_txx
27 #include <boost/foreach.hpp>
35 template<
class TImage>
39 , m_LayerName(
"Layer")
40 , m_GeometryType(wkbMultiPolygon)
41 , m_FieldType(OFTInteger)
43 this->SetNumberOfRequiredInputs(2);
44 this->SetNumberOfRequiredInputs(2);
48 template<
class TImage>
54 template<
class TImage>
62 template<
class TImage>
70 template<
class TImage>
75 m_OGRLayerCreationOptions.push_back(option);
79 template<
class TImage>
84 m_OGRLayerCreationOptions.clear();
88 template<
class TImage>
93 m_OGRLayerCreationOptions = options;
97 template<
class TImage>
98 const std::vector<std::string>&
102 return m_OGRLayerCreationOptions;
105 template<
class TImage>
113 template<
class TImage>
120 template<
class TImage>
127 template<
class TImage>
132 std::string projectionRefWkt = this->GetInput()->GetProjectionRef();
133 bool projectionInformationAvailable = !projectionRefWkt.empty();
134 OGRSpatialReference * oSRS = NULL;
135 if(projectionInformationAvailable)
137 oSRS =
static_cast<OGRSpatialReference *
>(OSRNewSpatialReference(projectionRefWkt.c_str()));
141 OGRLayerType outLayer = ogrDS->CreateLayer(m_LayerName, oSRS ,m_GeometryType, m_OGRLayerCreationOptions);
142 OGRFieldDefn field(m_FieldName.c_str(),m_FieldType);
147 template<
class TImage>
153 if (this->GetStreamSize()[0]==0 && this->GetStreamSize()[1]==0)
155 this->m_StreamSize = this->GetInput()->GetRequestedRegion().GetSize();
160 OGRLayerType srcLayer = currentTileVD->GetLayerChecked(0);
165 : ogrDS->GetLayer(m_LayerName);
171 OGRErr err = dstLayer.
ogr().StartTransaction();
172 if (err != OGRERR_NONE)
174 itkExceptionMacro(<<
"Unable to start transaction for OGR layer " << dstLayer.
ogr().GetName() <<
".");
178 for(; featIt!=srcLayer.
end(); ++featIt)
181 dstFeature.
SetFrom( *featIt, TRUE );
185 err = dstLayer.
ogr().CommitTransaction();
187 if (err != OGRERR_NONE)
189 itkExceptionMacro(<<
"Unable to commit transaction for OGR layer " << dstLayer.
ogr().GetName() <<
".");
196 template<
class TImage>
201 Superclass::PrintSelf(os, indent);
void SetOGRLayerCreationOptions(const std::vector< std::string > &options)
Collection of geometric objects.
DurationType GetElapsedMilliseconds() const
virtual void Synthetize(void)
void CreateField(FieldDefn const &field, bool bApproxOK=true)
void AddOGRLayerCreationOption(const std::string &option)
OGRFeatureDefn & GetLayerDefn() const
static Stopwatch StartNew()
Layer of geometric objets.
const std::vector< std::string > & GetOGRLayerCreationOptions(void)
virtual ~PersistentImageToOGRDataFilter()
Implementation class for Feature iterator. This iterator is a single pass iterator. We may fetch the Feature referenced by an iterator previously stored, but never resume the iteration after a call to Layer::begin(), Layer::start_at(), Layer::CreateFeature(), Layer::DeleteFeature(), Layer::GetFeature(), Layer::SetFeature(), nor fork the iteration.
const_iterator begin() const
void CreateFeature(Feature feature)
#define otbMsgDebugMacro(x)
void SetOGRDataSource(OGRDataSourcePointerType ogrDS)
void PrintSelf(std::ostream &os, itk::Indent indent) const
PersistentImageToOGRDataFilter()
virtual void GenerateData()
DataObject * GetInput(const DataObjectIdentifierType &key)
void SetFrom(Feature const &rhs, int *map, bool mustForgive=true)
void ClearOGRLayerCreationOptions()
Geometric objet with descriptive fields.
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
OGRDataSourceType * GetOGRDataSource(void)
virtual void Initialize(void)
const_iterator end() const