private void menu_open_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Mo tap tin du lieu"; //ofd.Filter = "*.shp|*"; if (ofd.ShowDialog() == DialogResult.OK) { if (ofd.FileName.ToLower().EndsWith(".shp")) { MapWinGIS.Shapefile tmpSf = new Shapefile(); var result = tmpSf.Open(@ofd.FileName, null); int iHandle = axMap1.AddLayer(tmpSf, true); AddLayer(axMap1.get_LayerName(iHandle)); } else if (ofd.FileName.ToLower().EndsWith(".tif") || ofd.FileName.ToLower().EndsWith(".png") || ofd.FileName.ToLower().EndsWith(".jpg")) { img = new MapWinGIS.Image(); img.Open(@ofd.FileName); idxLayerRaster = axMap1.AddLayer(img, true); AddLayer(axMap1.get_LayerName(idxLayerRaster)); } } }
/// <summary> /// Loads layer from datasource specifed by filename /// </summary> private void LoadLayer() { axMap1.RemoveAllLayers(); int handle = -1; string ext = System.IO.Path.GetExtension(m_layer.FileName).ToLower(); if (ext == ".shp") { MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile(); if (sf.Open(m_layer.FileName, null)) { handle = axMap1.AddLayer(sf, true); sf.Labels.SavingMode = MapWinGIS.tkSavingMode.modeNone; sf.Charts.SavingMode = MapWinGIS.tkSavingMode.modeNone; //sf.FastMode = true; } } else { MapWinGIS.Image img = new MapWinGIS.Image(); if (img.Open(m_layer.FileName, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, null)) { handle = this.axMap1.AddLayer(img, true); } } }
/// <summary> /// Loads layer from datasource specifed by filename /// </summary> private void LoadLayer() { axMap1.RemoveAllLayers(); int handle = -1; string ext = System.IO.Path.GetExtension(m_filename).ToLower(); if (ext == ".shp") { MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile(); if (sf.Open(m_filename, null)) { handle = axMap1.AddLayer(sf, true); sf.Labels.SavingMode = MapWinGIS.tkSavingMode.modeNone; sf.Charts.SavingMode = MapWinGIS.tkSavingMode.modeNone; } } else { MapWinGIS.Image img = new MapWinGIS.Image(); if (img.Open(m_filename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, null)) { handle = this.axMap1.AddLayer(img, true); } } // serializing initial state to display random options afterwrads m_initState = axMap1.SerializeLayer(handle); }
/// <summary> /// Will convolve the 2-D filter with the source image, producing the output image. /// This overload assumes that you are working with files. /// </summary> /// <param name="SourceFile">A string representing the image file to open.</param> /// <param name="DestFile">A string representing the image file to save to.</param> /// <param name="filter">A 2D array of floats, row major. Filter must be smaller than image.</param> /// <param name="ShowProgressDialog">Boolean, true to have the function automatically show a dialog.</param> /// <param name="ICallBack">A MapWinGIS.ICallback for handling errors and progress messages</param> /// <returns>Boolean, false if the process was canceled.</returns> public static bool ApplyFilter(string SourceFile, string DestFile, float[,] filter, bool ShowProgressDialog, MapWinGIS.ICallback ICallBack) { MapWinUtility.Logger.Dbg("ApplyFilter(SourceFile: " + SourceFile + ",\n" + " DestFile: " + DestFile + ",\n" + " filter: [" + filter.GetUpperBound(0) + ", " + filter.GetUpperBound(1) + "],\n" + " ShowProgressDialog: " + ShowProgressDialog.ToString() + ",\n" + " ICallback)"); bool res; // Argument checks if (SourceFile == null) { MapWinUtility.Logger.Dbg("Argument Exception: SourceFile cannot be null."); throw new ArgumentException("SourceFile cannot be null."); } if (System.IO.File.Exists(SourceFile) == false) { MapWinUtility.Logger.Dbg("Argument Exception: SourceFile not found."); throw new ArgumentException("SourceFile not found."); } if (DestFile == null) { MapWinUtility.Logger.Dbg("Argument Exception: DestFile cannot be null."); throw new ArgumentException("DestFile cannot be null."); } if (System.IO.File.Exists(SourceFile) == true) { System.IO.File.Delete(DestFile); } if (filter.GetUpperBound(0) == 0 || filter.GetUpperBound(1) == 0) { MapWinUtility.Logger.Dbg("Argument Exception: Filter must have values."); throw new ArgumentException("Filter must have values."); } // Check image object MapWinGIS.Image SourceImage = new MapWinGIS.Image(); res = SourceImage.Open(SourceFile, MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null); if (res == false) { MapWinUtility.Logger.Dbg("Application Exception: " + "Attempting to open " + SourceFile + " produced the following error:\n" + SourceImage.get_ErrorMsg(SourceImage.LastErrorCode)); throw new ApplicationException("Attempting to open " + SourceFile + " produced the following error:\n" + SourceImage.get_ErrorMsg(SourceImage.LastErrorCode)); } // Try to create the output image MapWinGIS.Image DestImage = new MapWinGIS.Image(); res = DestImage.CreateNew(SourceImage.Width, SourceImage.Height); if (res == false) { MapWinUtility.Logger.Dbg("Application Exception: " + "Attempting to create " + DestFile + " produced the following error:\n" + DestImage.get_ErrorMsg(DestImage.LastErrorCode)); throw new ApplicationException("Attempting to create " + DestFile + " produced the following error:\n" + DestImage.get_ErrorMsg(DestImage.LastErrorCode)); } DestImage.Save(DestFile, false, MapWinGIS.ImageType.USE_FILE_EXTENSION, ICallBack); res = Do_ApplyFilter(SourceImage, ref DestImage, filter, ShowProgressDialog, ICallBack); DestImage.Close(); SourceImage.Close(); MapWinUtility.Logger.Dbg("Finished ApplyFilter"); return(res); }
/// <summary> /// 从指定的目录加载一张图片到PreviewMap中 /// </summary> /// <param name="filename">图片的路径</param> /// <returns>true 加载成功,false,失败</returns> public bool GetPictureFromFile(string filename) { MapWinGIS.Image img = new MapWinGIS.Image(); string extentName = MapWinGIS.Utility.MiscUtils.GetExtensionName(filename); if ((img.CdlgFilter.ToLower()).IndexOf(extentName.ToLower()) > 0) { if (img.Open(filename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false) == false) { Program.g_error = "打开文件并加载到Preview Map上失败"; return(false); } else //文件打开 { string cutExtentName = filename.Substring(0, filename.Length - extentName.Length - 1); string tStr = Path.GetDirectoryName(cutExtentName + ".*"); if (tStr != "") { switch (MapWinGIS.Utility.MiscUtils.GetExtensionName(tStr).ToLower()) { case "bpw": //world类型的图片文件 case "gfw": m_ShowLocatorBox = true; break; default: // 不是一个world类型的文件 m_ShowLocatorBox = false; break; } } Program.frmMain.MapPreview.AddLayer(img, true); } } else { Program.g_error = "不支持的图片格式"; return(false); } return(true); }
private void AddLayer() { MapWinGIS.Shapefile shpfileOpen; string[] fileNombres; MapWinGIS.Grid grid; MapWinGIS.GridColorScheme gridScheme; MapWinGIS.Image image; MapWinGIS.Utils utils; OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Multiselect = true; int handle; string ext; //initialize dialog openDlg.Filter = "Supported Formats|*.shp;*.bgd;*asc;*.jpg|Shapefile (*.shp)|*.shp|Binary Grids (*.bgd)|*.bgd|ASCII Grids (*.asc)|*.asc |World File (*.jpg)|*.jpg"; openDlg.CheckFileExists = true; if (openDlg.ShowDialog(this) == DialogResult.OK) { fileNombres = openDlg.FileNames; int totalNombres = fileNombres.Length; for (int j = 0; j < totalNombres; j++) { //get the extension of the file ext = System.IO.Path.GetExtension(openDlg.FileNames[j]); if (ext == ".bgd" || ext == ".asc" || ext == ".jpg") { if (ext == ".jpg") { image = new MapWinGIS.Image(); // open image world file image.Open(openDlg.FileNames[j], MapWinGIS.ImageType.JPEG_FILE, true, null); handle = legend1.Layers.Add(image, true); legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(image.Filename)); //handle = axMap1.AddLayer(image, true); handleMap.Add(handle); } else { utils = new MapWinGIS.UtilsClass(); gridScheme = new MapWinGIS.GridColorScheme(); grid = new MapWinGIS.GridClass(); //open the grid grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null); //create a coloring scheme for the image gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains); //convert the grid to a image image = utils.GridToImage(grid, gridScheme, null); //add the image to the legend and map handle = axMap1.AddLayer(image, true); handleMap.Add(handle); grid.Close(); //utils = new MapWinGIS.UtilsClass(); //gridScheme = new MapWinGIS.GridColorScheme(); //grid = new MapWinGIS.GridClass(); ////open the grid //grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null); ////create a coloring scheme for the image //gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains); ////convert the grid to a image //image = utils.GridToImage(grid, gridScheme, null); ////add the image to the legend and map //handle = axMap1.AddLayer(image, true); ////handle = legend1.Layers.Add(image, true); //if (legend1.Layers.IsValidHandle(handle)) //{ // //set the layer name // legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(grid.Filename)); // //set's the legend layer type, this displays a default icon in the legend (line shapefile, point shapefile,polygon shapefile,grid,image) // legend1.Layers.ItemByHandle(handle).Type = MapWindow.Interfaces.eLayerType.Grid; // //set coloring scheme // //when applying a coloring scheme to a shapfile use axMap1.ApplyLegendColors(ShapefileColorScheme) // //when applying a coloring scheme for a grid or image use axMap1.SetImageLayerColorScheme(handle,GridColorScheme); // axMap1.SetImageLayerColorScheme(legend1.SelectedLayer, gridScheme); // legend1.Layers.ItemByHandle(legend1.SelectedLayer).Refresh(); //} //close the grid //grid.Close(); } } else if (ext == ".shp") { shpfileOpen = new MapWinGIS.ShapefileClass(); //open the shapefile shpfileOpen.Open(openDlg.FileNames[j], null); //add the shapefile to the map and legend handle = legend1.Layers.Add(shpfileOpen, true); legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(shpfileOpen.Filename)); //handle = axMap1.AddLayer(shpfileOpen, true); handleMap.Add(handle); string oldProj = shpfileOpen.Projection; // bool status = MapWinGeoProc.SpatialReference.ProjectShapefile(sourceProj, destProj, inputSF, resultSF) this.flagMapaAbierto = true; } } } }
/// <summary> /// 打开指定数据源的图层 /// </summary> /// <param name="filename">文件名</param> /// <param name="callback"></param> /// <returns></returns> public bool Open(string filename, MapWinGIS.ICallback callback) { this.Close(); if (filename.ToLower().EndsWith(".shp")) { MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile(); if (sf.Open(filename, callback)) { // 检查dbf是否存在 bool error = false; if (!File.Exists(Path.ChangeExtension(sf.Filename, ".dbf"))) { m_error = LayerSourceError.DbfIsMissing; error = true; } // 检查DBF记录数相匹配的形状的数量。 MapWinGIS.Table table = new MapWinGIS.Table(); table.Open(Path.ChangeExtension(sf.Filename, ".dbf"), null); if (sf.NumShapes != table.NumRows) { m_error = LayerSourceError.DbfRecordCountMismatch; error = true; } table.Close(); if (error) { sf.Close(); } else { m_shapefile = sf; } return(!error); } else { m_error = LayerSourceError.OcxBased; m_ErrorString = sf.get_ErrorMsg(sf.LastErrorCode); } } else { bool asGrid = true; if (filename.ToLower().EndsWith(".tif")) { asGrid = false; } // TODO: 可能更聪明的选择是在grid/image中使用应用程序设置 if (asGrid) { MapWinGIS.Grid grid = new MapWinGIS.Grid(); if (grid.Open(filename, MapWinGIS.GridDataType.UnknownDataType, false, MapWinGIS.GridFileType.UseExtension, callback)) { m_grid = grid; return(true); } } // 尝试image MapWinGIS.Image image = new MapWinGIS.Image(); if (image.Open(filename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, callback)) { m_image = image; return(true); } else { m_error = LayerSourceError.OcxBased; m_ErrorString = image.get_ErrorMsg(image.LastErrorCode); } } return(false); }
private void Map(Round t) { AxMapWinGIS.AxMap map = new AxMapWinGIS.AxMap(); map.Width = 380; map.Height = 380; host.Child = map; map.Show(); map.CreateControl(); map.ShowZoomBar = false; map.ShowCoordinates = MapWinGIS.tkCoordinatesDisplay.cdmNone; map.CursorMode = MapWinGIS.tkCursorMode.cmNone; MapWinGIS.Shapefile shapeFileMap = new MapWinGIS.Shapefile(); shapeFileMap.Open(@"D:\Projets\TheManager\TheManager_GUI\bin\Debug\gis\world\World_Countries.shp", null); map.AddLayer(shapeFileMap, true); ILocalisation localisation = Session.Instance.Game.kernel.LocalisationTournament(t.Tournament); double logoSize = 30.0; if (localisation as Country != null) { map.ZoomToShape(0, (localisation as Country).ShapeNumber); } else { if (localisation.Name() == "Europe") { map.ZoomToShape(0, 68 /*12 101*/); map.CurrentZoom = 4; } else if (localisation.Name() == "Africa") { map.ZoomToShape(0, 40); map.CurrentZoom = 3; } logoSize = 15.0; } foreach (Club c in t.clubs) { CityClub cc = c as CityClub; if (cc != null) { double projX = -1; double projY = -1; map.DegreesToProj(cc.city.Position.Longitude, cc.city.Position.Latitude, ref projX, ref projY); MapWinGIS.Image img = new MapWinGIS.Image(); img.Open(Utils.Logo(c)); MapWinGIS.Shapefile sf = new MapWinGIS.Shapefile(); sf.CreateNew("", MapWinGIS.ShpfileType.SHP_POINT); sf.DefaultDrawingOptions.AlignPictureByBottom = false; sf.DefaultDrawingOptions.PointType = MapWinGIS.tkPointSymbolType.ptSymbolPicture; sf.DefaultDrawingOptions.Picture = img; sf.DefaultDrawingOptions.PictureScaleX = Math.Round(logoSize / img.OriginalWidth, 2); sf.DefaultDrawingOptions.PictureScaleY = Math.Round(logoSize / img.OriginalHeight, 2); sf.CollisionMode = MapWinGIS.tkCollisionMode.AllowCollisions; MapWinGIS.Shape shp = new MapWinGIS.Shape(); shp.Create(MapWinGIS.ShpfileType.SHP_POINT); shp.AddPoint(projX, projY); sf.EditAddShape(shp); map.AddLayer(sf, true); } } if (_competition.rounds[_indexTour].clubs.Count > 0 && _competition.rounds[_indexTour].clubs[0] as NationalTeam != null) { shapeFileMap.StartEditingTable(); int fieldIndex = shapeFileMap.EditAddField("Qualification", MapWinGIS.FieldType.INTEGER_FIELD, 1, 1); shapeFileMap.DefaultDrawingOptions.FillType = MapWinGIS.tkFillType.ftStandard; for (int i = 0; i < shapeFileMap.NumShapes; i++) { shapeFileMap.EditCellValue(fieldIndex, i, 0); } Dictionary <NationalTeam, int> clubCourses = new Dictionary <NationalTeam, int>(); for (int i = 0; i < _competition.rounds.Count; i++) { Round round = _competition.rounds[i]; foreach (Club c in round.clubs) { NationalTeam nt = c as NationalTeam; if (!clubCourses.ContainsKey(nt)) { clubCourses.Add(nt, 1); } clubCourses[nt] = i + 1; } } foreach (KeyValuePair <NationalTeam, int> kvp in clubCourses) { shapeFileMap.EditCellValue(fieldIndex, kvp.Key.country.ShapeNumber, kvp.Value); } shapeFileMap.Categories.Generate(fieldIndex, MapWinGIS.tkClassificationType.ctUniqueValues, _competition.rounds.Count + 1); shapeFileMap.Categories.ApplyExpressions(); MapWinGIS.ColorScheme colorScheme = new MapWinGIS.ColorScheme(); colorScheme.SetColors2(MapWinGIS.tkMapColor.AliceBlue, MapWinGIS.tkMapColor.DarkBlue); shapeFileMap.Categories.ApplyColorScheme(MapWinGIS.tkColorSchemeType.ctSchemeGraduated, colorScheme); } map.Redraw(); }