Mapscript queryByPoint 不返回结果

发布于 2024-08-20 23:14:52 字数 4415 浏览 4 评论 0原文

我有一个用 c# mapscript 动态生成的地图文件,其定义如下:

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

我尝试 queryByPoint 来检索附近点击的形状的索引。在下面的代码中,我使用固定点而不是通过参数传递的点创建了一个特定的测试函数,因此我确信我使用的点实际上是功能的一部分。就我而言,我使用映射文件中包含的唯一功能的第一个点。

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

我有一个虚拟模板集,我什至不必使用公差,因为该点直接处于形状中,但 queryByPoint 不断返回我 MS_FAILURE。从我在网上的搜索来看,一切似乎都很好。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不即不离 2024-08-27 23:14:52

好的,第二次尝试:querybypoint 函数需要地图投影中的查询点,而不是图层的投影。

Ok, second try: the querybypoint function needs a query point in the map's projection, not the layer's projection.

怪我入戏太深 2024-08-27 23:14:52

您的图层具有投影 lonlat,但单位为米。从图层中删除它或将其更改为 DD。

Your layer has projection lonlat, but UNITS METERS. Remove that from the layer or change it to DD.

π浅易 2024-08-27 23:14:52

我认为你必须先打开一个图层才能从中获取功能:

open():无效
打开底层。在诸如此类的操作之前这是必需的
getFeature() 可以工作,但不行
在绘制或查询调用之前需要。

http://mapserver.org/mapscript/mapscript.html#layerobj

I think you must open a layer before you can get features from it:

open() : void
Opens the underlying layer. This is required before operations like
getFeature() will work, but is not
required before a draw or query call.

http://mapserver.org/mapscript/mapscript.html#layerobj

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文