[fdo-commits] r212 - branches/3.2.x/Providers/SHP/Src/Provider

svn_fdo at osgeo.org svn_fdo at osgeo.org
Fri Mar 9 13:36:14 EST 2007


Author: badreddinekaroui
Date: 2007-03-09 13:36:14 -0500 (Fri, 09 Mar 2007)
New Revision: 212

Modified:
   branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp
   branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h
   branches/3.2.x/Providers/SHP/Src/Provider/ShpSelectCommand.cpp
Log:
Merge ticket #21 fix from 2.1.1 branch to 2.1.x

Modified: branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp
===================================================================
--- branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp	2007-03-08 23:09:41 UTC (rev 211)
+++ branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp	2007-03-09 18:36:14 UTC (rev 212)
@@ -243,6 +243,51 @@
     FdoCommonFilterExecutor::ProcessDistanceCondition( filter );
 }
 
+void ShpFeatIdQueryEvaluator::DoSecondaryFilter(FdoIGeometry *filterGeom, FdoSpatialOperations spatialOp )
+{
+	interval_res*    results = new interval_res;
+
+    results->op = ShpComparisonOperation_In;
+	results->depth = m_level - 1;
+
+    recno_list*  secFilterList = &results->queryResults;
+
+    FdoPtr<ShpLpClassDefinition> shpLpClassDef = ShpSchemaUtilities::GetLpClassDefinition(m_Connection, m_Class->GetName());
+
+    ShpFileSet*  fileSet = shpLpClassDef->GetPhysicalFileSet();
+
+	recno_list*    featidPrimarySel = &m_FeatidLists.back()->queryResults;
+	FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
+    for ( size_t i = 0; i < featidPrimarySel->size(); i++ )
+    {
+        ULONG    offset;
+        int         length;
+        Shape*      shape = NULL; 
+        eShapeTypes type;
+
+        FdoInt32  featNum = featidPrimarySel->at(i);
+
+        // Get info from the file.
+        fileSet->GetShapeIndexFile()->GetObjectAt( featNum, offset, length);
+        shape = fileSet->GetShapeFile()->GetObjectAt (offset, type);
+		
+        FdoPtr<FdoByteArray>  geomLeftFgf = shape->GetGeometry ();
+        FdoPtr<FdoIGeometry>  geomLeft = gf->CreateGeometryFromFgf( geomLeftFgf );
+        delete shape;
+
+        bool  ret = FdoSpatialUtility::Evaluate( geomLeft, spatialOp, filterGeom);
+        if ( ret )
+            secFilterList->push_back( featNum );
+    }
+
+    //delete featidPrimarySel;
+    retno_lists::iterator  iter_lists = m_FeatidLists.end();
+	--iter_lists;
+    delete *iter_lists;  // delete the memory this vector entry points to
+    m_FeatidLists.erase( iter_lists );  // delete this vector entry
+    m_FeatidLists.push_back( results );
+}
+
 void ShpFeatIdQueryEvaluator::ProcessSpatialCondition(FdoSpatialCondition& filter)
 {  
     FdoPtr<FdoExpression> expr = filter.GetGeometry();
@@ -256,15 +301,31 @@
 
     FdoPtr<FdoByteArray>  geomRightFgf = geomRightVal->GetGeometry();
 
-    BoundingBox             searchArea;
-    FdoSpatialUtility::GetExtents( geomRightFgf, searchArea.xMin, searchArea.yMin, searchArea.xMax, searchArea.yMax);
-
     FdoPtr<FdoGeometricPropertyDefinition> gpd = FindGeomProp(m_Class);
     FdoPtr<FdoIdentifier> idname = filter.GetPropertyName();
 
     if (0 != wcscmp (gpd->GetName (), idname->GetName ()))
         throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_104_READER_PROPERTY_NOT_SELECTED), idname->GetName ()));
-	
+	// 
+	if( m_level == 2 && m_LogicalOpsList.size() != 0 && m_FeatidLists.size() != 0 && m_LogicalOpsList.back() == FdoBinaryLogicalOperations_And && m_LeftRightOpsList.back() == 1 )
+	{
+		// skip primary filter and do secondary filtering on the top of the stack of m_FeatidLists
+		m_LogicalOpsList.pop_back();
+		m_LeftRightOpsList.pop_back();
+
+		// pop the left ops as well
+		m_LogicalOpsList.pop_back();
+		m_LeftRightOpsList.pop_back();
+		m_level-=2;
+		FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
+		FdoPtr<FdoIGeometry>  filterGeom = gf->CreateGeometryFromFgf( geomRightFgf );
+		DoSecondaryFilter( filterGeom, filter.GetOperation() );
+		return;
+	}
+
+	BoundingBox             searchArea;
+    FdoSpatialUtility::GetExtents( geomRightFgf, searchArea.xMin, searchArea.yMin, searchArea.xMax, searchArea.yMax);
+
     if (m_RTree)
     {
         // For each bounding box build a sorted list of candidates (primary filter) and save it.

Modified: branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h
===================================================================
--- branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h	2007-03-08 23:09:41 UTC (rev 211)
+++ branches/3.2.x/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h	2007-03-09 18:36:14 UTC (rev 212)
@@ -91,6 +91,7 @@
     size_t                  EvaluateMergedListSize( int maxRecords );
 	void					ProcessLeafExpession( interval_res* curr_filter, int curr_logical_op, int maxRecords );
 	void					PrintFlattenParseTree();
+	void					DoSecondaryFilter(FdoIGeometry *filterGeom, FdoSpatialOperations spatialOp );
 
     FdoGeometricPropertyDefinition* FindGeomProp(FdoClassDefinition* classDef);
 

Modified: branches/3.2.x/Providers/SHP/Src/Provider/ShpSelectCommand.cpp
===================================================================
--- branches/3.2.x/Providers/SHP/Src/Provider/ShpSelectCommand.cpp	2007-03-08 23:09:41 UTC (rev 211)
+++ branches/3.2.x/Providers/SHP/Src/Provider/ShpSelectCommand.cpp	2007-03-09 18:36:14 UTC (rev 212)
@@ -116,12 +116,14 @@
     // Create the reader:
 
 	// Validate the filter. The filter may contain computed expressions involving not selected properties.
-	// Also check for unsupported spatial operations.
+	// Also check for unsupported spatial operations and try to optimize the filter
 	if( mFilter != NULL )
 	{
 		FdoPtr<FdoClassDefinition> classDef = ShpSchemaUtilities::GetLogicalClassDefinition (shpConn, class_name, NULL);
 		FdoPtr<FdoIFilterCapabilities> filterCaps = shpConn->GetFilterCapabilities();
         FdoCommonFilterExecutor::ValidateFilter( classDef, mFilter, mPropertiesToSelect, filterCaps );
+
+		mFilter = FdoCommonFilterExecutor::OptimizeFilter( mFilter );
 	}
 
     ret = new ShpFeatureReader (shpConn, class_name, mFilter, mPropertiesToSelect);



More information about the fdo-commits mailing list