[mapguide-users] OGR / GEOS selection problem

Traian Stanev traian.stanev at autodesk.com
Thu Jun 14 10:32:33 EDT 2007


Yes it's possible to call the FDO utility functions, as long as we decide that the provider should do most of the work. Potentially it means that it may fetch more stuff from the database than it has to, only to reject it when evaluating the filter on the client side. The FDO utility functions are also not terribly fast (they involve object construction, and some of the loops over segments are quadratic time, IIRC), so it's really a pick your poison situation.

The function call you need is this one:

static bool FdoSpatialUtility::Evaluate(FdoIGeometry* g1, FdoSpatialOperations op, FdoIGeometry* g2);

While this is simple enough, there will be some setup (perhaps 30-40 lines of code) to convert the feature and query WKB arrays to be FdoIGeometry objects.


You will need to link to FdoGeometry and FdoSpatial, which the provider currently does not, since it does geometry conversion by itself.


Traian


P.S. Here is an approximation to the code that would do it:


    int fgfLen = "the length of the feature geometry array in bytes";
    const FdoByte* fgf = "the feature geometry, converted to FGF";

    FdoPtr<FdoExpression> exprRight = filter.GetGeometry();
    FdoGeometryValue* gvRight = (FdoGeometryValue*)(exprRight.p);
    
    FdoPtr<FdoByteArray> baRight = gvRight->GetGeometry();

    FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
    FdoPtr<FdoIGeometry> geomRight = gf->CreateGeometryFromFgf(baRight);
    FdoPtr<FdoIGeometry> geomLeft = gf->CreateGeometryFromFgf(fgf, fgfLen);

    //call on the geometry utility to evaluate the spatial operation
    bool ret = FdoSpatialUtility::Evaluate(geomLeft, filter.GetOperation(), geomRight);
    

This probably has to be called from the OgrFeatureReader::ReadNext() function. When it gets a new feature from OGR, it applies the intersects filter to it, and if it fails, it moves on to the next OGR feature.









From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Kenneth, GEOGRAF A/S
Sent: Thursday, June 14, 2007 10:06 AM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] OGR / GEOS selection problem

Ok, I poked around, and found out that the "&&" operator means BBOX overlap.
So, to fix OGR, I changed ogrpgtablelayer.cpp line 449 from:

    m_poFilterGeom->getEnvelope( &sEnvelope );        
    osWHERE.Printf("WHERE %s && SetSRID('BOX3D(%.12f %.12f, %.12f %.12f)'::box3d,%d) ",
                  pszGeomColumn,
                  sEnvelope.MinX, sEnvelope.MinY,
                  sEnvelope.MaxX, sEnvelope.MaxY,
                  nSRSId );
to:
   m_poFilterGeom->getEnvelope( &sEnvelope );  
   char * pszWKT = NULL;

   if( m_poFilterGeom->exportToWkt( &pszWKT ) != OGRERR_NONE )
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Could not export geometry to WKT");

        osWHERE.Printf("WHERE %s && SetSRID('BOX3D(%.12f %.12f, %.12f %.12f)'::box3d,%d) AND intersects(%s, GeometryFromText('%s', %d)) ",
                       pszGeomColumn,
                       sEnvelope.MinX, sEnvelope.MinY,
                       sEnvelope.MaxX, sEnvelope.MaxY,
                       nSRSId,
                       pszGeomColumn,
                       pszWKT,
                       nSRSId
                       );
        CPLFree( pszWKT );

And it works fine, BUT looking at other providers (ea. MySQL) reveals that this is a general flaw:
        sprintf( szWHERE, 
                 "WHERE MBRIntersects(GeomFromText('%s'), %s)", 
                 szEnvelope, 
                 pszGeomColumn); 

This may also be fixed, but it seems that this is more a design choice from OGR, rather than a flaw.

Traian mentioned that there is utility functions in Fdo to check for intersections.
A real fix would be to update the OGRFeatureReader (in the provider), to filter out elements that do not intersect, using Fdo utility functions.

I'm not that well into Fdo yet, so I don't know where to look for those functions.


Regards, Kenneth, GEOGRAF A/S



Kenneth, GEOGRAF A/S skrev: 
It should not work if you make a polygon selection.
Tooltip and Click sends a square, so the envelope of the filter should be the same as the filter

Regards, Kenneth, GEOGRAF A/S

  


Traian Stanev skrev: 
 
Wait, from this it looks like it takes the BBOX (envelope) of the filter and sends that to PostGIS...? That may explain things.
 
 
 
-----Original Message----- 
From: mapguide-users-bounces at lists.osgeo.org on behalf of Kenneth, GEOGRAF A/S 
Sent: Wed 6/13/2007 5:42 PM 
To: MapGuide Users Mail List 
Cc: 
Subject: Re: [mapguide-users] OGR / GEOS selection problem
It is actually forwarded to PostGIS:

        OGREnvelope  sEnvelope;

        m_poFilterGeom->getEnvelope( &sEnvelope );
        osWHERE.Printf("WHERE %s && SetSRID('BOX3D(%.12f %.12f, %.12f %.12f)'::box3d,%d) ",
                       pszGeomColumn,
                       sEnvelope.MinX, sEnvelope.MinY,
                       sEnvelope.MaxX, sEnvelope.MaxY,
                       nSRSId );


Not too good with PostGIS syntax, but since the m_poFilterGeom is the filter used (a small square in this case) it reads:
"Select from geometry_column where features are within the bbox of the filer"

Which should be quite ok, unless they have a similar idea of optimizing this to a BBOX test, as OGR does.

Anyway, I can confirm that Traians fix works with MapInfo TAB files, but NOT with PostGIS :(


Regards, Kenneth, GEOGRAF A/S
    


Traian Stanev skrev: 
To put test data into PostGres I use the tool that comes with it that
can import SHP files into the database.

I think it's called shp2pgsql.


Traian


-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Kenneth,
GEOGRAF A/S
Sent: Wednesday, June 13, 2007 3:21 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] OGR / GEOS selection problem

I tried it with MapInfo TAB files, and it works fine.

Maciej, can you post an SQL dump of one of the PostGIS tables?

I have installed PostGIS on my machine for testing, but I have no data, 
and no luck getting Fdo2Fdo working with FDO OGR.

Regards, Kenneth, GEOGRAF A/S



Traian Stanev skrev:
  
Well, I only tried it with SHP files and am pretty sure it fixed the
problem for SHP files (I did a before and after test, on a polygon
    
that
  
had the same problem as your screenshot). May be the PostGIS OGR
    
driver
  
does something else, like forward the spatial filter to PostGIS? In
    
that
  
case, may be I need to upgrade my PostGIS SDK...? Anybody know the
answer to that one?


Traian


-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Maciej
Skorczewski
Sent: Wednesday, June 13, 2007 12:29 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] OGR / GEOS selection problem

Traian


i have still this same error...

take a look on screen.

http://imagepolis.com/images/20070613819095046.JPG

http://imagepolis.com/images/20070613818181055.JPG

http://imagepolis.com/images/20070613434408347.JPG


Maciek

ps. and i still can't use SetSelectionXML...

    
http://www.nabble.com/SetSelectionXML-on-layer-from-database-%28PostgreS
  
QL-%3EPostgGIS%29-tf3900386s16610.html

(tiny of this url to forum)
http://tiny.pl/fdtn


maciek skorczewski



_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
  
    
_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
  
________________________________________

_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
  

________________________________________

_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
  




More information about the mapguide-users mailing list