1

Closed

Projection Issue needs testing

description

Here is a transcription from a discussion topic from October. I don't know if we ever addressed this or what. I am putting it in as an issue so that we can test it when we get time. If we have a unit test for this one and it works, then we can close this I think.

Ted


Hi guys.

I'm having problems transforming my Projection (Hartebeesthoek 1994) to WGS 1984.

I wrote a calculator that lets you set the source and destination Coordinate system. It also allows you to choose geographic or projection transformation.

My problem is that my coordinate system returns infinite values for WGS84.

My Coordinates :

Hartebeesthoek 1994 --> Northing: -3727963 , Easting: -52720
WGS 1984 --> Lat -33.6767, Lng: 18.4312

My Code:

private void fillDatums(bool projected)
    {
        cmbFromDatumn.Items.Clear();
        cmbToDatumn.Items.Clear();

        if (projected)
        {
            foreach (string _name in KnownCoordinateSystems.Projected.Names)
            {
                cmbFromDatumn.Items.Add(_name);
                cmbToDatumn.Items.Add(_name);
            }
        }
        else
        {
            foreach (string _name in KnownCoordinateSystems.Geographic.Names)
            {
                cmbFromDatumn.Items.Add(_name);
                cmbToDatumn.Items.Add(_name);
            }
        }
    }

    private void cmbFromDatumn_SelectedIndexChanged(object sender, EventArgs e)
    {
        //GeographicInfo g = new GeographicInfo();

        try
        {
            //g.Name = cmbFromDatumn.Text;
            CoordinateSystemCategory csg = KnownCoordinateSystems.Geographic.GetCategory(cmbFromDatumn.Text);

            cmbFromGrid.Items.Clear();

            foreach (string item in csg.Names)
            {
                cmbFromGrid.Items.Add(item);
            }

            cmbFromGrid.Enabled = true;
            cmbFromGrid.SelectedIndex = 0;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

    private void cmbToDatumn_SelectedIndexChanged(object sender, EventArgs e)
    {
        //GeographicInfo g = new GeographicInfo();

        try
        {
            //g.Name = cmbToDatumn.Text;
            CoordinateSystemCategory csg = KnownCoordinateSystems.Geographic.GetCategory(cmbToDatumn.Text);

            cmbToGrid.Items.Clear();

            foreach (string item in csg.Names)
            {
                cmbToGrid.Items.Add(item);
            }

            cmbToGrid.Enabled = true;
            cmbToGrid.SelectedIndex = 0;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    private void btnConvert_Click(object sender, EventArgs e)
    {
        saveSelectedDatums();
        double[] xy = new double[1];
        GeographicSystems gs = new GeographicSystems();
        pFrom = new ProjectionInfo();
        pTo = new ProjectionInfo();

        pFrom = gs.GetCategory(cmbFromDatumn.Text).GetProjection(cmbFromGrid.Text);
        pTo = gs.GetCategory(cmbToDatumn.Text).GetProjection(cmbToGrid.Text);

        lblConvertion.Text = "Transforming form " + pFrom.GeographicInfo.Name + " to " + pTo.GeographicInfo.Name;
        xy = transformDatum(pFrom,pTo);

        txtToLat.Text = xy[0].ToString();
        txtToLng.Text = xy[1].ToString();
    }

    private double[] transformDatum(ProjectionInfo _from,ProjectionInfo _to)
    {
        double[] xy = new double[] {Convert.ToDouble(txtFromLat.Text),Convert.ToDouble(txtFromLng.Text)};
        double[] z = new double[] {1};

        Reproject.ReprojectPoints(xy, z, _from, _to, 0, 1);
        return xy;
    }
Closed Feb 28 at 8:04 AM by jany_
This issue list is no longer active. This issue has been copied to our issue list on github (https://github.com/DotSpatial/DotSpatial/issues)

Please check there to find out whether this issue was fixed.

comments