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

Steve Lime Steve.Lime at dnr.state.mn.us
Thu Jul 23 14:23:29 EDT 2009


MapServer doesn't do two queries although it does request the records twice from the data
source. The first query actually executes your SQL. This builds the list of ids. MapServer then
runs through that list asking for each feature in turn based on the ids already gathered. 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

>>> 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