Geographic and Projected Transformation

Oct 25, 2010 at 12:56 PM

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

 

Jan 19, 2011 at 12:24 PM

Did you resolve this?

Developer
Jan 19, 2011 at 3:22 PM

I know I get infinite values sometimes if you are out of range.  For instance, if you try to go from WGS84 to UTM10, and are in California, things are fine.  As you wrap further around the globe, however, the distortion increases until at some point it is no longer possible to represent the point on the globe on the cylinder.  As a result, you end up with infinite values.  However, you should never get infinite values when going TO WGS84, or from one geographic projection to another.  This is almost certainly a bug and I will add it to the issues list, rather than a discussion.

Ted

 

Jan 21, 2011 at 6:21 AM
Hi kingboyk.

No I unfortunately didn't have the time to check it out further.
My boss went and bought a third party toolkit from eye4software.

I would have liked to use this project further as I'm already using gmap.net as well.

I saw Shade1974 (Ted) posted that they will move the discussion into the issue list.

Will let you know when I solved it though.

Regards
Linoxxis.

On Wed, Jan 19, 2011 at 3:24 PM, kingboyk <notifications@codeplex.com> wrote:

From: kingboyk

Did you resolve this?

Read the full discussion online.

To add a post to this discussion, reply to this email (DotSpatial@discussions.codeplex.com)

To start a new discussion for this project, email DotSpatial@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Jan 21, 2011 at 8:51 AM

Thanks for the reply Linoxxis, and also for the name of the software you are using!

Steve