I need to build a tool where the user selects a coordinate system for a given CAD file. What is the easiest way to do this with ArcObjects?
Obviously, I could populate a list with the hundreds of projection constants (i.e. esrSRProjCSType
), but what user is going to want to scroll through such a huge list? Must be a better way… any tips?
Update:
Thanks everybody. I went with the SpatialReferenceDialog approach below. Now, anybody know how to use NewGeoTransformationDialog to apply datum trans?
private void btn_getCs_Click(object sender, EventArgs e)
{
string StatusMsg = "";
bool Status = true;
SpatialReferenceDialog oSpatialReferenceDialog = null;
ISpatialReference oSpatialReference = null;
ISpatialReferenceFactory2 oSpatialReferenceFactory2 = null;
IGeographicCoordinateSystem oGCS = null;
try
{
oSpatialReferenceFactory2 = (SpatialReferenceEnvironmentClass)new SpatialReferenceEnvironmentClass();
oGCS = oSpatialReferenceFactory2.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984.GetHashCode());
oSpatialReferenceDialog = new SpatialReferenceDialogClass();
oSpatialReference = oSpatialReferenceDialog.DoModalEdit(oGCS, false, false, false, false, true, this.Handle.ToInt32());
txtBx_srDwg.Text = oSpatialReference.Name;
}
catch (System.Runtime.InteropServices.COMException CE)
{
StatusMsg = CE.ErrorCode.ToString() + ": " + CE.Message;
Status = false;
}
catch (Exception E)
{
StatusMsg = E.ToString();
Status = false;
}
finally
{
}
}
Best Answer
You can use the built in SpatialReferenceDialog that allows the user to select the spatial reference. Here's an example built in VB.NET that I use in one of my applications. pSR is set as ESRI.ArcGIS.Geometry.ISpatialReference and SelectSR is a Boolean that I use to check whether the user selected a valid spatial reference. Check for the latest version of each of the interfaces.