Skip to content
Snippets Groups Projects
Commit 3ca68ddf authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

ENH:reimplement get_lenght method from gdal/ogr

It would allow to use ogr fusion functionalities even with gdal version < 1.8.0
The implementation of the get_lenght method is based on the method available in OGRGeometryCollection class
The behaviour is not modify for otb compiled with gdal > 1.8.0.
The related compiles for now but there are remainig issues with layer deletation in the
related test
parent 1416d28b
No related branches found
No related tags found
No related merge requests found
......@@ -20,9 +20,9 @@
#include "otbOGRDataSourceWrapper.h"
#if(GDAL_VERSION_NUM < 1800)
#error FusionOGRTileFilter requires GDAL version >= 1.8.0
#endif
//#if(GDAL_VERSION_NUM < 1800)
//#error FusionOGRTileFilter requires GDAL version >= 1.8.0
//#endif
#include "itkProcessObject.h"
......@@ -121,7 +121,13 @@ protected:
} SortFeature;
void ProcessStreamingLine(bool line);
/** get length in case of OGRGeometryCollection.
* This function recodes the get_lenght method available since gdal 1.8.0
* in the case of OGRGeometryCollection. The aim is allow to access polygon stiching
* functionalities with gdal 1.6.
*/
double GetLengthOGRGeometryCollection(OGRGeometryCollection * intersection);
private:
FusionOGRTileFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
......
......@@ -73,7 +73,30 @@ FusionOGRTileFilter<TInputImage>
return static_cast<OGRDataSourceType *> (this->itk::ProcessObject::GetInput(1));
}
template<class TInputImage>
double
FusionOGRTileFilter<TInputImage>
::GetLengthOGRGeometryCollection( OGRGeometryCollection * intersection )
{
double dfLength = 0.0;
for( int iGeom = 0; iGeom < intersection->getNumGeometries(); iGeom++ )
{
OGRGeometry* geom = intersection->getGeometryRef(iGeom);
switch( wkbFlatten(geom->getGeometryType()) )
{
case wkbLinearRing:
case wkbLineString:
dfLength += ((OGRCurve *) geom)->get_Length();
break;
case wkbGeometryCollection:
dfLength += GetLengthOGRGeometryCollection(dynamic_cast<OGRGeometryCollection *> (geom));
break;
default:
break;
}
}
return dfLength;
}
template<class TInputImage>
void
FusionOGRTileFilter<TInputImage>
......@@ -210,8 +233,13 @@ FusionOGRTileFilter<TInputImage>
}
else if (intersection->getGeometryType() == wkbMultiLineString)
{
fusion.overlap = dynamic_cast<OGRMultiLineString *>(intersection.get())->get_Length();
}
#if(GDAL_VERSION_NUM < 1800)
fusion.overlap = GetLengthOGRGeometryCollection(dynamic_cast<OGRGeometryCollection *> (intersection.get()));
#else
fusion.overlap = dynamic_cast<OGRMultiLineString *>(intersection.get())->get_Length();
#endif
}
long upperFID = upper.feat.GetFID();
long lowerFID = lower.feat.GetFID();
......
......@@ -270,7 +270,7 @@ ADD_TEST(obTvStreamingVectorizedSegmentationOGR ${OBIA_TESTS1}
)
IF(${GDAL_NUM_VERSION} VERSION_GREATER "10800")
#IF(${GDAL_NUM_VERSION} VERSION_GREATER "10800")
# ------- otb::FusionOGRTileFilter -------------
ADD_TEST(obTuFusionOGRTileFilter ${OBIA_TESTS1}
# --compare-ogr ${EPSILON_8}
......@@ -283,7 +283,7 @@ ADD_TEST(obTuFusionOGRTileFilter ${OBIA_TESTS1}
layer
112
)
ENDIF(${GDAL_NUM_VERSION} VERSION_GREATER "10800")
#ENDIF(${GDAL_NUM_VERSION} VERSION_GREATER "10800")
# OBIATests2 (need PQXX)
IF(OTB_USE_PQXX)
......@@ -353,9 +353,9 @@ otbStreamingVectorizedSegmentationOGR.cxx
otbFusionOGRTileFilter.cxx
)
IF(${GDAL_NUM_VERSION} VERSION_LESS "10800")
LIST(REMOVE_ITEM BasicOBIA_SRCS1 otbFusionOGRTileFilter.cxx)
ENDIF(${GDAL_NUM_VERSION} VERSION_LESS "10800")
#IF(${GDAL_NUM_VERSION} VERSION_LESS "10800")
#LIST(REMOVE_ITEM BasicOBIA_SRCS1 otbFusionOGRTileFilter.cxx)
#ENDIF(${GDAL_NUM_VERSION} VERSION_LESS "10800")
IF(OTB_USE_PQXX)
......
......@@ -68,7 +68,7 @@ REGISTER_TEST(otbLabelImageToOGRDataSourceFilterNew);
REGISTER_TEST(otbLabelImageToOGRDataSourceFilter);
REGISTER_TEST(otbStreamingVectorizedSegmentationOGRNew);
REGISTER_TEST(otbStreamingVectorizedSegmentationOGR);
#if GDAL_VERSION_NUM >= 1800
//#if GDAL_VERSION_NUM >= 1800
REGISTER_TEST(otbFusionOGRTileFilter);
#endif
//#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment