private void CreatPrjElement(XmlDocument doc, XmlNode root, ISpatialReference spatialRef) { XmlNode prjNd = doc.CreateElement("SRS"); prjNd.InnerText = spatialRef.ToWKTString(); root.AppendChild(prjNd); }
private IRasterDataProvider CreateOutFile(FilePrjSettings prjSettings, ISpatialReference dstSpatial, DataIdentify dataIdentify) { float resolutionX = prjSettings.OutResolutionX; float resolutionY = prjSettings.OutResolutionY; string[] options = null; string outformat = string.IsNullOrWhiteSpace(prjSettings.OutFormat) ? ".ldf" : prjSettings.OutFormat.ToLower(); string driver = ""; if (outformat == ".tif" || outformat == ".tiff") { driver = "GDAL"; options = new string[] { "DRIVERNAME=GTiff", "TFW=YES", "WKT=" + dstSpatial.ToWKTString(), "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", prjSettings.OutEnvelope.MinX, resolutionX, 0, prjSettings.OutEnvelope.MaxY, 0, -resolutionY) }; } else { driver = "LDF"; options = LdfOptions(prjSettings, dstSpatial, resolutionX, resolutionY, dataIdentify); List <string> opts = new List <string>(options); opts.Add("BANDNAMES=" + BandNameString(prjSettings.OutBandNos)); options = opts.ToArray(); } Size outSize = prjSettings.OutEnvelope.GetSize(resolutionX, resolutionY); int bandCount = prjSettings.OutBandNos.Length; string filename = prjSettings.OutPathAndFileName; return(CreateOutFile(driver, filename, bandCount, outSize, enumDataType.Int16, options)); }
private void PrintSpatialRefOfFile(string fname) { IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider; Assert.NotNull(prd); ISpatialReference spref = prd.SpatialRef; if (spref != null) { Console.Write(spref.ToWKTString() + "\n"); Console.WriteLine(spref.ProjectionCoordSystem == null ? "Is Geographics Coordinate System" : "Is Projection Coordinate System"); } else { Console.WriteLine("SpatialRef is NULL"); } ICoordTransform rct = prd.CoordTransform; Assert.NotNull(rct); for (int i = -10; i < 100; i++) { for (int j = -10; j < 100; j++) { double x = 0, y = 0; rct.Raster2DataCoord(i, j, out x, out y); Console.Write("(" + x.ToString("0.####").PadRight(7, ' ') + "," + y.ToString("0.####").PadRight(7, ' ') + "),"); } Console.Write("\n"); } }
public void ParserTiff() { string spreftxt = File.ReadAllText("f:\\2.prj"); ISpatialReference spref = SpatialReferenceFactory.GetSpatialReferenceByWKT(spreftxt, enumWKTSource.GDAL); Assert.NotNull(spref); Console.Write(spref.ToWKTString()); }
private void Projection(ISpatialReference proj) { if (proj.ProjectionCoordSystem == null) { ProjGLL(); } else { ExecuteCommand(4001, "#" + proj.ToWKTString()); } }
/// <summary> /// 保存为*.prj文件,同时在目录树上添加节点 /// </summary> private void SaveToPrjFile() { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"坐标系统\自定义\"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileName = _spatialReference.Name + ".prj"; string filePath = Path.Combine(path, fileName); File.WriteAllText(filePath, _spatialReference.ToWKTString(), Encoding.Default); }
private IRasterDataProvider CreateOutFile(IRasterDataProvider srcRaster, FilePrjSettings prjSettings, ISpatialReference dstSpatial, enumDataType dataType) { float resolutionX = prjSettings.OutResolutionX; float resolutionY = prjSettings.OutResolutionY; string[] options = null; string outformat = string.IsNullOrWhiteSpace(prjSettings.OutFormat) ? "LDF" : prjSettings.OutFormat.ToUpper(); string driver = ""; if (outformat == "TIFF") { driver = "GDAL"; options = new string[] { "DRIVERNAME=GTiff", "TFW=YES", "WKT=" + dstSpatial.ToWKTString(), "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", prjSettings.OutEnvelope.MinX, resolutionX, 0, prjSettings.OutEnvelope.MaxY, 0, -resolutionY) }; } else if (outformat == "MEM") { driver = "MEM"; options = new string[] { "INTERLEAVE=BSQ", "VERSION=MEM", "WITHHDR=TRUE", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}" }; } else { driver = "LDF"; options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstSpatial.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + prjSettings.OutEnvelope.MinX + "," + prjSettings.OutEnvelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}", "BANDNAMES=" + BandNameString(srcRaster, prjSettings.OutBandNos) }; } Size outSize = prjSettings.OutEnvelope.GetSize(resolutionX, resolutionY); int bandCount = prjSettings.OutBandNos.Length; string filename = prjSettings.OutPathAndFileName; return(CreateOutFile(driver, filename, bandCount, outSize, dataType, options)); }
public PersistObject ToPersistObject() { PersistObject obj = new PersistObject("MapArguments"); if (_fullExtent != null) { obj.AddSubNode(EnvelopeToPersisitObject(_fullExtent, "FullExtent")); } if (_extent != null) { obj.AddSubNode(EnvelopeToPersisitObject(_extent, "Extent")); } obj.AddAttribute("backcolor", ColorHelper.ColorToString(_backColor)); obj.AddAttribute("smoothingmode", _smoothingMode.ToString()); obj.AddAttribute("spatialreference", _targetSpatialReference != null ? _targetSpatialReference.ToWKTString() : string.Empty); return(obj); }
public void ParseProj4() { string proj4 = "+proj=merc +lon_0=0 +k0=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137"; Console.WriteLine("INPUT:"); Console.WriteLine(proj4); ISpatialReference spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(proj4); Console.WriteLine("ESRI WKT:"); Console.WriteLine(spatialRef.ToString()); Console.WriteLine("PROJ.4:"); Console.WriteLine(spatialRef.ToProj4String()); Console.WriteLine("OGC WKT:"); Console.WriteLine(spatialRef.ToWKTString()); Console.WriteLine("ENVI Projection Info:"); Console.WriteLine(spatialRef.ToEnviProjectionInfoString()); }