[mapserver-dev] A problem with NQUERY and OGR datasources

Brent Fraser bfraser at geoanalytic.com
Thu Jul 23 15:25:51 EDT 2009


See embedded comments...

Steve Lime wrote:
> MapServer doesn't do two queries although it does request the records twice from the data
> source. The first query actually executes your SQL. 

And this request has a spatial filter applied in the form of an extent.


> This builds the list of ids. MapServer then
> runs through that list asking for each feature in turn based on the ids already gathered. 

I don't have GDAL built for debug (that's next) but I suspect it does another query.
 From line 1941 of mapogr.cpp:

       msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
	:
       return msOGRFileGetShape(layer, shape, record, psInfo );

where psInfo has a rect structure, but is not assigned extent values (although 
I'm not sure it has to).  I need to do another debugging session...


> The
> second set can be really expensive depending on data source (hence the upcoming improvements
> in that area).
> 
> Anyway, seems to me that whatever ids OGR are returning as part of the query are not sufficient
> to retrieve a specific shape again. With shapefiles the id is just a shape index (0th shape, 1st shape,
> etc...). PostGIS forces you to define a unique integer key (e.g. OID). Not sure what OGR requires.
> 
> Steve


Good point.  I tried to use my UWI column (defined as VARCHAR) as the OGR FID, 
but I think it expects an integer.

ogrinfo with no <FID> in vrt, first record:

OGRFeature(vWM_wells_v1):0  <----------------- interesting!
   UWI (String) = 100041000108W400
   WELL_NAME (String) = MCCOLL-FRONTENAC-UNION WELL 4-10-1-8
   CUR_STS_TX (String) = DRY
   SRF_LAT (Real) = 49.015901
   SRF_LONG (Real) = -111.003801
   GEOM (String) = Point( -111.003801    49.015901)
   POINT (-111.00380100000001 49.015900999999999 0)


ogrinfo with <FID>UWI</FID> in vrt, first record:

OGRFeature(vWM_wells_v1):1256752300    <------- interesting!
   UWI (String) = 100041000108W400
   WELL_NAME (String) = MCCOLL-FRONTENAC-UNION WELL 4-10-1-8
   CUR_STS_TX (String) = DRY
   SRF_LAT (Real) = 49.015901
   SRF_LONG (Real) = -111.003801
   GEOM (String) = Point( -111.003801    49.015901)
   POINT (-111.00380100000001 49.015900999999999 0)


  This might not be a bug, but it's definitely a documentation opportunity!

Thanks!
Brent

> 
>>>> On 7/23/2009 at 1:00 PM, in message <4A68A534.7030501 at geoanalytic.com>, Brent
> Fraser <bfraser at geoanalytic.com> wrote:
> 
>> The problem:
>> ------------
>>    When using doing an NQUERY with a MAPSHAPE on a point layer with a 
>> connection 
>> of OGR/VRT/ODBC/SQLServer and geometry defined as WKT, I get the wrong 
>> records 
>> returned (but I always get the right NUMBER of records).  Changing the 
>> geometry to:
>>      <GeometryField encoding='PointFromColumns' x='SRF_LONG' y='SRF_LAT'/>
>> gives the same wrong results so its not restricted to WKT.
>>
>>    However, adding my own "spatial filter" in the OGR connection
>>
>>      <SrcSQL>SELECT * from vWM_wells_v1 WHERE
>>         SRF_LONG &gt; %VIEW_MIN_LONG% AND SRF_LONG &lt; %VIEW_MAX_LONG% AND
>>         SRF_LAT  &gt; %VIEW_MIN_LAT%  AND SRF_LAT  &lt; %VIEW_MAX_LAT%
>>      </SrcSQL>
>>
>> gives the right results.
>>
>>
>> The cause?:
>> ---------------
>>    I suspect this is due to mapserver asking OGR to do two queries for 
>> NQUERY 
>> (or any other type of template-related query).  The first query is to get a 
>> list 
>> of record ids after applying the spatial filter.  The second is in 
>> msReturnTemplateQuery to get the attributes for the records, but no spatial 
>> filter appears to be applied.  So for example the 21st record in the second 
>> query is actually different than the 21st record in the first query.
>>
>>    My debug session was rather hurried so I may have missed something.  Is 
>> this 
>> a known problem?
>>
>> My config:
>> ----------
>> MapServer version 5.2.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP 
>> OUTPUT=PDF
>>   OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE 
>> SUPPORTS=WMS_SERVER
>>   SUPPORTS=THREADS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL 
>> INPUT=SHAPEFILE
>>
>> C:\ms4w\Apache\cgi-bin>ogrinfo  --version
>> GDAL 1.6.0, released 2008/12/04
>>
>> Best Regards,
>> Brent Fraser
>>
>>
>>
>> _______________________________________________
>> mapserver-dev mailing list
>> mapserver-dev at lists.osgeo.org 
>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
> 
> 


More information about the mapserver-dev mailing list