ArcEngine关于单位转换示例

时间:2023-03-10 06:25:35
ArcEngine关于单位转换示例

示例界面:

ArcEngine关于单位转换示例

转换代码:

     private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
// Get the AreaUnits value string name.
string theSelectionText = ComboBox1.SelectedValue.ToString(); // Get the input Square Meters value.
double theInputValue = System.Convert.ToDouble(TextBox_Input_1.Text); // Create a placeholder output AreaUnits output value from the .ConvertFromSquareMeters Method.
double theOutputValue = ; // For each AreaUnits type perform the .ConvertFromSquareMeters calculation.
if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.Acres.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.Acres.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.Ares.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.Ares.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.Hectares.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.Hectares.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareCentimeters.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareCentimeters.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareDecimeters.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareDecimeters.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareFeet.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareFeet.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareInches.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareInches.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareKilometers.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareKilometers.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMeters.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMeters.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMiles.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMiles.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMillimeters.Name)
{
theOutputValue = Esri.ArcGISRuntime.Geometry.AreaUnits.SquareMillimeters.ConvertFromSquareMeters(theInputValue);
}
else if (theSelectionText == Esri.ArcGISRuntime.Geometry.AreaUnits.SquareYards.Name)
{
// NOTE: Using this long version you can also obtain information on the AreaUnit Class.
Esri.ArcGISRuntime.Geometry.AreaUnit myUnit_SquareYards = (Esri.ArcGISRuntime.Geometry.AreaUnit)Esri.ArcGISRuntime.Geometry.AreaUnit.Create(Esri.ArcGISRuntime.Geometry.AreaUnits.SquareYards.Id);
theOutputValue = myUnit_SquareYards.ConvertFromSquareMeters(theInputValue); // Additional AreaUnit Properties that you could make use of in another application
int myAreaUnit_SquareYards_ID = myUnit_SquareYards.Id;
string myAreaUnit_SquareYards_Name = myUnit_SquareYards.Name;
Esri.ArcGISRuntime.Geometry.UnitType myAreaUnit_SquareYards_UnitType = myUnit_SquareYards.UnitType;
} // Display the other XXXX AreaUnits values.
TextBox_Output_1.Text = theOutputValue.ToString();
}

参考网址:https://developers.arcgis.com/net/desktop/api-reference/