MapWinGIS GeoProjection Transform function returning false

Hi everyone,

I’m working on a project that uses MapWinGIS, and I’m trying to transform latitude and longitude into X and Y coordinates using the Transform function, but for some reason it keeps returning false. I am passing double data type arguments to both parameters x and y, just like the documentation requires.
I can’t debug and see why it’s failing so I was wondering if anyone has had this issue before, or could point me in the right direction as to why the method call is returning false.

conv trans

Thank you for your time!

Bernardo

Hello @bbleite

There’s not really enough context here to know. Did you call StartTransform prior to calling Transform?

Can you show the complete function/context?

Thanks.

Regards,
Jerry.

Hi Jerry,

Thanks for such a quick reply. Yes, the function is calling StartTransform prior to calling Transform:

bool tester2 = gpFROM.StartTransform(gpTO);

Here is the complete method being called when the user clicks that Convert button:

private void button5_Click(object sender, EventArgs e)
        {
            double lonX, latY;
            //int tester;
            var gpFROM = new GeoProjection();
            var gpTO = new GeoProjection();
            int code;
            int code2;

            // one of the following methods can be used; see more in GeoProjection class
            // - use projections provided by MapWinGIS enumerations:

            //see what projection is currently selected
            string[] wordsTO;
            wordsTO = comboBoxTo.Text.Split('=');
            code = int.Parse(wordsTO[1]);

            string[] wordsFROM;
            wordsFROM = comboBoxFROM.Text.Split('=');
            code2 = int.Parse(wordsFROM[1]);

            //gp.SetWgs84Projection(code);
            // check to see if left characters are "LL_"
            //If so, it's a coordinate system
            if (wordsTO[0].Substring(0, 3) == "LL_")
            {
                if (code == 4269)
                {
                    //std gpTO.SetWellKnownGeogCS(tkCoordinateSystem.csNAD83);
                    bool tester4 = gpTO.ImportFromEPSG(code);
                }
                else if (code == 4267)
                {
                    //std gpTO.SetWellKnownGeogCS(tkCoordinateSystem.csNAD83);
                    bool tester4 = gpTO.ImportFromEPSG(code);
                }
                else  //default case is WGS84...
                {
                    //gpTO.SetWellKnownGeogCS(tkCoordinateSystem.csWGS_84);
                    bool tester4 = gpTO.ImportFromEPSG(code);
                }
            }
            else
            {
                bool tester4 = gpTO.ImportFromEPSG(code);
            }

            if (wordsFROM[0].Substring(0, 3) == "LL_")
            {
                if (code2 == 4269)
                {
                    //std gpFROM.SetWellKnownGeogCS(tkCoordinateSystem.csNAD83);
                    bool tester3 = gpFROM.ImportFromEPSG(code2);
                }
                else if (code2 == 4267)
                {
                    //std gpFROM.SetWellKnownGeogCS(tkCoordinateSystem.csNAD83);
                    bool tester3 = gpFROM.ImportFromEPSG(code2);
                }
                else  //default case is WGS84...
                {
                    //std gpFROM.SetWellKnownGeogCS(tkCoordinateSystem.csWGS_84);
                    bool tester3 = gpFROM.ImportFromEPSG(code2);
                }
            }
            else
            {
                bool tester3 = gpFROM.ImportFromEPSG(code2);
            }



            //gpFROM.ImportFromEPSG(code);
            // assume this one is LL_
            //gpTO.ImportFromEPSG(code2);
            //gpTO.SetWellKnownGeogCS(code2);
            bool tester2 = gpFROM.StartTransform(gpTO);



            //axMap2.GeoProjection = gpFROM;
            //string testname;
            //testname = gp.Name;



            //DataTable dt = new DataTable();
            //dt = (DataTable)(dataGridView1.DataSource);


            int colX = 0;
            int colY = 1;
            //find these two first...
            string testnameX;
            testnameX = comboBoxFromX.Text.ToString();
            if (testnameX.Length != 0) //The user has selected something, but not sure if it exists
            {
                colX = existsvarname(testnameX);
            }

            string testnameY;
            testnameY = comboBoxFromY.Text.ToString();
            if (testnameY.Length != 0) //The user has selected something, but not sure if it exists
            {
                colY = existsvarname(testnameY);
            }


            string myvalue;
            //double eastX = 0;
            //double northY = 0;
            int newXindex;
            int newYindex;
            int landingcolumnX = -1;
            int landingcolumnY = -1;

            string defaultnameX = "LonDD";
            string defaultnameY = "LatDD";



            testnameX = comboBoxToX.Text.ToString();
            if (testnameX.Length != 0) //The user has selected something, but not sure if it exists
            {
                landingcolumnX = existsvarname(testnameX);
                defaultnameX = testnameX;
            }

            testnameY = comboBoxToY.Text.ToString();
            if (testnameY.Length != 0)
            {
                landingcolumnY = existsvarname(testnameY);
                defaultnameY = testnameY;
            }


            if (landingcolumnX != -1 | landingcolumnY != -1)  //The X or Y columns don't exist
            {
                newXindex = landingcolumnX;
                newYindex = landingcolumnY;
            }
            else
            {
                dt.Columns.Add(defaultnameX, typeof(double));
                dt.Columns.Add(defaultnameY, typeof(double));
                newXindex = dt.Columns.IndexOf(defaultnameX);
                newYindex = dt.Columns.IndexOf(defaultnameY);
            }

            if (colX > -1 & colY > -1)
            {
                for (int i = 0; i < (dataGridView1.RowCount - 1); i++)
                {
                    myvalue = dt.Rows[i][colX].ToString();
                    lonX = double.Parse(myvalue);
                    myvalue = dt.Rows[i][colY].ToString();
                    latY = double.Parse(myvalue);


                    if (gpFROM.Transform(ref lonX, ref latY))
                    {
                        //conversion was successful...
                        //tester = 1;

                        dt.Rows[i][newXindex] = lonX.ToString("F9");
                        dt.Rows[i][newYindex] = latY.ToString("F9");

                    }
                }
            }
            dataGridView1.EndEdit();
            dataGridView1.Refresh();
            gpFROM.StopTransform();
            updateboxes();
        }

Basically what’s happening is the user is loading a csv file without X and Y columns so they need to convert latitude and longitude into X and Y coordinates.

To be more accurate, we use MapWinGIS to convert from Lat-Lon to UTM Northing and Easting, or (2) to convert from UTM Northing and Easting into Lat-Lon.

What is weird is that this same code works correctly on the development environment of the previous developer that worked on this project. He suggested me to check if I have a registered version of MapWinGIS on my pc. He said it was quite the process to get installed properly and I for sure don’t recall the installation being such a complicated task. I might have done something wrong or not have completed the setup correctly.

How can I check if my version is registered? How do I get a registered version?

Thank you!

Hi Jerry,
I’m still working on this issue, and I have some more findings. As you mentioned and after some more digging, I found out that my issue is really with StartTransform, and not Transform. Here’s my GeoProjection target object after the code calls StartTransform:

The target GeoProjection gets declared, it then calls ImportFromEPSG passing a code, I get true as a response, and then calls StartTransform, which is failing returning false. I’m assuming that’s why the object has IsEmpty as true. I did notice that I got a “1806” for LastErrorCode. Any idea what the code could be?

I also saw that I have the option for inspecting the native object, but Native View is throwing an error. How can I enable native code debugging?

Thanks for the help!

Hello Bernardo.

Looking at the code, 1806 appears to be a generic OGR error. FYI, you can get the error message from the code by calling GdalUtils.ErrorMsg(code).

What EPSG code was being passed into each of your gpFROM and gpTO?

4326 for gpFROM and 32615 for gpTO.

Hi Jerry,

I used GdalUtils.ErrorMsg(code) like you advised, and the only error message I got was this:
OGR: undefined failure”.

Please let me know if you have any thoughts on this. Thanks!