首页 / 浏览问题 / 组件GIS / 问题详情
鼠标点击,在网络数据集上显示点
23EXP 2018年08月01日

在替换了示例代码 realspace   pathanalysis中的网络数据集后,鼠标点击选择结束点总是显示  请在50米内显示点。是不是和新的网络数据集要设置什么属性有关,下面的Add里好像加不到东西。

            // 获取相交的几何对象
            Recordset networkRecordset = m_networkDataset.GetRecordset(false, CursorType.Static);
            networkRecordset.MoveFirst();
            while (!networkRecordset.IsEOF)
            {
                Geometry geometry = networkRecordset.GetGeometry();
                if (geometry.HitTest(clickPoint2D, tolerence))
                {
                    hitGeometrys.Add(geometry); 
                }
                networkRecordset.MoveNext();
            }

imageimage.net.net   X86

 

2 个回答

您好!请您利用断点查询哪里不符合条件进行排查。据我所知“请在50米内显示点”是if...else...语句里的else输出的结果,说明你if语句里设置的条件不达标。
3,352EXP 2018年08月01日
嗯嗯嗯,我去看看
/// 返回给定点到网络数据集的最近点
        public Point2D NetworkHitTest(Point3D clickPoint, Double tolerence)
        {
            Point2D clickPoint2D = new Point2D(clickPoint.X, clickPoint.Y);
            List<Geometry> hitGeometrys = new List<Geometry>();
            Geometry hitGeometry = null;
            Point2D resultPoint2D = Point2D.Empty; ;

            // 获取相交的几何对象
            Recordset networkRecordset = m_networkDataset.GetRecordset(false, CursorType.Static);
            networkRecordset.MoveFirst();
            while (!networkRecordset.IsEOF)
            {   
                Geometry geometry = networkRecordset.GetGeometry();
                if (geometry.HitTest(clickPoint2D, tolerence))
                {
                    hitGeometrys.Add(geometry);
                }
                networkRecordset.MoveNext();
            }

            // 取点到道路距离最短的道路
            if (hitGeometrys.Count > 0)
            {
                hitGeometry = hitGeometrys[0];
                Double distance = Geometrist.Distance(hitGeometry, new GeoPoint(clickPoint2D));
                foreach (Geometry geometry in hitGeometrys)
                {
                    Double distance2 = Geometrist.Distance(geometry, new GeoPoint(clickPoint2D));
                    if (distance2 < distance)
                    {
                        distance = distance2;
                        hitGeometry = geometry;
                    }
                }
            }

            if (hitGeometry != null)
            {
                GeoLine line = hitGeometry as GeoLine;
                resultPoint2D = Geometrist.ComputePerpendicularPosition(clickPoint2D, line[0][0], line[0][1]);
            }

            networkRecordset.Dispose();

            return resultPoint2D;
        }
是因为samplerun类里的这个函数里的hitGeometrys.Count=0

cryingcrying恳求帮助

您好!您在场景中画站点能画上不?您的站点离网络数据集中的路线的距离有多远呢?感觉没有获取到您在场景中点击的那个点,您可以将容限改大一些。
不行啊,容限改的超级大也不行。你所说的站点是什么意思,不是很明白。
远程我看看,给我QQ发个消息
没用过.NET组件,我猜可能是容限的原因,就是那个tolerence。你是用自己的数据集替换了范例的数据集吗?

可能是两者的坐标系单位不同,导致的这个问题,你可以在桌面里右键数据集属性看看坐标系单位,或者改大容限试试。
698EXP 2018年08月01日
嗯嗯我去试试看
...