[mapserver-users] itemfeaturequery & qstring

Ted Spradley tspradley at snoogems.com
Sat Nov 21 15:12:30 EST 2009


Hi all,

I apologize in advance for maybe supplying too much detail.  I have
highlighted my questions to try to make this post faster to look through.

I am using mode=itemfeaturequery to locate a polygon by column 'objectid' in
'slayer=parcels', then searching 'qlayer=parcels_01' which is identical to
layer 'parcels' to find all of the parcels within TOLERANCE 500,
TOLERANCEUNITS FEET.

Questions here and then in context:

1: Why doesn't changing the TOLERANCE in layer 'parcels_01' change the
number of parcels returned?
2:  What is the difference between my scenario and the Test Suite?  Besides
attempting to use TOLERANCE > 0?  And the use of FILTER?  And the Test Suite
layer being a shapefile and mine being a spatial DB?  :-)

CGI control 'qstring' appears to pass a string to be used in the WHERE
clause of the SQL query correct?

As always, many, many thanks in advance,
Ted S.


I have encountered two obstacles:

1. My understanding of TOLERANCE and TOLERANCEUNITS - The returned results
are not as expected.  Using units FEET, the returned/mapped records are
identical as long as the value of TOLERANCE is > 0.

Here is the url query:
http://url.com/cgi-bin/mapserv?
qstring=objectid+%3D+1019608  (qstring=objectid = 1019608) ** this is the
subject of 2nd question
&map=/path/to/cad.map
&mode=itemfeaturequery
&slayer=parcels
&qitem=objectid
&qlayer=parcels_01
&qformat=selected_parcel
&mapext=shape
&layers=all

Here are map and layer definitions for 'parcels' and 'parcels_01'
MAP
  NAME	"CAD"	
  SIZE            800 800
  EXTENT          -125 24 -65 50
  UNITS		DD   # modifying map units changes the number of records returned
  IMAGECOLOR			100 100 255
  PROJECTION
    "init=epsg:4326"
  END

  QUERYMAP
    STATUS ON
    STYLE hilite
    COLOR 212 212 212
  END

  OUTPUTFORMAT
    NAME 'selected_parcel'
    DRIVER 'TEMPLATE'
    MIMETYPE 'text/html'
    FORMATOPTION 'FILE=selected_parcel.tmpl'
  END 

  SCALEBAR
    STATUS  embed
    INTERVALS 5
    ALIGN left
    POSITION lr
    SIZE 600 8
    UNITS feet
    COLOR 0 0 0
    BACKGROUNDCOLOR 212 212 212
  END   # End Scalebar

  LAYER
    NAME 'parcels'
    TYPE POLYGON
    STATUS          DEFAULT
    DEBUG			3
    TEMPLATE        'dummy'
    DUMP TRUE
    MAXSCALEDENOM 7000
    CONNECTIONTYPE POSTGIS
    CONNECTION "dbname=cad1 user=user password=pw host=localhost port=5432"
    DATA            "the_geom from parcels using unique gid using srid=-1"
    LABELITEM "owner_name"
    PROCESSING 'LABEL_NO_CLIP=1'
#    TOLERANCEUNITS feet  (these two parameters appear to not have any
effect in this layer)
#    TOLERANCE 500

    CLASS
      STYLE
        WIDTH 1 
        OUTLINECOLOR 0 255 0
      END
      LABEL
        COLOR 0 0 0
        TYPE TRUETYPE
        FONT ARIAL
        SIZE 10
        BUFFER 5
        MINFEATURESIZE 20
        POSITION AUTO
        ANGLE AUTO
      END
    END   # End class     
    PROJECTION
      "init=epsg:2278"
    END
    METADATA
      "wms_title" "County Property Parcels"
      "wfs_title" "County Property Parcels"
      "wms_srs"	"epsg:2278"
      "gml_include_items" "all"
      "gml_featureid" "ogc_fid" ## REQUIRED
      "qstring_validation_pattern" '.'
    END
  END # End layer 'parcels'

  LAYER
    NAME 'parcels_01'
    TYPE POLYGON
    STATUS          ON
    DEBUG			3
    TEMPLATE        'dummy'
    DUMP TRUE
    MAXSCALEDENOM 7000
    CONNECTIONTYPE POSTGIS
    CONNECTION "dbname=cad1 user=user password=pw host=localhost port=5432"
    DATA            "the_geom from parcels using unique gid using srid=-1"
    LABELITEM "owner_name"
    PROCESSING 'LABEL_NO_CLIP=1'
    TOLERANCEUNITS feet  
    TOLERANCE 1500  # The same records are returned whether this is 500 or
1500

    CLASS
      STYLE
        WIDTH 2
        COLOR 139 136 120
        OUTLINECOLOR 212 212 212
      END
      LABEL
        COLOR 0 0 0
        TYPE TRUETYPE
        FONT ARIAL
        SIZE 10
        MINFEATURESIZE 20
        POSITION AUTO
        ANGLE AUTO
      END
    END   # End class     
    PROJECTION
      "init=epsg:2278"
    END
    METADATA
      "wms_title" "County Property Parcels Comparison Layer"
      "wfs_title" "County Property Parcels Comparison Layer"
      "wms_srs"	"epsg:2278"
      "gml_include_items" "all"
      "gml_featureid" "ogc_fid" ## REQUIRED
      "qstring_validation_pattern" '.'
    END
  END # End layer 'parcels_01'

*******************************************************************************
To summarize question 1: Why doesn't changing the TOLERANCE in layer
'parcels_01' change the number of parcels returned?

*******************************************************************************

2. My understanding of qstring - 

My qstring and related qitem in the above url is:

qstring=objectid+%3D+1019608  (qstring=objectid = 1019608)
&qitem=objectid

My intuition is that it should be 'qstring=1019608' and 'qitem=objectid' -

by looking at the test suite example (modified to work with MS 5.4.1) of
mode=itemfeaturequery, there is a html select object with the name of
'qstring' and it's only values are the names of the counties.

The url query from the case3 is:

http://url.com/cgi-bin/mapserv?
mapserv=/Fcgi-bin/Fmapserv
&map=/path/to/case3.map
&imagepath=/path/to/temp/
&imageurl=/temp/
&mode=itemfeaturequery
&slayer=county
&qitem=cty_name
&qlayer=usgs100k
&qformat=selected_county
&qstring=Aitkin

The map file from case 3:

MAP
  NAME case3
  SHAPEPATH ../data
  SIZE 300 300
  EXTENT 74000 4775000 798000 5499000
  UNITS meters
    IMAGETYPE PNG24
    OUTPUTFORMAT
        NAME 'selected_county'
        DRIVER 'TEMPLATE'
        MIMETYPE 'text/html'
        FORMATOPTION 'FILE=selected_county.tmpl'
    END 

  WEB
    IMAGEPATH "/path/to/httpdocs/temp/"
    IMAGEURL "/temp/"

    HEADER case3_header.html
    FOOTER case3_footer.html
  END

  QUERYMAP
    STATUS ON
    STYLE SELECTED
    COLOR 255 255 0
  END

  SCALEBAR
    STATUS ON
    INTERVALS 3
    STYLE 1
    SIZE 200 4
    COLOR 212 212 212
    LABEL
      SIZE TINY
      COLOR 0 0 0
    END
  END

  LAYER
    NAME county
    DATA county
    STATUS DEFAULT
    TYPE POLYGON
    FILTERITEM cty_name
    FILTER "%name%"
    CLASS
      TEMPLATE 'dummy'
      COLOR 255 255 0
      OUTLINECOLOR 0 0 0
    END
    # Necessary for queries using qstring
    METADATA
	"qstring_validation_pattern" '.'
    END
  END

  LAYER
    NAME usgs100k
    DATA usgs100k
    STATUS DEFAULT
    TYPE POLYGON
    CLASS
      TEMPLATE 'dummy'
      OUTLINECOLOR 255 0 0        
    END
    TOLERANCE 0
    # Necessary for queries using qstring
    METADATA
	"qstring_validation_pattern" '.'
    END
  END  

END 
**************************************************************************
Here is the heart of my misunderstanding:  Does MS combine qstring & qitem
in the query to make 'AND qstring=Aitkin'?  Why doesn't MS complain about
that?

To summarize question 2:  What is the difference between my scenario and the
Test Suite?  Besides attempting to use TOLERANCE > 0?  And the use of
FILTER?  And the Test Suite layer being a shapefile and mine being a spatial
DB?  :-)

CGI control 'qstring' appears to pass a string to be used in the WHERE
clause of the SQL query correct?
****************************************************************************

If I change my url to correspond to the case of the test suite, it is:

http://url.com/cgi-bin/mapserv?qstring=1019608
&map=/path/to/cad.map
&mode=itemfeaturequery
&slayer=parcels
&qitem=objectid
&qlayer=parcels_01
&qformat=selected_parcel
&mapext=shape
&layers=all

And MS complains:

msPostGISLayerWhichShapes(): Query error. Error (ERROR: argument of AND must
be type boolean, not type integer LINE 1: ...0875,-6675211.21357807
11727570.9530875))',-1) and (1019608) ^ ) executing query: select
"objectid",encode(AsBinary(force_collection(force_2d("the_geom")),'NDR'),'base64')
as geom,"gid" from parcels where the_geom &&
GeomFromText('POLYGON((-6675211.21357807 11727570.9530875,-6675211.21357807
22614794.4837544,13205599.111978 22614794.4837544,13205599.111978
11727570.9530875,-6675211.21357807 11727570.9530875))',-1) and (1019608) 

Which is obvious:  PostGIS wants the end of the query to be:

'AND objectid = 1019608'

which when changed behaves as expected, returning one record with the
parcel's info from table 'parcels'.

-- 
View this message in context: http://n2.nabble.com/itemfeaturequery-qstring-tp4043863p4043863.html
Sent from the Mapserver - User mailing list archive at Nabble.com.


More information about the mapserver-users mailing list