ThinkGeo.com    |     Documentation    |     Premium Support

System.ArgumentOutOfRangeException: 'The input double value is out of range.'

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;
                }
            }
        }
    }
}

Hi Fathin,

Here is a simple version of your code, I remove the GeoTiff part of it.

It looks the sample code run correct, so I think maybe that’s related with the data.

Could you please test it? And if it also works in your side, a simple sample with test data should be helpful to make sure where is the problem. Or you can try to modify the sample to reproduce it and let us know.

Proj4Projection proj4Projection;

    private void map_Loaded(object sender, RoutedEventArgs e)
    {
        map.MapUnit = GeographyUnit.Meter;
        LayerOverlay myOverlay = new LayerOverlay();
        map.Overlays.Add(myOverlay);
        myOverlay.Open();

        InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
        layer.InternalFeatures.Add(new Feature(10000000, 10000000));
        layer.InternalFeatures.Add(new Feature(-10000000, -10000000));

        layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;
        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        myOverlay.Layers.Add(layer);

        //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();

        map.CurrentExtent = myOverlay.GetBoundingBox();
        map.TrackOverlay.TrackMode = TrackMode.Line;
        map.Refresh();
    }

    private void map_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    {
        var point = e.MouseDevice.GetPosition(map);

        ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y);
        PointShape pointShape = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, screenPointF, (float)map.ActualWidth, (float)map.ActualHeight);


        string x = pointShape.X.ToString("f6", CultureInfo.InvariantCulture);
        string y = pointShape.Y.ToString("f6", CultureInfo.InvariantCulture);

        if (proj4Projection != null)
        {
            PointShape p2 = proj4Projection.ConvertToExternalProjection(pointShape) as PointShape;

            string tmpstring = "RSO_WEST(KERTAU)" + "(" + (y) + "," + " " + (x) + ")" + " " + " Lat: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.Y) + "Long: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.X) + " " + "Height :" + "m";
            Debug.WriteLine(tmpstring);
        }
    }

Regards,

Ethan

Hi Ethan,

I get problem when i try to install nuget package for mapsuite for wpf standard. It get this error:

‘MapSuiteDependency-NewtonsoftJson’ already has a dependency defined for ‘Microsoft.CSharp’.

Regards

Fathin

HI Ethan,

I try implement your code , but it still throws same error when i move the mouse cursor randomly. Then why when i add this line of code

InMemoryFeatureLayer layer = new InMemoryFeatureLayer();
layer.InternalFeatures.Add(new Feature(10000000, 10000000));
layer.InternalFeatures.Add(new Feature(-10000000, -10000000));

it will cause my map become so far and small, need to zoom in and the point is outside the map area, how can i make a plotting point on map.
This link is the sample and include data sample for my project : https://drive.google.com/file/d/10ZqVBmdOv-UtGDiePaK1xZXp6t0iWhC4/view?usp=sharing

If you want to try how i get the Gdal value from below, it need to add reference gdal Csharp 2.3 with 64 bit platform.

using System.IO;
using OSGeo.GDAL;
using OSGeo.OSR;

Gdal.AllRegister(); //Register driver(s).

    //string Dted = @"C:\N03.dt2";
    double[] gGeoTrans = new double[6];
    Dataset ds = Gdal.Open(@"C:\Users\User\Desktop\RasterMapViewer\RasterMapViewer\DTED\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];

    string tmpstring = "RSO_WEST(KERTAU)" + "(" + (y) + "," + " " + (x) + ")" + " " + " Lat: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.Y) + "Long: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(p2.X) + " " + "Height :" + ThisCellValue + "m";
  TextBoxSatu.Text = tmpstring;

Regards,

Fathin

Hi Fathin,

Your package is about 1.3 GB, I think that’s because you include all the packages in it. Could you please remove the unnecessary dlls from it so I can download it, because my network is a little bad today.

And I set the two point is just for simulate your scenario, you can just modfiy it to any point you want.

Could you please paste the trace stack of the exception: “System.ArgumentOutOfRangeException: ‘The input double value is out of range.’”? If that’s thrown from our code, the GDAL is not need, our target is create a simplest sample to recreate your issue, it shouldn’t contains any unnecssary code.

You can modify based our sample and upload it here (Remove packages, bin and obj folders).
9409.zip (11.1 KB)

Regards,

Ethan

HI Ethan,

I try rendered the raster map on your sample code. I still throw error when i play around with it. It does not show which line that throw the error, only the error message.


Why it get error when i try to restore nuget package?

Error 1 NuGet Package restore failed for project 9409: ‘MapSuiteDependency-NewtonsoftJson’ already has a dependency defined for ‘Microsoft.CSharp’… 0 0

This the sample that you share that i use : https://drive.google.com/file/d/1njJnHpDZE2JU7aW0ixozNfNTbpQogjMc/view?usp=sharing

Regards,

Fathin

Hi Fathin,

I download your sample, it works without problem.

Then I view the package you mentioned: https://www.nuget.org/packages/MapSuiteDependency-NewtonsoftJson/

From it’s “Dependencies” I think that’s maybe related with your .net framework.

I think you can try to install higher version .net framework to avoid this problem.

My test environment as below:

OS: win7
IDE: VS 2017
.net framework: 4.5

And I think you should want to clear your Nuget Cache then get all packages again, or you can install the other packages listed follow your .net framework version.

Wish that’s helpful.

Regards,

Ethan