[mapserver-users] Function "queryByRect(rectObj rect)" not working correctly

"tschobber tschöbbi" tschobber at gmx.at
Tue Jun 15 02:59:29 PDT 2010


Hi mailing list,

I have a problem concerning the Mapserver function "queryByRect(rectObj rect)" or the function "getResult". The method returns the wrong results or rather shapes or something is wrong with the mapfile (see attachment). The strange part is that the amount of shapes selected is correct but the shapes selected aren't correct - important is that if I use the function "whichShapes" the shapes are selected correctly.

The first php code snippet shows a part of the method that gets wrong results. The second has the same effect but is using the function "whichShapes" and "nextShape" and the results are correct.



CODE1:

[PHP]

.
.
.

$map->queryByRect($oGeorefRect);//$oGeorefRect is a rectObj 

$oLayer = $map->GetLayerByName($querylayer_in);//$querylayer_in = see mapfile layer "layer_xxx_100614_694d5fb11c67415"

$numResults = $oLayer->getNumResults();

for ($iRes=0; $iRes < $numResults; $iRes++) {
		
$oRes = $oLayer->getResult($iRes);
$oLayer->getFeature($oRes->shapeindex);

.
.
.

[/PHP]


CODE2:

[PHP]

.
.
.

$map->queryByRect($oGeorefRect);//$oGeorefRect is a rectObj 

$oLayer = $map->GetLayerByName($querylayer_in);//$querylayer_in = see mapfile layer "layer_xxx_100614_694d5fb11c67415"

$numResults = $oLayer->getNumResults();
$status = $oLayer->open();
$oLayer->whichShapes($oGeorefRect);

while($oShape = $oLayer->nextShape()) {

.
.
.

[/PHP]

What's the difference between those functions? Why is one working and the other not?

Thanks for answers.

Greetings,

Martin
-- 
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.  
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl
-------------- next part --------------
MAP
  EXTENT 100576.796875 265258 699423.203125 594238
  FONTSET "../data/fonts/fonts.txt"
  IMAGECOLOR 255 255 255
  IMAGETYPE AGGA
  SYMBOLSET "../includes/sys.sym"
  SHAPEPATH "../data"
  SIZE 700 385
  STATUS ON
  UNITS METERS
  CONFIG MS_ERRORFILE "/tmp/ms_error.txt"
  NAME "xxxxyyyy"

  DEBUG 1
  OUTPUTFORMAT
    NAME "AGGA"
    MIMETYPE "image/png"
    DRIVER "AGG/PNG"
    EXTENSION "png"
    IMAGEMODE "RGBA"
    TRANSPARENT TRUE
    FORMATOPTION "TRANSPARENT=ON"
  END

  OUTPUTFORMAT
    NAME "gif"
    MIMETYPE "image/gif"
    DRIVER "GD/GIF"
    EXTENSION "gif"
    IMAGEMODE "PC256"
    TRANSPARENT FALSE
  END

  OUTPUTFORMAT
    NAME "png"
    MIMETYPE "image/png"
    DRIVER "GD/PNG"
    EXTENSION "png"
    IMAGEMODE "PC256"
    TRANSPARENT FALSE
  END

  OUTPUTFORMAT
    NAME "png24"
    MIMETYPE "image/png"
    DRIVER "GD/PNG"
    EXTENSION "png"
    IMAGEMODE "RGB"
    TRANSPARENT FALSE
    FORMATOPTION "INTERLACE=OFF"
  END

  OUTPUTFORMAT
    NAME "jpeg"
    MIMETYPE "image/jpeg"
    DRIVER "GD/JPEG"
    EXTENSION "jpg"
    IMAGEMODE "RGB"
    TRANSPARENT FALSE
    FORMATOPTION "QUALITY=100"
  END

  OUTPUTFORMAT
    NAME "imagemap"
    MIMETYPE "text/html"
    DRIVER "imagemap"
    EXTENSION "html"
    IMAGEMODE "PC256"
    TRANSPARENT FALSE
  END

  PROJECTION
    "init=epsg:31297"
  END
  LEGEND
    IMAGECOLOR 255 255 255
    KEYSIZE 20 10
    KEYSPACING 5 5
    LABEL
      SIZE MEDIUM
      TYPE BITMAP
      BUFFER 0
      COLOR 0 0 0
      FORCE FALSE
      MINDISTANCE -1
      MINFEATURESIZE -1
      OFFSET 0 0
      PARTIALS TRUE
    END
    POSITION LL
    STATUS OFF
  END

  QUERYMAP
    COLOR 255 0 0
    SIZE -1 -1
    STATUS ON
    STYLE HILITE
  END

  REFERENCE
    COLOR -1 -1 -1
    EXTENT 105000 265258 695000 594238
    IMAGE "../img/keymap_0.png"
    OUTLINECOLOR 255 0 0
    SIZE 153 84
    STATUS ON
      MARKER 0
      MARKERSIZE 0
      MINBOXSIZE 3
      MAXBOXSIZE 0
  END

  SCALEBAR
    ALIGN CENTER
    BACKGROUNDCOLOR 255 255 255
    COLOR 50 50 50
    IMAGECOLOR 255 255 255
    INTERVALS 4
    LABEL
      SIZE TINY
      TYPE BITMAP
      BUFFER 0
      COLOR 50 50 50
      FORCE FALSE
      MINDISTANCE -1
      MINFEATURESIZE -1
      OFFSET 0 0
      PARTIALS TRUE
    END
    OUTLINECOLOR 50 50 0
    POSITION LR
    POSTLABELCACHE TRUE
    SIZE 120 2
    STATUS OFF
    STYLE 0
    UNITS KILOMETERS
  END

  WEB
    IMAGEPATH "/tmp/ms_tmp/"
    IMAGEURL "/ms_tmp/"
    MAXSCALEDENOM 3e+06
    MINSCALEDENOM 100000
    QUERYFORMAT text/html
    LEGENDFORMAT text/html
    BROWSEFORMAT text/html
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_line_002"
    NAME "xxx_01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE LINE
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 66 66 66
        SIZE 1
        SYMBOL 1
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_line_001"
    NAME "xxx01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE LINE
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 99 99 99
        SIZE 2
        SYMBOL 1
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_line_004"
    NAME "xxy01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE LINE
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 99 99 99
        SIZE 2
        SYMBOL 1
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_line_007_3"
    NAME "fluss01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 107 174 214
        SIZE 1
        SYMBOL 1
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_poly_004"
    NAME "xyy01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE POLYGON
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 189 215 231
        OUTLINECOLOR 107 174 214
        SYMBOL 0
        WIDTH 1
      END
    END
  END

  LAYER
    CLASSITEM "value"
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from (SELECT gd_point_073.the_geom,gd_point_073.id as id, td_dim_geom.name as name,gd_point_073.oid,sum(td_theme_at_uba_ozon.value) as value FROM gd_point_073,td_theme_at_uba_ozon, td_dim_geom WHERE td_dim_geom.id = gd_point_073.id   AND gd_point_073.id = td_theme_at_uba_ozon.geom AND (td_theme_at_uba_ozon.year = '2004' ) AND (td_theme_at_uba_ozon.uba_ozon_type = 'jmw' ) GROUP BY gd_point_073.id,gd_point_073.the_geom,td_dim_geom.name,gd_point_073.oid  order by value desc) as foo using unique oid USING SRID=31297;"
    METADATA
      "LAYER_NAME"	"layer_xxx_100614_694d5fb11c67415"
      "DESCRIPTION"	"OZON, Jahresmittelwert"
      "GEOM_NAME"	"gd_point_073"
      "RESULT_FIELDS"	"id"
      "QUERY_TABLE"	"td_theme_at_uba_ozon"
    END
    NAME "layer_xxx_100614_694d5fb11c67415"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TOLERANCE 10
    TYPE POINT
    UNITS METERS
    CLASS
      NAME "≤ 40"
      EXPRESSION ([value] <= 40)
      STYLE
        ANGLE 360
        COLOR 171 221 164
        OUTLINECOLOR 30 30 30
        SIZE 10
        SYMBOL 1
        WIDTH 1
      END
      TEMPLATE "xxx"
    END
    CLASS
      NAME "> 40 - 50"
      EXPRESSION ([value] > 40 and [value] <= 50)
      STYLE
        ANGLE 360
        COLOR 171 221 164
        OUTLINECOLOR 30 30 30
        SIZE 16
        SYMBOL 1
        WIDTH 1
      END
      TEMPLATE "xxx"
    END
    CLASS
      NAME "> 50 - 60"
      EXPRESSION ([value] > 50 and [value] <= 60)
      STYLE
        ANGLE 360
        COLOR 171 221 164
        OUTLINECOLOR 30 30 30
        SIZE 22
        SYMBOL 1
        WIDTH 1
      END
      TEMPLATE "xxx"
    END
    CLASS
      NAME "> 60 - 70"
      EXPRESSION ([value] > 60 and [value] <= 70)
      STYLE
        ANGLE 360
        COLOR 171 221 164
        OUTLINECOLOR 30 30 30
        SIZE 28
        SYMBOL 1
        WIDTH 1
      END
      TEMPLATE "xxx"
    END
    CLASS
      NAME "> 70"
      EXPRESSION ([value] > 70)
      STYLE
        ANGLE 360
        COLOR 171 221 164
        OUTLINECOLOR 30 30 30
        SIZE 34
        SYMBOL 1
        WIDTH 1
      END
      TEMPLATE "xxx"
    END
  END

  LAYER
    CLASSITEM "value"
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from (SELECT gd_point_006.the_geom,gd_point_006.id as id, td_dim_geom.name as name,gd_point_006.oid,td_theme_at_topo_orte2.value as value FROM gd_point_006,td_theme_at_topo_orte2, td_dim_geom WHERE td_dim_geom.id = gd_point_006.id  AND td_dim_geom.id = td_theme_at_topo_orte2.geom AND td_dim_geom.id = gd_point_006.id AND (td_theme_at_topo_orte2.orte_type = 'class1' )  order by value desc) as foo using unique oid USING SRID=31297;"
    NAME "yyy01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE POINT
    UNITS METERS
    CLASS
      NAME "Bedeutende Stadt im Ausland"
      EXPRESSION "9"
      STYLE
        ANGLE 360
        COLOR 200 200 200
        OUTLINECOLOR 30 30 30
        SIZE 7
        SYMBOL 1
        WIDTH 1
      END
    END
    CLASS
      NAME "Bezirkshauptstadt"
      EXPRESSION "2"
      STYLE
        ANGLE 360
        COLOR 255 255 255
        OUTLINECOLOR 30 30 30
        SIZE 7
        SYMBOL 1
        WIDTH 1
      END
    END
    CLASS
      NAME "Landeshauptstadt"
      EXPRESSION "1"
      STYLE
        ANGLE 360
        COLOR 255 255 255
        OUTLINECOLOR 30 30 30
        SIZE 7
        SYMBOL 2
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from gd_line_006"
    NAME "xyx01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    OPACITY 75
    TYPE LINE
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 99 99 99
        SIZE 1
        SYMBOL 1
        WIDTH 1
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from (select gd_point_005_label.the_geom,gd_point_005_label.id,gd_point_005_label.oid,td_dim_geom.name from gd_point_005_label,td_dim_geom where gd_point_005_label.id = td_dim_geom.id) as foo using unique oid USING srid=31297"
    LABELITEM "name"
    NAME "blub"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE ANNOTATION
    UNITS METERS
    CLASS
      NAME "class0"
      LABEL
        ANGLE 0.000000
        ANTIALIAS TRUE
        FONT "arial"
        MAXSIZE 256
        MINSIZE 4
        SIZE 8
        TYPE TRUETYPE
        BUFFER 1
        COLOR 0 0 0
        FORCE FALSE
        MINDISTANCE 1
        MINFEATURESIZE -1
        OFFSET 0 0
        OUTLINECOLOR 255 255 255
        PARTIALS FALSE
        POSITION CC
      END
    END
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from (select gd_point_006.the_geom,gd_point_006.id,gd_point_006.oid,td_dim_geom.name from gd_point_006,td_dim_geom where gd_point_006.id = td_dim_geom.id) as foo using unique oid USING srid=31297"
    LABELITEM "name"
    NAME "blub01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    TYPE ANNOTATION
    UNITS METERS
    CLASS
      NAME "class0"
      LABEL
        ANGLE 0.000000
        ANTIALIAS TRUE
        FONT "arial"
        MAXSIZE 256
        MINSIZE 4
        SIZE 8
        TYPE TRUETYPE
        BUFFER 1
        COLOR 0 0 0
        FORCE FALSE
        MINDISTANCE 1
        MINFEATURESIZE -1
        OFFSET 0 -9
        OUTLINECOLOR 255 255 255
        PARTIALS FALSE
        POSITION CC
      END
    END
  END

  LAYER
    DATA "gd_raster_001.tif"
    NAME "test01"
    PROJECTION
      "init=epsg:31297"
    END
    STATUS ON
    OPACITY 15
    TYPE RASTER
    UNITS METERS
  END

  LAYER
    CONNECTION "user=xxx password=xxx dbname=xxx host=localhost"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from (select gd_point_073.the_geom,gd_point_073.id,gd_point_073.oid from gd_point_073,sys_select_data where gd_point_073.id = sys_select_data.geom and sys_select_data.id='any_100614_694d5fbc4fe2e9' ) as foo using unique oid USING srid=31297"
    NAME "QUERY_xxx"
    STATUS ON
    OPACITY 70
    TYPE POINT
    UNITS METERS
    CLASS
      NAME "class0"
      STYLE
        ANGLE 360
        COLOR 222 20 20
        OUTLINECOLOR 100 0 0
        SIZE 5
        SYMBOL 1
        WIDTH 1
      END
    END
  END

END


More information about the MapServer-users mailing list