Example #1
0
        public void TestGdalRasterLayer()
        {
            if (!System.IO.File.Exists("D:\\Daten\\zone49_mga.ecw"))
            {
                NUnit.Framework.Assert.Ignore("Adjust file path");
            }
            if (!System.IO.File.Exists("D:\\Daten\\zone50_mga.ecw"))
            {
                NUnit.Framework.Assert.Ignore("Adjust file path");
            }

            var ecw1 = new SharpMap.Layers.GdalRasterLayer("zone49", "D:\\Daten\\zone49_mga.ecw");
            var ecw2 = new SharpMap.Layers.GdalRasterLayer("zone50", "D:\\Daten\\zone50_mga.ecw");

            var p1 = ecw1.GetProjection();

            ecw2.ReprojectToCoordinateSystem(p1);

            var m = new SharpMap.Map(new System.Drawing.Size(1024, 768));

            m.Layers.Add(ecw1);
            m.Layers.Add(ecw2);

            m.ZoomToExtents();
            using (var img = m.GetMap())
            {
                img.Save("ecw.png");
            }
        }
Example #2
0
        /// <summary>
        /// 获得当前影像的范围
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="isShapeFile"></param>
        /// <param name="gcsWkt"></param>
        /// <returns></returns>
        public static Envelop GetEnvelop(string fileName, bool isShapeFile, string gcsWkt)
        {
            ICoordinateSystem srcCoor = null;

            SharpMap.Layers.Layer layer = null;
            if (isShapeFile)
            {
                SharpMap.Layers.VectorLayer l = new SharpMap.Layers.VectorLayer(Path.GetFileNameWithoutExtension(fileName));
                l.DataSource = new SharpMap.Data.Providers.ShapeFile(fileName, true);
                l.SRID       = 4326;
                srcCoor      = ((SharpMap.Data.Providers.ShapeFile)l.DataSource).CoordinateSystem;
                layer        = l;
            }
            else
            {
                SharpMap.Layers.GdalRasterLayer l = new SharpMap.Layers.GdalRasterLayer(Path.GetFileNameWithoutExtension(fileName), fileName);
                l.SRID    = 4326;
                l.Enabled = true;
                srcCoor   = l.GetProjection();
                layer     = l;
            }

            Envelop envelop = new Envelop();

            //if (srcCoor != null)
            //{
            //    CoordinateSystemFactory cFac = new CoordinateSystemFactory();
            //    ICoordinateSystem tarCoor = cFac.CreateFromWkt(gcsWkt);
            //    ICoordinateTransformation transform = null;
            //    try
            //    {
            //        transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(srcCoor, tarCoor);
            //    }
            //    catch (Exception e)
            //    {
            //        return new Envelop();
            //    }

            //    SharpMap.Geometries.BoundingBox imageBox = GeometryTransform.TransformBox(layer.Envelope, transform.MathTransform);

            //    envelop.North = imageBox.Top;
            //    envelop.South = imageBox.Bottom;
            //    envelop.West = imageBox.Left;
            //    envelop.East = imageBox.Right;
            //}
            //else
            //{
            envelop.East  = layer.Envelope.Right;
            envelop.West  = layer.Envelope.Left;
            envelop.North = layer.Envelope.Top;
            envelop.South = layer.Envelope.Bottom;
            //}
            return(envelop);
        }
        public void TestGdalRasterLayer()
        {
            if (!System.IO.File.Exists("D:\\Daten\\zone49_mga.ecw"))
                NUnit.Framework.Assert.Ignore("Adjust file path");
            if (!System.IO.File.Exists("D:\\Daten\\zone50_mga.ecw"))
                NUnit.Framework.Assert.Ignore("Adjust file path");

            var ecw1 = new SharpMap.Layers.GdalRasterLayer("zone49", "D:\\Daten\\zone49_mga.ecw");
            var ecw2 = new SharpMap.Layers.GdalRasterLayer("zone50", "D:\\Daten\\zone50_mga.ecw");

            var p1 = ecw1.GetProjection();
            ecw2.ReprojectToCoordinateSystem(p1);

            var m = new SharpMap.Map(new System.Drawing.Size( 1024, 768));
            m.Layers.Add(ecw1);
            m.Layers.Add(ecw2);

            m.ZoomToExtents();
            using (var img = m.GetMap())
            {
                img.Save("ecw.png");
            }
        }