コード例 #1
0
        /// <summary>
        ///  获取某个路径下的MPJ文件
        /// </summary>
        /// <param name="dirInfo"></param>
        private void get_MPJ_File(DirectoryInfo dirInfo)
        {
            advTreeMPJ.Nodes.Clear();
            int count = 0;

            foreach (FileInfo file in dirInfo.GetFiles())
            {
                if (file.Extension.Equals(".MPJ"))
                {
                    count++;//用于显示进度条数据
                    Node pNode = new Node();
                    pNode.Text = file.Name;
                    advTreeMPJ.Nodes.Add(pNode);

                    //打开工程文件 加载工程下的图层文件
                    WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass();
                    ws.Open(file.DirectoryName + "\\" + file.Name, WorkSpace.EnumOpenMode.OpenReadOnly);
                    XMap map = ws.GetMapByName(file.Name.Split('.')[0]);
                    ws.ActiveMap = map;
                    //遍历工程文件下的所有图层文件
                    for (int i = 1; i <= map.LayerCount; i++)
                    {
                        IXMapLayer mapLayer  = map.get_Layer(i);
                        Node       childNode = new Node();
                        childNode.Text = mapLayer.LayerName;
                        pNode.Nodes.Add(childNode);
                    }
                    ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard);
                    SetTextMessage(count * 100 / dirInfo.GetFiles().Length);
                }
            }
        }
コード例 #2
0
ファイル: Convert.cs プロジェクト: HTD/Woof
 /// <summary>
 /// Converts generic list of objects to DataTable
 /// </summary>
 /// <param name="x"></param>
 /// <returns></returns>
 private DataTable GetDataTable(IList x)
 {
     if (x.Count < 1) return null;
     var m = new XMap(x[0]);
     var c = m.Values.Count;
     var t = GetDataTable(x[0]);
     object[] r;
     var rt = x.Count;
     for (int i = 0, rc = 1; rc < rt; i = 0, rc++) {
         r = new object[c];
         m = new XMap(x[rc]);
         m.ForEach(d => {
             if (d.Value == null) r[i++] = DBNull.Value;
             else r[i++] = (m.Types[d.Key] == typeof(DateTime) && (DateTime)d.Value == DateTime.MinValue) ? DBNull.Value : d.Value;
         });
         t.Rows.Add(r);
     }
     return t;
 }
コード例 #3
0
ファイル: Convert.cs プロジェクト: HTD/Woof
 /// <summary>
 /// Converts generic object to DataTable with 1 row
 /// </summary>
 /// <param name="x"></param>
 /// <returns></returns>
 private DataTable GetDataTable(object x)
 {
     var m = new XMap(x);
     var t = new DataTable();
     var r = new object[m.Values.Count];
     var i = 0;
     Type type;
     Type nnType;
     m.ForEach(d => {
         type = m.Types[d.Key];
         nnType = Nullable.GetUnderlyingType(type);
         if (nnType != null) type = nnType;
         t.Columns.Add(d.Key, type);
         if (d.Value == null) r[i++] = DBNull.Value;
         else r[i++] = (m.Types[d.Key] == typeof(DateTime) && (DateTime)d.Value == DateTime.MinValue) ? DBNull.Value : d.Value;
     });
     t.Rows.Add(r);
     return t;
 }
コード例 #4
0
        /// <inheritdoc/>
        public override byte[] TryGetStreamInternal(double left, double top, double right, double bottom, int width, int height)
        {
            // load effective layers into an array to avoid multiple enumerations
            var effectiveLayers = EffectiveXMapLayers
                                  .Select(layer => new { IsBaseLayer = BaseXMapLayers.Any(baseLayer => baseLayer.Name == layer.Name), Layer = layer })
                                  .ToArray();

            // setup size
            var size = new System.Windows.Size(width, height);

            // setup map section
            var mapSection = new MapSectionByBounds()
            {
                bounds = new Bounds()
                {
                    minX = left,
                    maxX = right,
                    minY = Math.Min(top, bottom),
                    maxY = Math.Max(top, bottom)
                }
            };

            // TODO: implement layer visibility as soon as xMap-2 supports this through its SOAP interface
            //
            // the xMap-2 that was integrated was not able to disable base layers when using the SOAP. In debug versions this will
            // be ignored; for release versions we're going to throw a NotImplementedException when any of the base layers hase
            // been disabled.

            var disabledBaseLayers = effectiveLayers
                                     .Where(item => item.IsBaseLayer && !item.Layer.Enabled)
                                     .Select(item => item.Layer.Name)
                                     .ToArray();

            if (disabledBaseLayers.Length > 0)
            {
                var message = "currently base layers cannot be disabled when requesting map images by bounds [affects: " + string.Join(", ", disabledBaseLayers) + "]";
#if DEBUG
                Debug.WriteLine("WARNING: " + message);
#else
                if (!IgnoreMissingLayeredMapCapabilities)
                {
                    throw new NotImplementedException(message);
                }
#endif
            }

            // create and initialize the service
            using (var service = new XMap())
            {
                service.Url     = url;
                service.Timeout = 8000;

                if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password))
                {
                    service.PreAuthenticate = true;
                    service.Credentials     = new CredentialCache {
                        { new Uri(url), "Basic", new NetworkCredential(User, Password) }
                    };
                }

                // setup map image request
                var mapRequest = new MapRequest()
                {
                    imageOptions = new ImageOptions()
                    {
                        format = ImageFormat.PNG, formatSpecified = true,
                        width  = width, widthSpecified = true,
                        height = height, heightSpecified = true,
                    },
                    mapSection       = mapSection,
                    coordinateFormat = "EPSG:76131",
                    storedProfile    = CustomProfile,
                    resultFields     = new ResultFields()
                    {
                        image = true, imageSpecified = true
                    }
                };

                // TODO: assumption: all non-base layers in EffectiveXMapLayers are to be enabled via mapRequest.requestProfile.featureLayerProfile
                //
                // Turn enabled non-base layers into Theme elements. Furthermore, request object inormation for
                // the Theme elements added when a map object information sink has been provided.

                var featureLayerThemes = effectiveLayers
                                         .Where(item => !item.IsBaseLayer && item.Layer.Enabled)
                                         .Select(item => item.Layer.AsTheme())
                                         .ToArray();

                if (featureLayerThemes.Any())
                {
                    mapRequest.requestProfile = new RequestProfile()
                    {
                        featureLayerProfile = new FeatureLayerProfile()
                        {
                            themes = featureLayerThemes
                        }
                    };

                    if (MapObjectInformationSink != null)
                    {
                        mapRequest.resultFields.featureThemeIds = featureLayerThemes.Select(theme => theme.id).ToArray();
                    }
                }

                // send request
                var mapResponse = service.renderMap(mapRequest);

#if DEBUG
                // for debug version, check if the image returned matches our request

                var requestedBounds = ((MapSectionByBounds)mapRequest.mapSection).bounds;

                if (!BoundingBoxesAreEqual(requestedBounds, mapResponse.bounds))
                {
                    IssueBoundingBoxWarning(requestedBounds, mapResponse.bounds, width, height, mapRequest.storedProfile ?? "");
                }
#endif

                // call object information sink when object information has been delivered
                if (MapObjectInformationSink != null && mapResponse.features != null)
                {
                    MapObjectInformationSink(
                        mapResponse.features.Select(feature => new XServer2Feature(feature) as IMapObject),
                        new MapRectangle(mapSection.bounds.minX, mapSection.bounds.maxX, mapSection.bounds.minY, mapSection.bounds.maxY),
                        size
                        );
                }

                // done, return rendered map image
                return(mapResponse.image);
            }
        }
コード例 #5
0
        //更新工程文件以及该工程文件的图层文件
        private void tsmiMPJFileUpdate_Click(object sender, EventArgs e)
        {
            UpdateMPJFile umpjdlg = new UpdateMPJFile(this);

            if (umpjdlg.ShowDialog() == DialogResult.OK)
            {
                //如果需要备份 先备份MPJ文件
                if (SwichBtnVale)
                {
                    //备份文件
                    BackupFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path, SaveMPJFilePath);
                    foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes)
                    {
                        BackupFile(n.Text, MPJ_Path, SaveMPJFilePath);
                    }
                    //先删除MPJ文件以及该工程文件下的图层文件
                    DeleteFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path);
                    foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes)
                    {
                        DeleteFile(n.Text, MPJ_Path);
                    }

                    //更新MPJ文件
                    UpdateFile(NewMPJFile, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path);
                    //打开工程文件 更新工程下的图层文件
                    WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass();
                    ws.Open(NewMPJFilePath, WorkSpace.EnumOpenMode.OpenReadOnly);
                    XMap map = ws.GetMapByName(NewMPJFile.Replace(".MPJ", ""));
                    ws.ActiveMap = map;

                    for (int i = 1; i <= map.LayerCount; i++)
                    {
                        IXMapLayer mapLayer = map.get_Layer(i);
                        UpdateFile(mapLayer.LayerName, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path);
                    }
                    ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard);
                }
                else//不备份直接更新
                {
                    //先删除MPJ文件以及该工程文件下的图层文件
                    DeleteFile(this.advTreeMPJ.SelectedNode.Text, MPJ_Path);
                    foreach (Node n in this.advTreeMPJ.SelectedNode.Nodes)
                    {
                        DeleteFile(n.Text, MPJ_Path);
                    }

                    //更新MPJ文件
                    UpdateFile(NewMPJFile, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path);
                    //打开工程文件 更新工程下的图层文件
                    WorkSpace.IMxWorkSpace ws = new WorkSpace.MxWorkSpaceClass();
                    ws.Open(NewMPJFilePath, WorkSpace.EnumOpenMode.OpenReadOnly);
                    XMap map = ws.GetMapByName(NewMPJFile.Replace(".MPJ", ""));
                    ws.ActiveMap = map;

                    for (int i = 1; i <= map.LayerCount; i++)
                    {
                        IXMapLayer mapLayer = map.get_Layer(i);
                        UpdateFile(mapLayer.LayerName, NewMPJFilePath.Replace("\\" + NewMPJFile, ""), MPJ_Path);
                    }
                    ws.Close(WorkSpace.EnumCloseMode.NoDlgDiscard);
                }
            }
        }