/// <summary> /// Opens specified grid layer using MapWinGIS global settings /// </summary> public static void OpenGridLayer(string filename, bool useFileManager) { axMap1.RemoveAllLayers(); if (useFileManager) { //FileManager fm = new FileManager(); //Image img = fm.OpenRaster(filename, tkFileOpenStrategy.fosProxyForGrid); //axMap1.AddLayer(img, true); axMap1.AddLayerFromFilename(filename, tkFileOpenStrategy.fosAutoDetect, true); } else { if (!File.Exists(filename)) { MessageBox.Show("Failed to find grid: " + filename); } else { Grid grid = new Grid { GlobalCallback = callback }; if (grid.Open(filename, GridDataType.UnknownDataType, false, GridFileType.UseExtension, null)) { int layerHandle = axMap1.AddLayer(grid, true); if (layerHandle != -1) { var img = axMap1.get_Image(layerHandle); if (img != null) { Debug.Print("Number of bands: " + img.NoBands); Debug.Print("Allow external color scheme: " + img.AllowGridRendering); MessageBox.Show("Layer was added to the map"); } } else { MessageBox.Show("Failed to load layer: " + axMap1.get_ErrorMsg(axMap1.LastErrorCode)); } } else { MessageBox.Show("Failed to open grid"); } //grid.Close(); } } }
private static bool DisplayAllLayers() { var ds = new OgrDatasource(); if (!ds.Open(CONNECTION_STRING)) { Debug.WriteLine("Failed to establish connection: " + ds.GdalLastErrorMsg); } else { map.RemoveAllLayers(); // make sure it matches SRID of the layers (4326 in this case) map.Projection = tkMapProjection.PROJECTION_WGS84; for (int i = 0; i < ds.LayerCount; i++) { var layer = ds.GetLayer(i); if (layer != null) { int handle = map.AddLayer(layer, true); if (handle == -1) { Debug.WriteLine("Failed to add layer to the map: " + map.get_ErrorMsg(map.LastErrorCode)); } else { Debug.WriteLine("Layer was added the map: " + layer.Name); } } } map.ZoomToMaxVisibleExtents(); ds.Close(); } return(true); }