private static SharpMap.Map InitializeVRT(ref int index, float angle) { SharpMap.Map map = new SharpMap.Map(); int ind = index - 6; if (ind >= Vrts.Length) { ind = 0; } if (!System.IO.File.Exists(RelativePath + Vrts[ind])) { throw new System.Exception("Make sure the data is in the relative directory: " + RelativePath); } SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer("VirtualRasterTable", RelativePath + Vrts[ind]); var ext = System.IO.Path.GetExtension(layer.Filename); map.Layers.Add(layer); _gdalSampleDataset = string.Format("'{0}'", ext != null ? ext.ToUpper() : string.Empty); map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; //index++; return(map); }
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"); } }
private static SharpMap.Map InitializeGeoTiff(float angle) { try { var map = new SharpMap.Map(); map.BackColor = System.Drawing.Color.White; const string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; if (!System.IO.File.Exists(relativePath + "format01-image_a.tif")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!System.IO.File.Exists(relativePath + "outline.shp")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = System.Drawing.Brushes.Transparent; shapeLayer.Style.Outline = System.Drawing.Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); map.ZoomToExtents(); //System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); //mat.RotateAt(angle, map.WorldToImage(map.Center)); //map.MapTransform = mat; return(map); } catch (System.TypeInitializationException ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { throw new System.Exception( string.Format( "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion)); } throw; } }
public static Map InitializeMap() { try { //Sample provided by Dan Brecht and Joel Wilson Map map = new Map(); map.BackColor = Color.White; string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; if (!File.Exists(relativePath + "format01-image_a.tif")) { throw new Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!File.Exists(relativePath + "outline.shp")) { throw new Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = Brushes.Transparent; shapeLayer.Style.Outline = Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); map.ZoomToExtents(); return map; } catch (Exception ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { throw new Exception(String.Format("The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion)); } throw; } }
/// <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 static Map InitializeMap() { try { //Sample provided by Dan Brecht and Joel Wilson Map map = new Map(); map.BackColor = Color.White; string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; if (!File.Exists(relativePath + "format01-image_a.tif")) { throw new Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!File.Exists(relativePath + "outline.shp")) { throw new Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = Brushes.Transparent; shapeLayer.Style.Outline = Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); map.ZoomToExtents(); return(map); } catch (Exception ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { throw new Exception(String.Format("The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion)); } throw; } }
public void TestIssue116() { string rasterFile = TestUtility.GetPathToTestFile("world.topo.bathy.200412.3x21600x10800.jpg"); if (!System.IO.File.Exists(rasterFile)) { Assert.Ignore("Test file {0} not present.", rasterFile); } using (var map = new SharpMap.Map()) { var rasterLyr = new SharpMap.Layers.GdalRasterLayer("Raster", rasterFile); map.Layers.Add(rasterLyr); var linePoints = new[] { new GeoAPI.Geometries.Coordinate(0, 0), new GeoAPI.Geometries.Coordinate(10, 10) }; var line = NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(4326).CreateLineString(linePoints); var linealDs = new SharpMap.Data.Providers.GeometryProvider(line); var linealLyr = new SharpMap.Layers.VectorLayer("Lineal", linealDs) { SRID = 4326 }; linealLyr.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Red, 2f) { EndCap = System.Drawing.Drawing2D.LineCap.Round }; map.Layers.Add(linealLyr); map.ZoomToExtents(); var centerMap = new System.Drawing.PointF(map.Size.Width / 2f, map.Size.Height / 2f); for (float f = -180; f <= 180; f += 5) { var mapTransform = new System.Drawing.Drawing2D.Matrix(); mapTransform.RotateAt(f, centerMap); map.MapTransform = mapTransform; using (var img = map.GetMap()) img.Save(System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), $"TestIssue116.{(f < 0 ? "N" : "P")}{((int)Math.Abs(f)):D3}deg.png")); } } }
public static SharpMap.Map InitializeMap(int angle, string[] filenames) { if (filenames == null || filenames.Length == 0) { return(null); } var map = new SharpMap.Map(); for (int i = 0; i < filenames.Length; i++) { if (filenames[i].StartsWith("PG:")) { SharpMap.Layers.ILayer lyr = null; try { lyr = new SharpMap.Layers.GdalRasterLayer($"PG_RASTER{i}", filenames[i]); } catch (Exception) { return(null); } map.Layers.Add(lyr); } else { map.Layers.Add(new SharpMap.Layers.GdalRasterLayer(System.IO.Path.GetFileName(filenames[i]), filenames[i])); } } var mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; map.ZoomToExtents(); return(map); }
private static SharpMap.Map InitializeGeoTiff(int index, float angle) { try { //Sample provided by Dan Brecht and Joel Wilson var map = new SharpMap.Map(); map.BackColor = System.Drawing.Color.White; const string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; switch (index) { case 2: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.tif"); layer.UseRotation = true; map.Layers.Add(layer); break; case 3: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.jp2"); layer.UseRotation = true; map.Layers.Add(layer); break; case 4: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "world_raster_mod.tif"); layer.UseRotation = true; map.Layers.Add(layer); break; default: if (!System.IO.File.Exists(relativePath + "format01-image_a.tif")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!System.IO.File.Exists(relativePath + "outline.shp")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = System.Drawing.Brushes.Transparent; shapeLayer.Style.Outline = System.Drawing.Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); break; } map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; if (_num > 5) _num = 1; _gdalSampleDataset = "GeoTiff" + _num; return map; } catch (System.TypeInitializationException ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { throw new System.Exception( string.Format( "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion)); } throw; } }
private static SharpMap.Map InitializeVRT(ref int index, float angle) { SharpMap.Map map = new SharpMap.Map(); int ind = index - 6; if (ind >= Vrts.Length) ind = 0; if (!System.IO.File.Exists(RelativePath + Vrts[ind])) { throw new System.Exception("Make sure the data is in the relative directory: " + RelativePath); } SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer("VirtualRasterTable", RelativePath + Vrts[ind]); var ext = System.IO.Path.GetExtension(layer.Filename); map.Layers.Add(layer); _gdalSampleDataset = string.Format("'{0}'", ext != null ? ext.ToUpper() : string.Empty); map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; //index++; return map; }
private static SharpMap.Map InitializeGeoTiff(int index, float angle) { try { //Sample provided by Dan Brecht and Joel Wilson var map = new SharpMap.Map(); map.BackColor = System.Drawing.Color.White; const string relativePath = "GeoData/GeoTiff/"; SharpMap.Layers.GdalRasterLayer layer; switch (index) { case 0: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.tif"); map.Layers.Add(layer); break; case 1: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.jp2"); map.Layers.Add(layer); break; case 2: layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "world_raster_mod.tif"); map.Layers.Add(layer); break; default: if (!System.IO.File.Exists(relativePath + "format01-image_a.tif")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif"); map.Layers.Add(layer); layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif"); map.Layers.Add(layer); SharpMap.Layers.VectorLayer shapeLayer; if (!System.IO.File.Exists(relativePath + "outline.shp")) { throw new System.Exception("Make sure the data is in the relative directory: " + relativePath); } shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp")); shapeLayer.Style.Fill = System.Drawing.Brushes.Transparent; shapeLayer.Style.Outline = System.Drawing.Pens.Black; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Enabled = true; map.Layers.Add(shapeLayer); break; } //if (layer != null) // layer.UseRotation = true; map.ZoomToExtents(); System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; _gdalSampleDataset = "GeoTiff" + _num; return(map); } catch (System.TypeInitializationException ex) { if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.") { var asm = Assembly.GetAssembly(typeof(OSGeo.GDAL.Gdal)).GetName(); throw new System.Exception( string.Format( "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. " + "They are a part of the GDAL NuGet package v{0}.", asm.Version.ToString(3))); } throw; } }
public override Texture LoadFile(QuadTile qt) { //获取切片的本地路径 string filePath = GetLocalPath(qt); qt.ImageFilePath = filePath; Texture texture = null; string ddsPath = filePath; ////判断是否是DDS文件 if (World.Settings.ConvertDownloadedImagesToDds) { ddsPath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".dds"; } filePath = ddsPath; //判断磁盘上,是否有当前文件,若有,则直接读取,若没有,则重新加载 if (!File.Exists(filePath)) { filePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + "." + ImageExtension; //动态读取Tiff影像中的值 SharpMap.Map map = new SharpMap.Map(); for (int i = 0; i < Layers.Length; i++) { SharpMap.Layers.GdalRasterLayer layer; layer = new SharpMap.Layers.GdalRasterLayer(Path.GetFileNameWithoutExtension(Layers[i]), Layers[i]); layer.SRID = 4326; layer.Enabled = true; map.Layers.Add(layer); } //设置Map的背景色为透明色 map.BackColor = System.Drawing.Color.Transparent; //设置地图的投影 map.Projection = CoordinatesDescription.GCS; //图像的formate System.Drawing.Imaging.ImageCodecInfo imageEncoder = GetEncoderInfo(formate); //图片的大小 map.Size = new System.Drawing.Size(m_textureSizePixels, m_textureSizePixels); //请求图像的范围 string bboxString = ""; bboxString = qt.West.ToString() + "," + qt.South.ToString() + "," + qt.East.ToString() + "," + qt.North.ToString(); SharpMap.Geometries.BoundingBox bbox = this.ParseBBOX(bboxString); //判断图像的拉伸范围 map.PixelAspectRatio = ((double)m_textureSizePixels / (double)m_textureSizePixels) / (bbox.Width / bbox.Height); map.Center = bbox.GetCentroid(); map.Zoom = bbox.Width; //获得当前请求的图片 System.Drawing.Image img = map.GetMap(); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } //保存到本地磁盘 img.Save(filePath); } //设置是否显示图片的无效值 if (qt.QuadTileSet.HasTransparentRange) { texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey, qt.QuadTileSet.ColorKeyMax); } else { texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey); } ////判断,是否转化为dds文件 if (World.Settings.ConvertDownloadedImagesToDds) { ConvertImage(texture, filePath); } //返回当前纹理 return(texture); }
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"); } }