[mapguide-users] OGR / GEOS selection problem

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


Ok, I fixed it for all providers, using the GDal / GEOS intersects 
operation.
Update OGRFeatureReader::ReadNext(...) to:

bool OgrFeatureReader::ReadNext()
{   
    m_sprops.clear();
   
    if (m_poFeature)
        OGRFeature::DestroyFeature(m_poFeature);
   
    m_poFeature = m_poLayer->GetNextFeature();

    //Ugly hack to fix broken providers, with BBOX only testing
    OGRGeometry* spfilter = m_poLayer->GetSpatialFilter();
    if (spfilter != NULL)
        while (m_poFeature != NULL && m_poFeature->GetGeometryRef() != 
NULL && !spfilter->Intersects(m_poFeature->GetGeometryRef()))
        {
            OGRFeature::DestroyFeature(m_poFeature);
            m_poFeature = m_poLayer->GetNextFeature();
        }

    return (m_poFeature != NULL);
}

That will work for all the providers, but has a slight overhead as the 
features are transfered from the datasource (eg. database) before testing.
Fixing the OGR provider would be better, but out of the MapGuide scope.

Also, the skewing fix can now be disabled, but does no harm.

While I was testing the PostGIS provider, I got annoyed with the lack of 
error messages.
You can update the code to this:

FdoConnectionState OgrConnection::Open()
{
    const wchar_t* dsw = GetProperty(PROP_NAME_DATASOURCE);
    bool readonly = _wcsnicmp(GetProperty(PROP_NAME_READONLY), L"TRUE", 
4) == 0;
   
    W2A(dsw);
   
    printf ("Attempt OGR connect to %s \n", mbdsw);
    printf ("ReadOnly %d\n", (int)readonly);
   
    m_poDS = OGRSFDriverRegistrar::Open(mbdsw, !readonly);
    if( m_poDS == NULL )
    {
        std::string str = "Connect failed: ";
        str.append(CPLGetLastErrorMsg());
        const char* x = str.c_str();
        A2W(x);
        throw FdoConnectionException::Create(wx);
    }
   
    m_connState = FdoConnectionState_Open;
   
    return m_connState;
}

This will give the user a slight hint about the problem (eg, bad 
connectionstring, username etc.)

Regards, Kenneth, GEOGRAF A/S




Traian Stanev skrev:
>
>  
>
> Sure, but the actual geometric operation is what matters. If it ends 
> up doing a BBOX, it would not be right. It needs to do Intersects.
>
>  
>
>  
>
>  
>
> *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 4:15 AM
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] OGR / GEOS selection problem
>
>  
>
> 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
>     <mailto: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>
>
>     [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>
>
>         [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 <mailto:mapguide-users at lists.osgeo.org>
>
>         http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>          
>
>          
>
>         _______________________________________________
>
>         mapguide-users mailing list
>
>         mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
>
>         http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>           
>
>             
>
>     _______________________________________________
>
>     mapguide-users mailing list
>
>     mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
>
>     http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>      
>
>      
>
>     _______________________________________________
>
>     mapguide-users mailing list
>
>     mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
>
>     http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>       
>
>  
> ------------------------------------------------------------------------
>
>
>   
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto: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/15c9e128/attachment.html


More information about the mapguide-users mailing list