/// <summary> /// 获取坐标系详细参数信息 /// </summary> /// <param name="spatialRef"></param> /// <returns></returns> public static string GetSpatialRefDetail(this ISpatialReference spatialRef) { if (spatialRef == null) { throw new Exception("坐标系(ISpatialReference)对象为Null,无法获取坐标系信息!"); } string str = string.Empty; try { if (spatialRef is IPRJSpatialReferenceGEN gen1) { gen1.ExportSpatialReferenceToPRJ(out str, out _); } else { IESRISpatialReferenceGEN gen2 = spatialRef as IESRISpatialReferenceGEN; gen2.ExportToESRISpatialReference(out str, out _); } str = Environment.NewLine + str; } catch { }//在部分环境中无法将ISpatialReference转成IPRJSpatialReferenceGEN接口 return(spatialRef.Name + str); }
public string ExportToESRISpatialReference(ISpatialReference spatialReference) { int bytes = 0; string buffer = null; ISpatialReference projectedCoordinateSystem = spatialReference; IESRISpatialReferenceGEN parameterExport = projectedCoordinateSystem as IESRISpatialReferenceGEN; parameterExport.ExportToESRISpatialReference(out buffer, out bytes); return(buffer); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // if (context == null) { return(null); } if (context.Instance == null) { return(null); } if (provider == null) { return(null); } // Cannot handle multiple objects if (context.Instance is object[]) { return(null); } // string wkt = null; if (value != null) { wkt = value.ToString(); } // Do ArcGIS Desktop Test object dialog = null; try { dialog = new SpatialReferenceDialogClass(); } catch { } if (dialog == null) { MessageBox.Show( "You do not have ArcGIS Desktop Installed", Resources.TEXT_APPLICATION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return(null); } // Variable to hold edited or created spatial reference ISpatialReference spatialReferenceOut = null; // Use DoModelCreate (if NULL) or DoModelEdit (if not NULL) if (string.IsNullOrEmpty(wkt)) { ISpatialReferenceDialog2 spatialReferenceDialog = (ISpatialReferenceDialog2)dialog; spatialReferenceOut = spatialReferenceDialog.DoModalCreate(false, false, false, 0); } else { // Recreate ESRI Spatial Reference from String ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReferenceInfo spatialReferenceInfo = null; int size; spatialReferenceFactory.CreateESRISpatialReferenceInfo(wkt, out spatialReferenceInfo, out size); ISpatialReference spatialReference = (ISpatialReference)spatialReferenceInfo; // Display Spatial Reference Dialog ISpatialReferenceDialog3 spatialReferenceDialog = (ISpatialReferenceDialog3)dialog; spatialReferenceOut = spatialReferenceDialog.DoModalEdit3(spatialReference, true, 0); } // Exit if Output SpatialReference is NULL if (spatialReferenceOut == null) { return(wkt); } // Convert ESRI Spatial Reference to a String IESRISpatialReferenceGEN spatialReferenceGEN = (IESRISpatialReferenceGEN)spatialReferenceOut; string projection; int size2; spatialReferenceGEN.ExportToESRISpatialReference(out projection, out size2); if (string.IsNullOrEmpty(projection)) { return(wkt); } // Return Result return(projection); }