我有一个用c#mapscript制作的动态生成的mapfile,定义如下:
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
我尝试查询ByPoint以检索附近形状的索引。在下面的代码中,我使用固定点而不是参数传递的点进行了特定的测试功能,所以我确信我使用的点实际上是功能的一部分。在我的例子中,我使用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。从我在网上的搜索,一切似乎都没问题。有什么想法吗?
答案 0 :(得分:3)
好的,第二次尝试:querybypoint函数需要地图投影中的查询点,而不是图层的投影。
答案 1 :(得分:0)
你的图层有投影lonlat,但UNITS METERS。从图层中删除它或将其更改为DD。
答案 2 :(得分:0)
我认为你必须先打开一个图层才能从中获取功能:
open():void 打开底层。这在操作之前是必需的 getFeature()可以工作,但不是 在抽奖或查询电话之前需要。