Mapscript queryByPoint return no results

Posted by lucian.jp on Stack Overflow See other posts from Stack Overflow or by lucian.jp
Published on 2010-02-09T12:42:42Z Indexed on 2010/05/09 0:38 UTC
Read the original article Hit count: 373

Filed under:
|
|

I have a dynamically generated mapfile made with c# mapscript that is defined like:

MAP
  EXTENT 5.91828 45.63552 5.92346 45.65051
  IMAGECOLOR 192 192 192
  IMAGETYPE png
  SIZE 256 256
  STATUS ON
  TRANSPARENT TRUE
  UNITS METERS
  NAME "GMAP_TILE"

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

  SYMBOL
    NAME "circle"
    TYPE ELLIPSE
    FILLED TRUE
    POINTS
      1 1
    END
  END

  SYMBOL
    NAME ">"
    TYPE TRUETYPE
    ANTIALIAS TRUE
    CHARACTER ">"
    GAP -20
    FONT "arial"
    POSITION CC
  END

  PROJECTION
    "proj=merc"
    "a=6378137"
    "b=6378137"
    "lat_ts=0.0"
    "lon_0=0.0"
    "x_0=0.0"
    "y_0=0"
    "units=m"
    "k=1.0"
    "nadgrids=@null"
  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 255 0
    SIZE -1 -1
    STATUS ON
    STYLE HILITE
  END

  SCALEBAR
    ALIGN CENTER
    COLOR 0 0 0
    IMAGECOLOR 255 255 255
    INTERVALS 4
    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
    SIZE 200 3
    STATUS OFF
    STYLE 0
    UNITS MILES
  END

  WEB
    IMAGEPATH ""
    IMAGEURL ""
    QUERYFORMAT text/html
    LEGENDFORMAT text/html
    BROWSEFORMAT text/html
  END

  LAYER
    NAME "Troncons"
    PROJECTION
      "proj=longlat"
      "ellps=WGS84"
      "datum=WGS84"
    END
    STATUS DEFAULT
    TEMPLATE "nofile.html"
    TOLERANCE 100
    TOLERANCEUNITS METERS
    TYPE LINE
    UNITS METERS
    CLASS
      NAME "Troncons"
      STYLE
        ANGLE 360
        COLOR 0 0 255
        SIZE 5
        SYMBOL "circle"
        WIDTH 5
      END
      STYLE
        ANGLE 360
        COLOR 0 0 0
        SIZE 12
        SYMBOL ">"
        WIDTH 1
      END
    END
    FEATURE
      POINTS
        5.91828 45.63552
        5.91876 45.63611
        5.91898 45.6364
        5.91936 45.63701
        5.91952 45.63731
        5.91968 45.63762
        5.91993 45.63825
        5.92003 45.63856
        5.92018 45.63919
        5.92028 45.63983
        5.92031 45.64014
        5.92033 45.64046
        5.92034 45.64077
        5.92034 45.64108
        5.92034 45.64171
        5.92035 45.64234
        5.92035 45.6428
        5.92037 45.6433
        5.9204 45.64394
        5.92046 45.64458
        5.92056 45.64522
        5.92062 45.64554
        5.92069 45.64586
        5.92077 45.64617
        5.92097 45.64679
        5.92122 45.64739
        5.92136 45.64769
        5.92169 45.64828
        5.92207 45.64886
        5.92228 45.64914
        5.92272 45.64969
        5.92321 45.65023
        5.92346 45.65051
      END
    END
  END
END

I try to queryByPoint to retreive the index of the shape clciked near. In the code below I made a specific test function with fixed point instead of points passed by parameter so I am sure the point I use is actually part of a feature. In my case I use the first point of the only feature contained in mapfile.

public string GetTronconId()
    {
        //_map is my dynamically created mapObj
        if (_map != null)
            for (int i = 0; i < _map.numlayers; i++)
            {
                layerObj layer = _map.getLayer(i);
                // Code never pass this point
                if (layer.queryByPoint(_map, new pointObj(5.91898, 45.6364, 0, 0), (int) MS_QUERY_MODE.MS_QUERY_MULTIPLE, 100) == (int) MS_RETURN_VALUE.MS_SUCCESS)
                {
                    int numresults = layer.getNumResults();
                    if (numresults != 0)
                    {
                        layer.open();
                        for (int j = 0; j < numresults; j++)
                        {
                            resultCacheMemberObj resultat = layer.getResult(j);
                            shapeObj shape = null;
                            if (layer.getShape(shape, resultat.tileindex, resultat.shapeindex) == (int) MS_RETURN_VALUE.MS_SUCCESS)
                                return shape.getValue(0);
                        }
                    }
                }
            }

        return null;
    }

I have a dummy TEMPLATE set, I do not eveen have to use the tolerance since the point is derectly in a shape, but the queryByPoint keep returning me MS_FAILURE. From my searches on the web everything seem to be OK. Any idea?

© Stack Overflow or respective owner

Related posts about mapserver

Related posts about mapscript