ArcServer 9.3 下线性参考定位的实现。

首先要生成路径(route)数据,然后在路径(route)数据的基础上生成点事件以及线事件。

这样就可以利用esri提供的Imsegmentation接口, 通过Imsegmentation 接口的GetPointsAtM 和GetSubcurveBetweenMs 就可以找到
M 值(里程值)为某一特定值的所有点以及M值在某一特定区间内的线。以下面例子为例,实现的是管线上具有某一里程值(距离管线起始点的管线线上距离)的点的定位。

                      //连接远程地图服务

                    ESRI.ArcGIS.ADF.Identity id = new ESRI.ArcGIS.ADF.Identity("Administrator", "123456", "gis2-trq");
                    ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsconn;
                    agsconn = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("10.150.38.34", id);
                    agsconn.Connect();

                    if (!agsconn.IsConnected)
                    {
                        agsconn.Dispose();
                        return "";
                    }

                    //得到对应的地图服务以及对应的featureclass
                    ESRI.ArcGIS.Server.IServerObjectManager som = agsconn.ServerObjectManager;
                    string servertype = "MapServer";
                    string serverobjectname = "LCZ";
                    ESRI.ArcGIS.Server.IServerContext sc = som.CreateServerContext(serverobjectname, servertype);
                    IMapServer pMapServer = sc.ServerObject as IMapServer;
                    IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
                    IMap pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);


                    IFeatureLayer pFLayer = pMap.get_Layer(2) as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFLayer.FeatureClass;

                    ESRI.ArcGIS.Geodatabase.QueryFilter qFilter = sc.CreateObject("esriGeodatabase.QueryFilter") as ESRI.ArcGIS.Geodatabase.QueryFilter;

                       //mile 为一特定的里程值
                    qFilter.WhereClause = String.Format("From_M<={0} AND End_M>={1}", mile, mile);
                    IFeatureCursor fCursor = pFeatureClass.Search(qFilter, true);
                    IFeature feature;
                    ESRI.ArcGIS.Geometry.IPolyline polyline = null;
                    while ((feature = fCursor.NextFeature()) != null)
                    {
                        polyline = feature.Shape as ESRI.ArcGIS.Geometry.IPolyline;
                    }

                    ESRI.ArcGIS.Geometry.IMSegmentation mseg = null;
                    ESRI.ArcGIS.Geometry.IPointCollection pColl = null;
                  //得到 IMSegmentation接口对象

                    mseg = (ESRI.ArcGIS.Geometry.IMSegmentation)polyline;
                    double M = mile;

                   //得到满足里程条件的点集
                    pColl = mseg.GetPointsAtM(M, 0) as ESRI.ArcGIS.Geometry.IPointCollection;
                  // projectpoint为一坐标转换函数,将pColl.get_Point(0).X得到的beijing54坐标转换为WGS84经纬度坐标。这样做可能会有误差影响定位结果。

                         //最好能保持坐标一致,就不用转换了,就不会有误差产生。

  ESRI.ArcGIS.Geometry.IPoint pt = projectpoint(pColl.get_Point(0).X, pColl.get_Point(0).Y, false);
                       ESRI.ArcGIS.ADF.Web.Geometry.Point pSelGeo = new ESRI.ArcGIS.ADF.Web.Geometry.Point(pt.X, pt.Y);
                     ClearTempElementInMap(map);//清除定位标记
              ESRI.ArcGIS.ADF.Web.Geometry.Envelope pEnv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(pSelGeo.X - 0.001, pSelGeo.Y - 0.001, pSelGeo.X + 0.001, pSelGeo.Y + 0.001);
                    map.Extent = pEnv;
                    AddTempGraphicElement(pSelGeo, false, "", false, System.Drawing.Color.Red, 30, map);//添加定位点标记符号

                    ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar toolbar = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar)map.Page.FindControl("Toolbar1");
                    map.CallbackResults.CopyFrom(toolbar.CallbackResults);
                    return map.CallbackResults.ToString();

 

posted @ 2009-03-14 17:28  周文  阅读(517)  评论(0编辑  收藏  举报