[fdo-commits] r201 - branches/3.2.1/Providers/SHP/Src/Provider

svn_fdo at osgeo.org svn_fdo at osgeo.org
Sun Feb 25 12:27:11 EST 2007


Author: badreddinekaroui
Date: 2007-02-25 12:27:11 -0500 (Sun, 25 Feb 2007)
New Revision: 201

Modified:
   branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp
   branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h
   branches/3.2.1/Providers/SHP/Src/Provider/ShpSelectCommand.cpp
Log:
See ticket #21

Modified: branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp
===================================================================
--- branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp	2007-02-24 12:54:30 UTC (rev 200)
+++ branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.cpp	2007-02-25 17:27:11 UTC (rev 201)
@@ -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.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h
===================================================================
--- branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h	2007-02-24 12:54:30 UTC (rev 200)
+++ branches/3.2.1/Providers/SHP/Src/Provider/ShpFeatIdQueryEvaluator.h	2007-02-25 17:27:11 UTC (rev 201)
@@ -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.1/Providers/SHP/Src/Provider/ShpSelectCommand.cpp
===================================================================
--- branches/3.2.1/Providers/SHP/Src/Provider/ShpSelectCommand.cpp	2007-02-24 12:54:30 UTC (rev 200)
+++ branches/3.2.1/Providers/SHP/Src/Provider/ShpSelectCommand.cpp	2007-02-25 17:27:11 UTC (rev 201)
@@ -96,11 +96,14 @@
     class_name = id->GetText ();
     FdoPtr<ShpConnection> shpConn = (ShpConnection*)GetConnection ();
 
-	// Validate the filter. The filter may contain computed expressions involving not selected properties 
+	// Validate the filter. The filter may contain computed expressions involving not selected properties.
+	// Also, try to optimize the filter
 	if( mFilter != NULL )
 	{
-		FdoPtr<FdoClassDefinition> clas = ShpSchemaUtilities::GetLogicalClassDefinition (shpConn, class_name, NULL);
-        FdoCommonFilterExecutor::ValidateFilter( clas, mFilter, mPropertiesToSelect );
+		FdoPtr<FdoClassDefinition> classDef = ShpSchemaUtilities::GetLogicalClassDefinition (shpConn, class_name, NULL);
+        FdoCommonFilterExecutor::ValidateFilter( classDef, mFilter, mPropertiesToSelect );
+		
+		mFilter = FdoCommonFilterExecutor::OptimizeFilter( mFilter );
 	}
 
     ret = new ShpFeatureReader (shpConn, class_name, mFilter, mPropertiesToSelect);



More information about the fdo-commits mailing list