我有一个用 c# mapscript 制作的动态生成的 map 文件,其定义如下:
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 检索附近的形状的索引。在下面的代码中,我使用固定点而不是通过参数传递的点制作了一个特定的测试函数,因此我确定我使用的点实际上是功能的一部分。就我而言,我使用 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;
}
我有一个虚拟的 TEMPLATE 集,我什至不必使用容差,因为该点是正确的形状,但 queryByPoint 不断返回给我 MS_FAILURE。从我在网上的搜索来看,一切似乎都很好。任何想法?
最佳答案
好的,第二次尝试:querybypoint 函数需要 map 投影中的查询点,而不是图层的投影。
关于c# - Mapscript queryByPoint 不返回结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2229025/