[mapguide-users] OGR / GEOS selection problem

Kenneth, GEOGRAF A/S ks at geograf.dk
Thu Jun 14 10:06:14 EDT 2007


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
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070614/33e3684f/attachment.html


More information about the mapguide-users mailing list