コード例 #1
0
 internal BitmapSource(Image image)
 {
     if (image == null)
     {
         throw new NullReferenceException("Internal reference is empty.");
     }
     _image = image;
 }
コード例 #2
0
ファイル: Main.cs プロジェクト: orapow/yt
        void addLayer(Tn tn)
        {
            var    ext = tn.file.Substring(tn.file.LastIndexOf("."));
            object lay = null;

            if (ext == ".shp")
            {
                var shp = new Shapefile();
                shp.Open(tn.file);
                lay        = shp;
                tn.tp      = 3;
                tn.extents = shp.Extents;

                tn.Fields = new List <ShpLayer.Field>();
                for (var f = 0; f < shp.NumFields; f++)
                {
                    var fe = shp.Field[f];
                    tn.Fields.Add(new ShpLayer.Field()
                    {
                        Name = fe.Name, Length = fe.Width, Type = fe.Type.ToString("G")
                    });
                }

                tn.Shapges = new List <ShpLayer.Shape>();
                for (var i = 0; i < shp.NumShapes; i++)
                {
                    showtip("正在加载文件:" + tn.file + " " + i + "/" + shp.NumShapes);
                    var sp  = shp.Shape[i];
                    var spe = new ShpLayer.Shape();
                    spe.Tp     = (byte)sp.ShapeType;
                    spe.Extent = new Extend(sp.Extents.xMin, sp.Extents.yMin, sp.Extents.xMax, sp.Extents.yMax);
                    var data = new Dictionary <string, string>();
                    for (var f = 0; f < shp.NumFields; f++)
                    {
                        data.Add(shp.Field[f].Name, shp.Table.CellValue[f, i] + "");
                    }
                    spe.Data = data;
                    for (var j = 0; j < sp.NumParts; j++)
                    {
                        spe.Points.Add(j, getPoints(sp.PartAsShape[j]));
                    }
                    tn.Shapges.Add(spe);
                }
            }
            else
            {
                var img = new MapWinGIS.Image();
                img.Open(tn.file);
                var r = false;
                img.SetNoDataValue(0, ref r);
                lay        = img;
                tn.tp      = 2;
                tn.extents = img.Extents;
            }
            tn.inptr = map1.AddLayer(lay, true);
            showtip("文件:" + tn.file + " 加载完成");
        }
コード例 #3
0
        public Vertical_Profiling_Form(MapWinGIS.Image demImg, MapWinGIS.Point pt1, MapWinGIS.Point pt2)
        {
            this.InitializeComponent();
            //MapWinGIS.Point pt1 = new MapWinGIS.Point();
            //pt1.Set(0, 4);
            //MapWinGIS.Point pt2 = new MapWinGIS.Point();
            //pt2.Set(2, 0);

            int row1, col1;

            demImg.ProjectionToImage(pt1.x, pt1.y, out col1, out row1);
            int row2, col2;

            demImg.ProjectionToImage(pt2.x, pt2.y, out col2, out row2);
            var myModel = new PlotModel {
                Title = "Mặt cắt dọc"
            };

            //double step = 0.1;
            //int a_count = (int)Math.Abs((pt1.x - pt2.x) / step);
            //var plot3_Series = new LineSeries { StrokeThickness = 1, MarkerSize = 1 };
            //for (int i = 0; i < a_count; i++)
            //{
            //    int row;
            //    int column;
            //    double x_val = pt1.x + i*step;
            //    double y_val = LineEquation(pt1, pt2, x_val);
            //    demImg.ProjectionToImage(x_val, y_val, out column, out row);
            //    double yDEM = 0;
            //    demImg.Band[1].get_Value(column,row,out yDEM);
            //    plot3_Series.Points.Add(new DataPoint(x_val, yDEM));

            //}
            MapWinGIS.Point ptTmp1 = new MapWinGIS.Point();
            ptTmp1.Set(col1 + 0.5, row1 + 0.5);
            MapWinGIS.Point ptTmp2 = new MapWinGIS.Point();
            ptTmp2.Set(col2 + 0.5, row2 + 0.5);

            int a_count      = Math.Abs(col1 - col2);
            var plot3_Series = new LineSeries {
                StrokeThickness = 1, MarkerSize = 1
            };

            for (int i = 0; i < a_count; i++)
            {
                double x_val = col1 + i;
                double y_val = LineEquation(ptTmp1, ptTmp2, x_val);
                double yDEM  = 0;
                demImg.Band[1].get_Value((int)x_val, (int)y_val, out yDEM);
                demImg.ImageToProjection((int)x_val, (int)y_val, out x_val, out y_val);
                plot3_Series.Points.Add(new DataPoint(x_val, yDEM));
            }
            myModel.Series.Add(plot3_Series);

            this.plotView1.Model = myModel;
        }
コード例 #4
0
        //Creates a shape file that contains all flights lat and long points and then generates a feald in the table that contains all flights images
        private void CreatePointShapefile()
        {
            axMap1.Projection   = tkMapProjection.PROJECTION_WGS84;
            axMap1.TileProvider = tkTileProvider.OpenStreetMap;
            var positions = pR.GetPositionsFromDB();
            var sfPoints  = new Shapefile();

            sfPoints.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
            // creating points and inserting them in the shape
            foreach (Position position in positions)
            {
                int count = 0;
                var pnt   = new Point();
                pnt.x = Convert.ToDouble(position.longitude);
                pnt.y = Convert.ToDouble(position.latitude);
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                int index = 0;
                shp.InsertPoint(pnt, ref index);
                sfPoints.EditInsertShape(shp, ref count);
                count++;
            }
            var _idShape = axMap1.AddLayer(sfPoints, true);
            int indexo   = sfPoints.Table.FieldIndexByName["MWShapeId"];
            var names    = new HashSet <string>();

            for (int i = 0; i < sfPoints.Table.NumRows; i++)
            {
                names.Add(sfPoints.Table.CellValue[indexo, i].ToString());
            }
            string[] files = Directory.GetFiles(@"D:\Faks\Druga godina\Treci Semestar\Programiranje_u_NET_okolini\Konstrukcijska_Vjezba\FlightTracker\FlightTracker\Resources\imagesOfPlanes");
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = sfPoints.Categories.Add(name);
                        ct.DrawingOptions.PointType     = tkPointSymbolType.ptSymbolPicture;
                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;
                        ct.DrawingOptions.DrawingMode   = tkVectorDrawingMode.vdmGDIPlus;
                        sfPoints.CollisionMode          = tkCollisionMode.AllowCollisions;
                        ct.Expression             = "[MWShapeId]=" + name;
                        ct.DrawingOptions.Picture = img;

                        sfPoints.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }
            }
            sfPoints.Categories.ApplyExpressions();
            axMap1.KnownExtents = tkKnownExtents.keCroatia;
        }
コード例 #5
0
 public void SnapshotTest()
 {
     MapWindow.Interfaces.View target   = new View(); // TODO: Initialize to an appropriate value
     MapWinGIS.Extents         Bounds   = null;       // TODO: Initialize to an appropriate value
     MapWinGIS.Image           expected = null;       // TODO: Initialize to an appropriate value
     MapWinGIS.Image           actual;
     actual = target.Snapshot(Bounds);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
コード例 #6
0
        public static BitmapSource CreateNew(int newWidth, int newHeight)
        {
            var img = new Image();

            if (img.CreateNew(newWidth, newHeight))
            {
                return(new BitmapSource(img));
            }
            throw new ApplicationException("Failed to create image: " + img.ErrorMsg[img.LastErrorCode]);
        }
コード例 #7
0
        public void UserPointImageListItemTest()
        {
            Layer target     = new Layer();  // TODO: Initialize to an appropriate value
            long  imageIndex = 0;            // TODO: Initialize to an appropriate value

            MapWinGIS.Image expected = null; // TODO: Initialize to an appropriate value
            MapWinGIS.Image actual;
            actual = target.UserPointImageListItem(imageIndex);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #8
0
        /// <summary>
        /// Changes the textures
        /// </summary>
        void iconControl1_SelectionChanged()
        {
            string filename = iconControl1.SelectedName;

            if (filename == string.Empty)
            {
                return;
            }

            // seeking the transarent color
            Bitmap bmp            = new Bitmap(filename);
            Color  clrTransparent = Color.White;

            for (int i = 0; i < bmp.Width; i++)
            {
                int j;
                for (j = 0; j < bmp.Height; j++)
                {
                    Color clr = bmp.GetPixel(i, j);
                    if (clr.A == 0)
                    {
                        clrTransparent = clr;
                        break;
                    }
                }
                if (j != bmp.Width)
                {
                    break;
                }
            }

            MapWinGIS.Image img = new MapWinGIS.Image();
            if (img.Open(filename, ImageType.USE_FILE_EXTENSION, true, null))
            {
                img.LoadBuffer(50);

                img.TransparencyColor    = Colors.ColorToUInteger(clrTransparent);
                img.TransparencyColor2   = Colors.ColorToUInteger(clrTransparent);
                img.UseTransparencyColor = true;

                _options.Picture = img;

                DrawPreview();
            }
            else
            {
                string errString = string.Empty;
                if (img.LastErrorCode != 0)
                {
                    errString = ": " + img.get_ErrorMsg(img.LastErrorCode);
                }
                Globals.MessageBoxError("Failed to open image: " + errString);
            }
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: TheWind97/GIS
        public bool AddLayers(string name)
        {
            //this.mapControl.RemoveAllLayers();

            //this.mapControl.LockWindow(tkLockMode.lmLock);
            if (name.ToLower().EndsWith(".shp"))
            {
                Shapefile shp = new Shapefile();
                shp.Open(name, null);
                int layerID = mapControl.AddLayer(shp, true);
                //indexLayers.Insert(0, layerID);
            }
            else if (openDialog.SafeFileName.ToLower().EndsWith(".tif") ||
                     openDialog.SafeFileName.ToLower().EndsWith(".png") ||
                     openDialog.SafeFileName.ToLower().EndsWith(".jpg"))
            {
                MapWinGIS.Image img = new MapWinGIS.Image();
                img.Open(name, ImageType.TIFF_FILE, false, null);
                img.UseRgbBandMapping = true;
                for (int i = 0; i < img.NoBands; i++)
                {
                    bandIndex.Add(i);
                }
                //MessageBox.Show(img.UseRgbBandMapping.ToString());
                int layer = mapControl.AddLayer(img, true);

                //indexLayers.Insert(0, layer);
            }


            // List on Tree Layers
            var splited = openDialog.FileName.Split('\\');

            treeLayers.CheckBoxes  = true;
            treeLayers.AfterCheck += treeLayer_AfterCheck;
            TreeNode layerNode = new TreeNode(splited[splited.Length - 1].Split('.')[0]);

            layerNode.Checked = true;
            treeLayers.Nodes[0].Nodes.Add(layerNode);
            layerNode.Parent.Checked = true;

            // Draw Marker
            shp_tmp = new Shapefile();
            if (!shp_tmp.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
            {
                MessageBox.Show("Failed to create shapefile: " + shp_tmp.ErrorMsg[shp_tmp.LastErrorCode]);
                return(false);
            }
            int layer_tmp = mapControl.AddLayer(shp_tmp, true);

            mapControl.CursorMode      = tkCursorMode.cmNone;
            mapControl.MouseDownEvent += mapControl_MouseDownEvent;
            return(this.mapControl.NumLayers > 0);
        }
コード例 #10
0
        /// <summary>
        /// Reprojects image
        /// </summary>
        public static TestingResult Reproject(MapWinGIS.Image image, out MapWinGIS.Image imageNew, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            MapWinGIS.GeoProjection projImage = new MapWinGIS.GeoProjection();
            projImage.ImportFromProj4(image.GetProjection());

            string sourcePrj    = image.GetProjection();
            string targetPrj    = projection.ExportToProj4();
            string origFilename = image.Filename;

            MapWinGIS.ICallback callback = image.GlobalCallback;
            imageNew = null;

            LayerSource obj    = new LayerSource(image);
            LayerSource objNew = null;

            if (CoordinateTransformation.SeekSubstituteFile(obj, projection, out objNew))
            {
                imageNew = objNew.Image;
                return(TestingResult.Substituted);
            }

            string newFilename = CoordinateTransformation.FilenameWithProjectionSuffix(origFilename, projImage, projection);

            newFilename = CoordinateTransformation.GetSafeNewName(newFilename);

            // setting callback
            if (report != null)
            {
                if (!report.Visible)
                {
                    report.InitProgress(projection);
                }

                report.ShowFilename(image.Filename);
            }

            MapWinGIS.GeoProcess.SpatialReference.ProjectImage(sourcePrj, targetPrj, origFilename, newFilename, report);

            if (report != null)
            {
                report.ClearFilename();
            }

            imageNew = new MapWinGIS.Image();
            if (imageNew.Open(newFilename, MapWinGIS.ImageType.USE_FILE_EXTENSION, false, callback))
            {
                return(TestingResult.Ok);
            }
            else
            {
                imageNew = null;
                return(TestingResult.Error);
            }
        }
コード例 #11
0
        public void GetScreenPictureTest()
        {
            Reports target   = new Reports(); // TODO: Initialize to an appropriate value
            Extents BoundBox = null;          // TODO: Initialize to an appropriate value

            MapWinGIS.Image expected = null;  // TODO: Initialize to an appropriate value
            MapWinGIS.Image actual;
            actual = target.GetScreenPicture(BoundBox);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #12
0
        public static IImageSource Open(string filename, bool inRam)
        {
            var img = new Image();

            if (!img.Open(filename, ImageType.USE_FILE_EXTENSION, inRam))
            {
                Logger.Current.Warn("Failed to open datasource: " + img.ErrorMsg[img.LastErrorCode]);
                return(null);
            }

            return(Wrap(img));
        }
コード例 #13
0
 public void AddTest3()
 {
     MapWindow.Interfaces.Layers target              = new MapWindow.Layers(); // TODO: Initialize to an appropriate value
     MapWinGIS.Image             ImageObject         = null;                   // TODO: Initialize to an appropriate value
     MapWinGIS.Image             ImageObjectExpected = null;                   // TODO: Initialize to an appropriate value
     MapWindow.Interfaces.Layer  expected            = null;                   // TODO: Initialize to an appropriate value
     MapWindow.Interfaces.Layer  actual;
     actual = target.Add(ref ImageObject);
     Assert.AreEqual(ImageObjectExpected, ImageObject);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: TheWind97/GIS
        private void combinationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormBandCombination fCombine = new FormBandCombination(bandIndex);

            fCombine.ShowDialog();
            MapWinGIS.Image img = mapControl.get_Image(0);
            img.RedBandIndex   = fCombine.redIndex;
            img.GreenBandIndex = fCombine.greenIndex;
            img.BlueBandIndex  = fCombine.blueIndex;
            MessageBox.Show(img.UseRgbBandMapping.ToString());
            MessageBox.Show(img.RedBandIndex.ToString() + img.GreenBandIndex.ToString() + img.BlueBandIndex.ToString());
            mapControl.Redraw();
        }
コード例 #15
0
        internal static IImageSource Wrap(Image img)
        {
            if (img == null)
            {
                return(null);
            }

            if (img.SourceType == tkImageSourceType.istGDALBased)
            {
                return(new RasterSource(img));
            }
            return(new BitmapSource(img));
        }
コード例 #16
0
ファイル: BandRender.cs プロジェクト: rerangst/BTLGIS
 public BandRender(MapWinGIS.Image img)
 {
     InitializeComponent();
     comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
     comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
     comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
     for (int i = 0; i < img.NoBands; i++)
     {
         comboBox1.Items.Add("Band " + (i + 1).ToString());
         comboBox2.Items.Add("Band " + (i + 1).ToString());
         comboBox3.Items.Add("Band " + (i + 1).ToString());
     }
     button1.Click += Button1_Click;
 }
コード例 #17
0
        private void AddRasterLayerToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string FilePath, Filename;

            FilePath = @"F:\AY\SCREEN_CAPTURE\ARCPY\Catchment\cat_poly\cat_poly.shp";

            OpenFileDialog openfiledialog1 = new OpenFileDialog();

            openfiledialog1.Filter      = "Raster tif(*.tif)|*.tif|Raster png(*.png)|*.png|All Files(*.*)|*.*";
            openfiledialog1.FilterIndex = 1;

            if (openfiledialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                FilePath = openfiledialog1.FileName;
            }
            else if (openfiledialog1.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                //return;
            }

            //FilePath = @"F:\AY\SCREEN_CAPTURE\ARCPY\Catchment\cat_poly\cat_poly.shp";

            int layerHandle = -1;

            if (FilePath.ToLower().EndsWith(".tif") ||
                FilePath.ToLower().EndsWith(".png"))
            {
                MapWinGIS.Image img = new MapWinGIS.Image();
                if (img.Open(FilePath, ImageType.TIFF_FILE, false, null))
                {
                    layerHandle = axMap1.AddLayer(img, true);
                    //HandleValue[LayerNumbers] = axMap1.AddLayer(img, true);
                    //AllLoadedFileName[LayerNumbers] = FilePath.ToString();
                    AllLoadedFileName[layerHandle] = FilePath.ToString();

                    //Level 2
                    //treeView1.Nodes[0].Nodes.Add(FilePath.ToString(), FilePath.ToString());         //0 0

                    Filename = Path.GetFileName(FilePath);
                    treeView1.Nodes[0].Nodes.Add(Filename);
                    ///LayerNumbers++;
                }
                else
                {
                    MessageBox.Show(img.ErrorMsg[img.LastErrorCode]);
                }
            }
            //TxtLayerNumber.Text = LayerNumbers.ToString();
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: TheWind97/GIS
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.openDialog.Title = "Open data";
            MapWinGIS.Image img = new MapWinGIS.Image();


            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                this.AddLayers(openDialog.FileName);
                //foreach (String name in openDialog.FileNames)
                //{
                //
                //}
            }
        }
コード例 #19
0
ファイル: RasterSource.cs プロジェクト: zylimit/MapWindow5
        public static IRasterSource Open(string filename)
        {
            var img = new Image();

            if (!img.Open(filename))
            {
                throw new ApplicationException("Failed to open datasource: " + img.ErrorMsg[img.LastErrorCode]);
            }
            if (img.SourceType != tkImageSourceType.istGDALBased)
            {
                // TODO: force opening BMP files with GDAL as well for uniformity
                throw new ApplicationException("Image format isn't supported by RasterSource");
            }
            return(new RasterSource(img));
        }
コード例 #20
0
        /// <summary>
        ///当选择了icon,更新预览
        /// </summary>
        private void IconControl1SelectionChanged()
        {
            string filename = iconControl1.SelectedName;

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var   bmp            = new Bitmap(filename);
            Color clrTransparent = Color.White;

            MapWinGIS.Image img = new MapWinGIS.Image();
            if (img.Open(filename, ImageType.USE_FILE_EXTENSION, true, null))
            {
                img.LoadBuffer(50);

                img.TransparencyColor    = Colors.ColorToUInteger(clrTransparent);
                img.TransparencyColor2   = Colors.ColorToUInteger(clrTransparent);
                img.UseTransparencyColor = true;

                _options.PointType = tkPointSymbolType.ptSymbolPicture;
                _options.Picture   = img;

                UpdatePrictureScale();

                DrawPreview();
            }
            else
            {
                string errString = string.Empty;
                if (img.LastErrorCode != 0)
                {
                    errString = ": " + img.ErrorMsg[img.LastErrorCode];
                }
                MessageBox.Show("Failed to open image: " + errString);
            }

            if (!_noEvents)
            {
                btnApply.Enabled = true;
            }
        }
コード例 #21
0
        /// <summary>
        /// Makes a snapshot of the map and saves it in the image folder with the name of the example
        /// </summary>
        private void btnSnapshot_Click(object sender, EventArgs e)
        {
            TreeNode node = this.treeView1.SelectedNode;

            if (node != null && node.Tag != null)
            {
                Example ex = node.Tag as Example;
                if (ex != null)
                {
                    MapWinGIS.Image img = (MapWinGIS.Image) this.axMap1.SnapShot(this.axMap1.Extents);
                    if (img != null)
                    {
                        string filename = Path.GetDirectoryName(Application.ExecutablePath) +
                                          @"..\..\..\..\Resources\images\" + ex.function + ".png";
                        img.Save(filename, false, MapWinGIS.ImageType.USE_FILE_EXTENSION, null);
                    }
                }
            }
        }
コード例 #22
0
        public void GetImageRepTest()
        {
            Layers target   = new Layers();                // TODO: Initialize to an appropriate value
            string filename = string.Empty;                // TODO: Initialize to an appropriate value

            MapWinGIS.Image newImage               = null; // TODO: Initialize to an appropriate value
            MapWinGIS.Image newImageExpected       = null; // TODO: Initialize to an appropriate value
            Grid            newGrid                = null; // TODO: Initialize to an appropriate value
            Grid            newGridExpected        = null; // TODO: Initialize to an appropriate value
            GridColorScheme GrdColorScheme         = null; // TODO: Initialize to an appropriate value
            GridColorScheme GrdColorSchemeExpected = null; // TODO: Initialize to an appropriate value
            ICallback       cb         = null;             // TODO: Initialize to an appropriate value
            ICallback       cbExpected = null;             // TODO: Initialize to an appropriate value

            target.GetImageRep(filename, ref newImage, ref newGrid, ref GrdColorScheme, ref cb);
            Assert.AreEqual(newImageExpected, newImage);
            Assert.AreEqual(newGridExpected, newGrid);
            Assert.AreEqual(GrdColorSchemeExpected, GrdColorScheme);
            Assert.AreEqual(cbExpected, cb);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
コード例 #23
0
 private MapWinGIS.Image OpenMarker(string path)
 {
     if (!File.Exists(path))
     {
         MessageBox.Show("Can't find the file: " + path);
     }
     else
     {
         MapWinGIS.Image img = new MapWinGIS.Image();
         if (!img.Open(path, ImageType.USE_FILE_EXTENSION, true, null))
         {
             MessageBox.Show(img.ErrorMsg[img.LastErrorCode]);
             img.Close();
         }
         else
         {
             return(img);
         }
     }
     return(null);
 }
コード例 #24
0
        private void UpdateGridToMap()
        {
            int layerHandler;

            /*
             * foreach (MapWinGIS.Image UpdateMapGridImage in gridImages)
             * {
             *  layerHandler = Map.AddLayer(GridImage, true);
             *  gridLayerHandlers.Add(layerHandler);
             *  Map.set_ImageLayerPercentTransparent(layerHandler, ((float)vSclbTransparent.Value) / 100);
             * }
             *
             * Map.ZoomToMaxExtents();
             */
            MapWinGIS.Image img = new MapWinGIS.Image();
            img.Open((string)Map.Tag);
            layerHandler = Map.AddLayer(img, true);
            gridLayerHandlers.Add(layerHandler);
            Map.set_ImageLayerPercentTransparent(layerHandler, ((float)vSclbTransparent.Value) / 100);
            Map.ZoomToMaxExtents();
        }
コード例 #25
0
        /// <summary>
        /// Reprojects layer of undefined type
        /// </summary>
        /// <param name="filename">Filename of layer to reproject. A changed name will be returned when new file was created</param>
        /// <param name="projection">New projection</param>
        /// <param name="inPlace">Whether new files should be written</param>
        /// <param name="report">A reference to report form</param>
        /// <returns>True on success and false otherwise</returns>
        public static TestingResult ReprojectLayer(LayerSource layer, out LayerSource newLayer, MapWinGIS.GeoProjection projection, frmTesterReport report)
        {
            newLayer = null;
            TestingResult result = TestingResult.Error;

            switch (layer.Type)
            {
            case LayerSourceType.Shapefile:
                MapWinGIS.Shapefile sfNew = null;
                result = CoordinateTransformation.Reproject(layer.Shapefile, out sfNew, projection, report);
                if (sfNew != null)
                {
                    newLayer = new LayerSource(sfNew);
                }
                break;

            case LayerSourceType.Grid:
                MapWinGIS.Grid gridNew = null;
                result = CoordinateTransformation.Reproject(layer.Grid, out gridNew, projection, report);
                if (gridNew != null)
                {
                    newLayer = new LayerSource(gridNew);
                }
                break;

            case LayerSourceType.Image:
                MapWinGIS.Image imageNew = null;
                result = CoordinateTransformation.Reproject(layer.Image, out imageNew, projection, report);
                if (imageNew != null)
                {
                    newLayer = new LayerSource(imageNew);
                }
                break;

            default:
                System.Diagnostics.Debug.Print("Coordinate transformation: unsupported interface");
                break;
            }
            return(result);
        }
コード例 #26
0
ファイル: MenuForm.cs プロジェクト: phantom1999/busbaf
        private void PointIco(string icopath)
        {
            int index = _shape.Table.FieldIndexByName["cat"];
            var names = new HashSet <string>();

            for (int i = 0; i < _shape.Table.NumRows; i++)
            {
                names.Add(_shape.Table.CellValue[index, i].ToString());
            }

            string[] files = Directory.GetFiles(icopath);
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = _shape.Categories.Add(name);

                        ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture;

                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;

                        ct.DrawingOptions.DrawingMode = tkVectorDrawingMode.vdmGDIPlus;

                        _shape.CollisionMode      = tkCollisionMode.AllowCollisions;
                        ct.Expression             = " [cat]=" + name;
                        ct.DrawingOptions.Picture = img;

                        _shape.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }

                _shape.Categories.ApplyExpressions();
            }
        }
コード例 #27
0
        /// <summary>
        /// handles an image added to the map using file open dialog
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public int AddLayer(MapWinGIS.Image image, string layerName = "", bool isVisible = true)
        {
            var h = _axmap.AddLayer(image, isVisible);

            if (h >= 0)
            {
                if (layerName.Length == 0)
                {
                    layerName = Path.GetFileName(image.Filename);
                }

                _axmap.set_LayerName(h, layerName);
                _currentMapLayer = SetMapLayer(h, layerName, isVisible, true, image.GeoProjection, "ImageClass", image.Filename);

                if (LayerRead != null)
                {
                    LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType);
                    LayerRead(this, lp);
                }
            }
            return(h);
        }
コード例 #28
0
        public void MapMouseUp(int Button, int Shift, int x, int y, ref bool Handled)
        {
            try
            {
                if (Activated)
                {
                    m_MouseDown = false;

                    //exit if their is no layers
                    if (m_MapWin.Layers.NumLayers <= 0)
                    {
                        return;
                    }

                    //if a wms layer is selected and visible, broadcast so position can be checked
                    if (m_OnWMSLayer)
                    {
                        if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Visible)
                        {
                            m_MapWin.Plugins.BroadcastMessage("Identifier_Clicked_WMS " + x.ToString() + " " + y.ToString());
                        }
                        else
                        {
                            m_WMSLayerIDReturn = "Error: WMS Data Not Visible. Try Zooming In.";
                            LoadLayer();
                        }
                    }
                    else //Go about the normal selection
                    {
                        MapWinGIS.Extents BoundBox;
                        object            selShapes = new object();
                        double            tolx1 = 0, toly1 = 0, tolx2 = 0, toly2 = 0, tol = 0;
                        object            obj       = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetObject();
                        string            layerName = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name;
                        MapWindow.Interfaces.eLayerType LayerType = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType;

                        //get the selected region
                        BoundBox = GetBoundBox(m_Bounds);

                        //if layer is a shapefile then do the following
                        if (LayerType == MapWindow.Interfaces.eLayerType.LineShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PointShapefile ||
                            LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                        {
                            if (m_GridPropfrm.Visible)
                            {
                                m_GridPropfrm.Hide();
                            }

                            Shapefile shpFile = (Shapefile)obj;

                            //clear all the selected shapes
                            m_MapWin.View.SelectedShapes.ClearSelectedShapes();

                            //calculate tolerance
                            double r;
                            if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].PointType == MapWinGIS.tkPointType.ptUserDefined)
                            {
                                MapWinGIS.Image image = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].UserPointType;
                                r = (image.Width + image.Height) / 2;
                            }
                            else
                            {
                                r = 3;
                            }

                            m_MapWin.View.PixelToProj(x - r, y - r, ref tolx1, ref toly1);
                            m_MapWin.View.PixelToProj(x + r, y + r, ref tolx2, ref toly2);
                            tol = System.Math.Sqrt(System.Math.Pow((tolx1 - tolx2), 2) + System.Math.Pow((toly1 - toly2), 2));

                            bool SelectedShapes = shpFile.SelectShapes(BoundBox, tol, MapWinGIS.SelectMode.INTERSECTION, ref selShapes);

                            //display the selected shapes
                            if (SelectedShapes)
                            {
                                AddSelectShapes(selShapes);
                                m_shpFilePropfrm.PopulateForm(!m_HavePanel, shpFile, (int[])selShapes, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                            }
                            else
                            {
                                m_shpFilePropfrm.PopulateForm(!m_HavePanel, shpFile, m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].Name, false);
                            }
                        }
                        //if the layer is a grid do the following
                        else if (LayerType == MapWindow.Interfaces.eLayerType.Grid)
                        {
                            if (m_shpFilePropfrm.Visible)
                            {
                                m_WMSPropfrm.Hide();
                                m_shpFilePropfrm.Hide();
                            }

                            //get the grid object
                            Grid grid = m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].GetGridObject;

                            if (grid != null)
                            {
                                m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                            }
                            else
                            {
                                m_GridPropfrm.Hide();
                            }
                        }
                        //if the layer is a image do the following
                        else if (LayerType == MapWindow.Interfaces.eLayerType.Image)
                        {
                            if (m_shpFilePropfrm.Visible)
                            {
                                m_WMSPropfrm.Hide();
                                m_shpFilePropfrm.Hide();
                            }

                            Grid grid = FindAssociatedGrid(((MapWinGIS.Image)obj).Filename);

                            if (grid != null)
                            {
                                m_GridPropfrm.PopulateForm(!m_HavePanel, grid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                            }
                            else
                            {
                                // Identify by values -- so just open the first band of the image.
                                // This only works for greyscale of course in this version (one band grids only)

                                Grid tmpGrid = new Grid();
                                try
                                {
                                    // Open as a grid to get values
                                    if (tmpGrid.Open(((MapWinGIS.Image)obj).Filename, GridDataType.UnknownDataType, false, GridFileType.UseExtension, null))
                                    {
                                        m_GridPropfrm.PopulateForm(!m_HavePanel, tmpGrid, layerName, BoundBox, m_MapWin.Layers.CurrentLayer);
                                    }
                                    else
                                    {
                                        MapWinUtility.Logger.Message("No information on this image can be displayed.", "Identifier", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, DialogResult.OK);
                                        m_GridPropfrm.Hide();
                                    }
                                }
                                catch
                                {
                                    m_GridPropfrm.Hide();
                                }
                            }
                        }
                    }

                    //set handled
                    Handled = true;
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("MapMouseUp()", ex.Message);
            }
        }
コード例 #29
0
        public static BitmapSource CreateEmpty()
        {
            var img = new Image();

            return(new BitmapSource(img));
        }
コード例 #30
0
        /// <summary>
        /// Load map layers from XML file generated by axmap.SaveMapState.
        ///
        /// Layers are added to the map and is followed by restoring the map extent.
        /// The first added layer automatically sets the map control's projection.
        /// </summary>
        /// <param name="restoreMapState">
        /// When restoreMapState:true, map state is restored
        /// We use restoreMapState:false to load the layers but not restore axMap extent.
        /// </param>
        public void LoadMapState(bool restoreMapState = true)
        {
            _fileMapState = $@"{global.ApplicationPath}\mapstate";
            if (File.Exists(_fileMapState))
            {
                var doc      = new XmlDocument();
                var proceed  = true;
                var fileName = "";
                try
                {
                    doc.Load(_fileMapState);
                }
                catch (XmlException ex)
                {
                    Logger.Log(ex.Message, "MapLayersHandler", "LoadMapState");
                    proceed = false;
                }
                if (proceed)
                {
                    foreach (XmlNode ly in doc.DocumentElement.SelectNodes("//Layer"))
                    {
                        fileName = ly.Attributes["Filename"].Value;
                        var isVisible = true;
                        isVisible = ly.Attributes["LayerVisible"]?.Value == "1";
                        if (ly.Attributes["LayerType"].Value == "Shapefile")
                        {
                            var sf = new Shapefile();
                            if (sf.Open(fileName))
                            {
                                var h = AddLayer(sf, ly.Attributes["LayerName"].Value, isVisible);
                                _sfSymbologyHandler.SymbolizeLayer(ly.InnerXml);
                                _currentMapLayer.Visible = ly.Attributes["LayerVisible"].Value == "1";
                                _sfLabelHandler          = new ShapefileLabelHandler(_currentMapLayer);

                                if (ly.FirstChild.Name == "ShapefileClass")
                                {
                                    foreach (XmlNode child in ly.FirstChild.ChildNodes)
                                    {
                                        if (child.Name == "LabelsClass" && child.Attributes["Generated"].Value == "1")
                                        {
                                            _currentMapLayer.IsLabeled = child.Attributes["Generated"].Value == "1";
                                            _sfLabelHandler.LabelShapefile(child.OuterXml);
                                        }
                                    }
                                }
                            }
                        }
                        else if (ly.Attributes["LayerType"].Value == "Image")
                        {
                            //code when layertype is image
                            var img = new MapWinGIS.Image();
                            if (img.Open(fileName))
                            {
                                var h = AddLayer(img, ly.Attributes["LayerName"].Value, isVisible);
                            }
                        }
                    }
                    if (restoreMapState)
                    {
                        //We restore saved extent of the map but not the projection. Since layers
                        //were already added to the map, the first layer sets the map's projection.
                        foreach (XmlNode ms in doc.DocumentElement.SelectNodes("//MapState "))
                        {
                            var ext = new Extents();
                            ext.SetBounds(
                                double.Parse(ms.Attributes["ExtentsLeft"].Value),
                                double.Parse(ms.Attributes["ExtentsBottom"].Value),
                                0,
                                double.Parse(ms.Attributes["ExtentsRight"].Value),
                                double.Parse(ms.Attributes["ExtentsTop"].Value),
                                0);
                            _axmap.Extents   = ext;
                            _axmap.ExtentPad = double.Parse(ms.Attributes["ExtentsPad"].Value);
                        }
                    }
                }
            }
            else
            {
                File.Create(_fileMapState);
            }
        }