예제 #1
0
        /// <summary>
        /// 得到服务器上下文:AGSServer远程调用AO
        /// </summary>
        /// <returns></returns>
        private IServerContext GetServerContext()
        {
            string serverName = "localhost";    //服务器机器名称
            string mapSvrName = "china";        //空间数据服名称
            IServerObjectManager svrObjMgr = null;

            //获取SOM,并放入session变量中
            if (Session["SOM"] == null)
            {
                //用ADF connection库
                AGSServerConnection agsServerConnection = new AGSServerConnection();
                agsServerConnection.Host = serverName;
                //建立与服务器的连接
                agsServerConnection.Connect();
                svrObjMgr = agsServerConnection.ServerObjectManager;
            }
            else
            {
                svrObjMgr = Session["SOM"] as ServerObjectManager;
            }

            //根据服务名来创建上下文
            IServerContext svrContext = svrObjMgr.CreateServerContext(mapSvrName, "MapServer");

            return(svrContext);
        }
        private IServerContext GetServerContext(string sMapServiceName)
        {
            // *** Using Web ADF Common API
            ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisconnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection();
            gisconnection.Host = _serverName;

            gisconnection.Connect();

            _SOM = gisconnection.ServerObjectManager;

            // *** Change the map server object name as needed
            int            counter    = 0;
            IServerContext mapContext = null;

            while ((mapContext == null) && (counter < 3))
            {
                try
                {
                    mapContext = _SOM.CreateServerContext(sMapServiceName, "MapServer");
                }
                catch
                {
                }
                counter += 1;
            }

            if (mapContext == null)
            {
                try
                {
                    if (_sContextMapService != null)
                    {
                        mapContext = _SOM.CreateServerContext(_sContextMapService, "MapServer");
                    }
                }
                catch
                {
                }
            }

            return(mapContext);
        }
예제 #3
0
        /// <summary>
        /// 绘制点缓冲
        /// </summary>
        private void DrawBufferByPoint(ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt)
        {
            //1.连接服务器
            AGSServerConnection connection = new AGSServerConnection();

            connection.Host = "localhost";
            connection.Connect();

            //2.获得服务器
            IServerObjectManager pSom      = connection.ServerObjectManager;
            IServerContext       pSc       = pSom.CreateServerContext("china", "MapServer");//服务名和类型
            IMapServer           mapServer = pSc.ServerObject as IMapServer;

            //3.使用服务器对象 几何对象转换
            IMapServerObjects pMso = mapServer as IMapServerObjects;
            //ESRI.ArcGIS.Geometry.IGeometry comPt = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(adfPt, pSc)
            //    as ESRI.ArcGIS.Geometry.IGeometry;////ValueObjectToComObject(pnt, pSC);
            IPoint pt = new ESRI.ArcGIS.Geometry.PointClass();

            pt.X = adfPt.X;
            pt.Y = adfPt.Y;
            ESRI.ArcGIS.Geometry.IGeometry comPt = pt;

            ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
            ISpatialReference pSR = sre.CreateGeographicCoordinateSystem(4326);

            comPt.SpatialReference = pSR;

            //绘制buffer
            ITopologicalOperator pTOPO = comPt as ITopologicalOperator;

            pTOPO.Simplify();//??
            double   bufDis  = Map1.Extent.Width / 2;
            IPolygon bufPoly = pTOPO.Buffer(10) as IPolygon;

            bufPoly.Densify(0, 0);
            ESRI.ArcGIS.ADF.ArcGISServer.PolygonN valuePolyN = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufPoly, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)) as ESRI.ArcGIS.ADF.ArcGISServer.PolygonN;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon  adfPoly    = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(valuePolyN) as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;


            #region Densify
            ////***Densify
            // ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)bufPoly;
            // ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(com_pointcollection, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.poly));
            //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
            //for (int i = 0; i < com_pointcollection.PointCount - 1; i++)
            //{
            //    ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_pt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();
            //    new_adf_pt.X = com_pointcollection.get_Point(i).X;
            //    new_adf_pt.Y = com_pointcollection.get_Point(i).Y;
            //    new_adf_pointcollection.Add(new_adf_pt);
            //}
            //ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
            //new_adf_ring.Points = new_adf_pointcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
            //new_adf_ringcollection.Add(new_adf_ring);
            //ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
            //new_adf_polygon.Rings = new_adf_ringcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = new_adf_polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            ////*******Densify
            #endregion

            ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = adfPoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            GraphicElement geoEle = new GraphicElement(geom, System.Drawing.Color.Red);
            try
            {
                Map1.Zoom(adfPoly);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            geoEle.Symbol.Transparency = 50;

            IEnumerable gfc = Map1.GetFunctionalities();

            MapResource gMap = null;
            foreach (IGISFunctionality gfunc in gfc)
            {
                if (gfunc.Resource.Name == "graph")
                {
                    gMap = (MapResource)gfunc.Resource;
                    break;
                }
            }
            if (gMap == null)
            {
                return;
            }
            ElementGraphicsLayer glayer = null;
            foreach (DataTable dt in gMap.Graphics.Tables)
            {
                if (dt is ElementGraphicsLayer)
                {
                    glayer = dt as ElementGraphicsLayer;
                    break;
                }
            }
            if (glayer == null)
            {
                glayer = new ElementGraphicsLayer();
                gMap.Graphics.Tables.Add(glayer);
            }

            glayer.Clear();//清除数据
            glayer.Add(geoEle);

            //4.释放服务器对象
            pSc.ReleaseContext();

            if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
            {
                Map1.Refresh();
            }
            else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
            {
                Map1.RefreshResource(gMap.Name);
            }
            return;
        }
        private IServerContext GetServerContext(string sMapServiceName)
        {
            // *** Using Web ADF Common API           
          ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisconnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection();
            gisconnection.Host = _serverName;

            gisconnection.Connect();

            _SOM = gisconnection.ServerObjectManager;

            // *** Change the map server object name as needed 
            int counter = 0;
            IServerContext mapContext = null;
            while ((mapContext == null) && (counter < 3))
            {
                try
                {
                    mapContext = _SOM.CreateServerContext(sMapServiceName, "MapServer");
                }
                catch
                {

                }
                counter += 1;
            }

            if (mapContext == null)
            {
                try
                {
                    if ( _sContextMapService != null )
                        mapContext = _SOM.CreateServerContext(_sContextMapService, "MapServer");
                }
                catch
                {

                }
            }

            return mapContext;
        }