//[SetUp] public void DataReady(Action <int, string> progressCallback) { try { ///等经纬度投影 dstFilename = @"D:\mas数据\Mersi\fy3_Block.ldf"; dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");// srcFilename = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF"; dstEnvelope = PrjEnvelope.CreateByCenter(116.890377, 27.7621965, 33.49, 21.53); srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider; prjSetting = new FY3_MERSI_PrjSettings(); //prjSetting.OutResolutionX = 0.01F; //prjSetting.OutResolutionY = 0.01F; prjSetting.OutPathAndFileName = dstFilename; prjSetting.OutFormat = "LDF"; //prjSetting.OutEnvelope = dstEnvelope; //prjSetting.BandMapTable = bandmapList; prjSetting.IsRadiation = true; _progressCallback = progressCallback; } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(ex.Message); } }
private enumCoordinateType GetCoordinateType(SpatialFeatureClass spatialFeatureClass, out ISpatialReference spref) { spref = null; try { ISpatialReference rf = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(spatialFeatureClass.SpatialRef) as ISpatialReference; spref = rf; if (rf == null) { goto ensureByEnvelopeLine; } if (rf.ProjectionCoordSystem == null) { return(enumCoordinateType.Geographic); } else { return(enumCoordinateType.Projection); } } catch { goto ensureByEnvelopeLine; } ensureByEnvelopeLine: return(spatialFeatureClass.Envelope.IsGeoRange() ? enumCoordinateType.Geographic : enumCoordinateType.Projection); }
//[SetUp] public void DataReady(Action <int, string> progressCallback) { ///等经纬度投影 dstFilename = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD02HKM.ldf"; dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); // srcFilename = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD02HKM.HDF"; dstEnvelope = PrjEnvelope.CreateByCenter(110, 32, 5, 5); // string secondFile = @"D:\mas数据\MODIS\TERRA_2010_03_25_03_09_GZ.MOD03.HDF"; IRasterDataProvider secondFileRaster = GeoDataDriver.Open(secondFile) as IRasterDataProvider; srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider; //List<BandMap> bandmapList = new List<BandMap>(); prjSetting = new EOS_MODIS_PrjSettings(); prjSetting.OutResolutionX = 0.0025F; prjSetting.OutResolutionY = 0.0025F; prjSetting.OutPathAndFileName = dstFilename; prjSetting.OutFormat = "LDF"; //prjSetting.OutEnvelope = dstEnvelope; //prjSetting.BandMapTable = bandmapList; //prjSetting.IsRadiation = false; prjSetting.SecondaryOrbitRaster = null; prjSetting.LocationFile = secondFileRaster; _progressCallback = progressCallback; }
public string TestDstExtendWGS84() { try { PrjEnvelope dstEnvelope; dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); srcFilename = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF"; srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider; IFileProjector proj = FileProjector.GetFileProjectByName("FY3_MERSI"); proj.ComputeDstEnvelope(srcRaster, dstSpatialRef, out dstEnvelope, _progressCallback); Console.WriteLine(dstEnvelope.ToString()); return(dstEnvelope.ToString()); } finally { if (srcRaster != null) { if (srcRaster.BandProvider != null) { srcRaster.BandProvider.Dispose(); } srcRaster.Dispose(); } } }
public void TestProjMap() { string proj4Str = "proj +proj=stere +lon_0=0 +lat_0=-90 +lat_ts=-71 +ellps=WGS84 +datum=WGS84"; ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4Str); Console.WriteLine(srcSpatialRef.ToString()); }
private void button1_Click(object sender, EventArgs e) { ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); string prj4 = srcSpatialRef.ToProj4String(); ISpatialReference dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); using (IProjectionTransform tran = ProjectionTransformFactory.GetProjectionTransform(srcSpatialRef, dstSpatialRef)) { } }
public void Test() { ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj"); string proj4 = srcSpatialRef.ToProj4String(); Assert.AreEqual(proj4, "+proj=merc +x_0=0 +y_0=0 +lon_0=0 +lat_1=0 +datum=WGS84 +a=6371000 +b=6356863.01877305+f=正无穷大 +nodefs"); srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4); }
//private void button4_Click(object sender, EventArgs e) //{ // ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); // srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj"); // string proj4 = srcSpatialRef.ToProj4String(); // srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4); //} //private void button4_Click(object sender, EventArgs e) //{ // TestFy3AVirrProjection fyp = new TestFy3AVirrProjection(); // Action<int, string> progressCallback = new Action<int, string>(OutProgress); // fyp.DataReady(progressCallback); // Stopwatch stopwatch = new Stopwatch(); // stopwatch.Start(); // fyp.TestFy3VIRR(); // stopwatch.Stop(); // WriteLine("数据投影{0}ms", stopwatch.ElapsedMilliseconds); // stopwatch.Restart(); //} private void TestPrj4Parser_Click(object sender, EventArgs e) { ISpatialReference srcSpatialRef = null;// SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); string prjFile = "f:\\32600.prj"; srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("Mercator (sphere).prj"); string proj4 = srcSpatialRef.ToProj4String(); ISpatialReference inverSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4); bool isSame = srcSpatialRef.IsSame(inverSpatialRef); }
private ISpatialReference GetSpatialReference(string projectionIdentify) { switch (projectionIdentify) { case "ABS": return(SpatialReferenceFactory.GetSpatialReferenceByPrjFile("\\")); //return new SpatialReference(new GeographicCoordSystem(), new ProjectionCoordSystem()); case "GLL": default: return(SpatialReference.GetDefault()); } }
private void BindChild(TreeNode fNode) { string path = fNode.Name; if (path == null || !Directory.Exists(path)) { return; } DirectoryInfo fDir = new DirectoryInfo(path); FileSystemInfo[] finfos = fDir.GetFileSystemInfos(); SpatialReferenceFile spatialRefFile; foreach (FileSystemInfo f in finfos) { spatialRefFile = new SpatialReferenceFile(); string type = f.GetType().ToString(); TreeNode node = new TreeNode(); node.Name = f.FullName; //将文件的完整路径保存在节点的名字中 if ("System.IO.DirectoryInfo" == type) //是文件夹才递归调用自己 { spatialRefFile.IsPrjFile = false; node.Tag = spatialRefFile; node.ImageIndex = 0; node.SelectedImageIndex = 2; node.Text = f.Name; //将文件的名字保存在节点的文本显示中 fNode.Nodes.Add(node); BindChild(node); } else { if (!f.Name.Contains(".prj")) { continue; } if (f.Name.Substring(f.Name.LastIndexOf('.')) != ".prj") { continue; } node.Text = f.Name.Remove(f.Name.LastIndexOf('.')); spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(f.FullName); //是否能成功解析prj文件 spatialRefFile.IsPrjFile = true; node.Tag = spatialRefFile; node.ImageIndex = 1; node.SelectedImageIndex = 1; fNode.Nodes.Add(node); } } }
/// <summary> /// 解析坐标系统文件夹,并添加到树中 /// </summary> /// <param name="fNode"></param> private void BindChild(TreeNode fNode) { string path = fNode.Name; if (path == null || !Directory.Exists(path)) { return; } string[] paths = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); SpatialReferenceFile spatialRefFile; for (int i = 0; i < paths.Length; i++) { string subPath = paths[i]; TreeNode node = new TreeNode(); node.Name = subPath; spatialRefFile = new SpatialReferenceFile(); spatialRefFile.IsPrjFile = false; node.Tag = spatialRefFile; node.ImageIndex = 0; node.SelectedImageIndex = 2; node.Text = Path.GetFileNameWithoutExtension(subPath); fNode.Nodes.Add(node); BindChild(node); } for (int i = 0; i < files.Length; i++) { string subFile = files[i]; string fileExt = Path.GetExtension(subFile); if (fileExt != ".prj") { continue; } TreeNode node = new TreeNode(); node.Name = subFile; node.Text = Path.GetFileNameWithoutExtension(subFile); spatialRefFile = new SpatialReferenceFile(); spatialRefFile.SpatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(subFile); spatialRefFile.IsPrjFile = true; node.Tag = spatialRefFile; node.ImageIndex = 1; node.SelectedImageIndex = 1; fNode.Nodes.Add(node); } }
public override void Click() { IMapControl mapControl = (_hook as IHookOfAgileMap).MapControl; if (mapControl != null) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "ESRI Projection Files(*.prj)|*.prj"; if (dlg.ShowDialog() == DialogResult.OK) { ISpatialReference sref = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(dlg.FileName); mapControl.SpatialReference = sref; } } } }
private static ISpatialReference[] GetCustomSpatialReferences() { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "坐标系统\\自定义"); if (!Directory.Exists(path)) { return(null); } string[] files = Directory.GetFiles(path); if (files == null || files.Length == 0) { return(null); } List <ISpatialReference> spatialReferenceList = new List <ISpatialReference>(); ISpatialReference spatialReference; for (int i = 0; i < files.Length; i++) { string file = files[i]; spatialReference = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(file); if (spatialReference == null) { continue; } spatialReferenceList.Add(spatialReference); } //将等经纬度的调整为第一个 List <ISpatialReference> glls = spatialReferenceList.FindAll( match => match.Name.Contains("等经纬度") || (match.ProjectionCoordSystem == null && match.GeographicsCoordSystem != null) ); if (glls != null && glls.Count != 0) { foreach (ISpatialReference gl in glls) { spatialReferenceList.Remove(gl); } spatialReferenceList.InsertRange(0, glls); } return(spatialReferenceList.ToArray()); }
public void btnSure_Click(object sender, EventArgs e) { switch (cmbOutRange.SelectedItem.ToString()) { case "整轨投影": ProParas.PrjSetting.OutEnvelope = null; break; case "按中心点": ProParas.PrjSetting.OutEnvelope = PrjEnvelope.CreateByCenter(Convert.ToDouble(txtCenterX.Text), Convert.ToDouble(txtCenterY.Text), Convert.ToDouble(numerWidth.Value), Convert.ToDouble(numerHeight.Value)); break; case "按四角经纬度": ProParas.PrjSetting.OutEnvelope.MinX = Convert.ToDouble(txtMinX.Text); ProParas.PrjSetting.OutEnvelope.MaxX = Convert.ToDouble(txtMaxX.Text); ProParas.PrjSetting.OutEnvelope.MinY = Convert.ToDouble(txtMinY.Text); ProParas.PrjSetting.OutEnvelope.MaxY = Convert.ToDouble(txtMaxY.Text); break; case "按已定义的输出区域": ProParas.PrjSetting.OutEnvelope = null; break; } switch (cmbProType.SelectedItem.ToString()) { case "等经纬度投影": ProParas.DstSpatialRef = new SpatialReference(new GeographicCoordSystem()); break; case "麦卡托投影": ProParas.DstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("MASMercator.prj"); break; case "兰勃托投影": ProParas.DstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("MASLambert.prj"); break; case "极射赤面投影": ProParas.DstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("MasPolarStere.prj"); break; case "等面积投影": //ProParas.DstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(""); break; } }
//[SetUp] public void DataReady(Action <int, string> progressCallback) { IRasterDataProvider secondFileRaster = null; try { ///等经纬度投影 dstFilename = @"D:\mas数据\Mersi\fy3Mersi0250_Block.ldf"; dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); // srcFilename = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_0250M_MS.HDF"; dstEnvelope = PrjEnvelope.CreateByCenter(110, 32, 5, 5); // string secondFile = @"D:\mas数据\Mersi\FY3A_MERSI_GBAL_L1_20110501_0250_1000M_MS.HDF"; secondFileRaster = GeoDataDriver.Open(secondFile) as IRasterDataProvider; srcRaster = GeoDataDriver.Open(srcFilename) as IRasterDataProvider; //List<BandMap> bandmapList = new List<BandMap>(); prjSetting = new FY3_MERSI_PrjSettings(); prjSetting.OutResolutionX = 0.0025F; prjSetting.OutResolutionY = 0.0025F; prjSetting.OutPathAndFileName = dstFilename; prjSetting.OutFormat = "LDF"; //prjSetting.OutEnvelope = dstEnvelope; //prjSetting.BandMapTable = bandmapList; //prjSetting.IsRadiation = false; prjSetting.SecondaryOrbitRaster = secondFileRaster; _progressCallback = progressCallback; } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(ex.Message); } finally { if (secondFileRaster != null) { secondFileRaster.Dispose(); } } }
private void btnOpen_Click(object sender, EventArgs e) { try { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "ESRI Projection Files(*.prj)|*.prj"; if (dlg.ShowDialog() == DialogResult.OK) { ISpatialReference sref = SpatialReferenceFactory.GetSpatialReferenceByPrjFile(dlg.FileName); richTextBox1.Text = (sref as ISpatialRefFormat).FormatToString(); textBox1.Text = dlg.FileName; textBox1.Tag = sref; } } } catch (Exception ex) { textBox1.Text = string.Empty; textBox1.Tag = null; richTextBox1.Text = string.Empty; MsgBox.ShowError(ex.Message); } }
private void TestProj() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Size srSize = Size.Empty; Double[] lats = null; Double[] longs = null; using (IRasterDataProvider srcPrd = GeoDataDriver.Open(@"D:\masData\FY3A_VIRRX_GBAL_L1_20110322_0525_1000M_MS.HDF") as IRasterDataProvider) { using (IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider) { srSize = new System.Drawing.Size(srcPrd.Width, srcPrd.Height); lats = new Double[srcPrd.Width * srcPrd.Height]; longs = new Double[srcPrd.Width * srcPrd.Height]; using (IRasterBand latBand = srcbandpro.GetBands("Latitude")[0]) { using (IRasterBand lonsBand = srcbandpro.GetBands("Longitude")[0]) { unsafe { fixed(Double *ptrLat = lats) { fixed(Double *ptrLong = longs) { IntPtr bufferPtrLat = new IntPtr(ptrLat); IntPtr bufferPtrLong = new IntPtr(ptrLong); latBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLat, enumDataType.Double, srcPrd.Width, srcPrd.Height); lonsBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLong, enumDataType.Double, srcPrd.Width, srcPrd.Height); } } } } } stopwatch.Stop(); WriteLine("读取经纬度{0}ms", stopwatch.ElapsedMilliseconds); stopwatch.Restart(); IRasterProjector raster = new RasterProjector(); PrjEnvelope destEnvelope; Action <int, string> progressCallback = new Action <int, string>(OutProgress); //progressCallback = null; //测试不用进度条的情况 ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj"); ISpatialReference dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("ChinaBoundary.prj"); raster.ComputeDstEnvelope(srcSpatialRef, longs, lats, srSize, dstSpatialRef, out destEnvelope, progressCallback); stopwatch.Stop(); WriteLine("计算范围{0}ms", stopwatch.ElapsedMilliseconds); WriteLine("范围{0}", destEnvelope.ToString()); Size dstSize = new Size((int)(destEnvelope.Width / 0.01), (int)(destEnvelope.Height / 0.01)); UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height]; raster.ComputeIndexMapTable(srcSpatialRef, longs, lats, srSize, dstSpatialRef, dstSize, destEnvelope, out dstRowLookUpTable, out dstColLookUpTable, progressCallback); stopwatch.Stop(); WriteLine("计算投影查找表{0}ms", stopwatch.ElapsedMilliseconds); stopwatch.Restart(); int srcBandCount = srcPrd.BandCount; using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver) { string proj4 = dstSpatialRef.ToProj4String(); using (IRasterDataProvider prdWriter = drv.Create(@"d:\Myproj4LutX.ldf", dstSize.Width, dstSize.Height, srcBandCount, enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + proj4) as IRasterDataProvider) { UInt16[] dstData = new UInt16[dstSize.Width * dstSize.Height]; UInt16[] srcData = new UInt16[srSize.Width * srSize.Height]; //int perProgress = 0; //int curProgress = 0; for (int i = 0; i < srcBandCount; i++) { using (IRasterBand latBand = srcPrd.GetRasterBand(i + 1)) { unsafe { fixed(UInt16 *ptr = srcData) { IntPtr bufferptr = new IntPtr(ptr); latBand.Read(0, 0, srSize.Width, srSize.Height, bufferptr, enumDataType.UInt16, srSize.Width, srSize.Height); } } } //stopwatch.Stop(); //WriteLine("读取一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1); //stopwatch.Restart(); raster.Project <UInt16>(srcData, srSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstData, 0, progressCallback); //stopwatch.Stop(); //WriteLine("投影一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1); //stopwatch.Restart(); using (IRasterBand band = prdWriter.GetRasterBand(i + 1)) { unsafe { fixed(UInt16 *ptr = dstData) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height); } } } //curProgress = (i+1) * 100 / srcBandCount; //if (progressCallback != null && curProgress > perProgress) //{ // progressCallback(curProgress, ""); // perProgress = curProgress; //} //stopwatch.Stop(); //WriteLine("写出一个通道{0}ms", stopwatch.ElapsedMilliseconds); //stopwatch.Restart(); } } } stopwatch.Stop(); WriteLine("投影完所有通道{0}ms", stopwatch.ElapsedMilliseconds); stopwatch.Restart(); } } }