Hi
I need to display the raster map, before this i don’t have any issue to rendered the map. Unfortunately, this error occurs when i try to click on map many times it will throws this error:
Exception Unhandled
with message
System.ArgumentOutOfRangeException: ‘The input double value is out of range.’
What the issues of this? I thought it because of my Gdal code that i use to display elevation data, but after i try without the Gdal code it throws the same error.
CODE
namespace RasterMapViewer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{ Proj4Projection proj4Projection;
GeoTiffRasterLayer tiffLayer;
public MainWindow()
{
InitializeComponent();
}
private void Map_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.Meter;
LayerOverlay myOverlay = new LayerOverlay();
Map1.Overlays.Add(myOverlay);
myOverlay.Open();
myOverlay.TileCache = new FileBitmapTileCache(@"C:\Users\User\Documents\Visual Studio 2012\Projects\RasterMapViewer\RasterMapViewer\Cache\");
string[] files = System.IO.Directory.GetFiles(@"C:\Users\User\Desktop\DSI REFERENCE\Map Data\Raster");
foreach (string file in files)
{
GeoTiffRasterLayer tiffLayer = new GeoTiffRasterLayer(file);
myOverlay.Layers.Add(tiffLayer);
}
//Apply the projection
proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString = "+proj=omerc +lat_0=4 +lonc=102.25 +alpha=323.0257905 +k=0.99984 +x_0=804670.24 +y_0=0 +no_uoff +gamma=323.1301023611111 +a=6377295.664 +b=6356094.667915204 +units=m +no_defs"; //Current Proj in meter
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); //Change to the proj with decimal degree
proj4Projection.Open();
PopupOverlay popupOverlay = new PopupOverlay();
Map1.CurrentExtent = myOverlay.GetBoundingBox();
Map1.TrackOverlay.TrackMode = TrackMode.Line;
Map1.Refresh();
}
private void Map1_MouseMove(object sender, MouseEventArgs e)
{
Point point = e.MouseDevice.GetPosition(Map1);
ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y);
PointShape pointShape = ExtentHelper.ToWorldCoordinate(Map1.CurrentExtent, screenPointF, (float)Map1.ActualWidth, (float)Map1.ActualHeight);
string x = pointShape.X.ToString("f6", CultureInfo.InvariantCulture);
string y = pointShape.Y.ToString("f6", CultureInfo.InvariantCulture);
if (proj4Projection != null)
{
//PointShape p = new PointShape(605770.08015, 388756.038425);
PointShape p2 = proj4Projection.ConvertToExternalProjection(pointShape) as PointShape;
//Gdal.AllRegister(); //Register driver(s).
////string Dted = @"C:\N03.dt2";
//double[] gGeoTrans = new double[6];
//Dataset ds = Gdal.Open(@"C:\N03.dt2", Access.GA_ReadOnly); //Open Dataset
//ds.GetGeoTransform(gGeoTrans);
//OSGeo.GDAL.Band gThisBand = ds.GetRasterBand(1);
//double X = Convert.ToDouble(p2.X);
//double Y = Convert.ToDouble(p2.Y);
//// Your query location is X, Y (both doubles), convert your location into
//// local row, col addressing to specify which cell to read
//int row = (int)((gGeoTrans[3] - Y) / -gGeoTrans[5]);// ULY - xcoord / -N-S CellSize;
//int col = (int)((X - gGeoTrans[0]) / gGeoTrans[1]); // xcoord - ULX / E-W CellSize
//// check here that the row and col are >= 0 and < gDataset.RasterXSize and
//// gDataset.RasterYSize or you will get a read error.
//// read the value.. reading is done to an array but as we want only one cell
//// it needs to be an array of 1 float.
//float[] buff = new float[1];
//if ((col <= ds.RasterXSize) && col >= 0)
//{
// if ((row <= ds.RasterYSize) && row >= 0)
// {
// gThisBand.ReadRaster(col, row, 1, 1, buff, 1, 1, 0, 0); // read the cell value
// }
//}
//else
//{
// return;
//}
//float ThisCellValue = buff[0];
TextBoxSatu.Text = "RSO_WEST(KERTAU)" + "(" + (y) + "," + " " + (x) + ")" + " " + " Lat: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.Y) + "Long: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.X) + " " + "Height :" + "m";
//}
//catch (Exception)
//{
// return;
//}
}
}
private void button_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
if (button != null)
{
switch (button.Name)
{
case "TrackPolygon":
Map1.TrackOverlay.TrackMode = TrackMode.Line;
break;
case "TrackNormal":
default:
Map1.TrackOverlay.TrackMode = TrackMode.None;
break;
case "TrackDelete":
Map1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
tiffLayer = null;
Map1.Refresh();
break;
}
}
}
}
}