[Proj] Problems Migrating to .net 2.0

Eric Miller EMiller at dfg.ca.gov
Tue Feb 21 10:35:29 PST 2006


Okay,

Well, it wasn't clear to me since the namespace was altered from "ProjApi" to "proj_api".  That leads me to believe other things may have been altered...

Anyway, I haven't done any research on .NET 2.0, so can't be much help.  My only guess besides the invalid projection definitions is that the memory for the data arrays is being garbage collected despite the [InAttribute, OutAttribute] attributes on the import definition.  I've since learned, it'd be easier to just write "ref double[] foo" but I'm not sure that'd matter.

I'd say, fix the projection init statements and check for IntPtr.Zero after pj_init_plus() before doing anything else.  Even though the error isn't a Null Pointer exception, it still can't hurt to check.

BTW, on a worldwide scale, your UTM zone number calc will be wrong in some areas due to the exceptions around Norway and such.

>>> ed at topozone.com 2/21/2006 9:57:25 AM >>>
Eric -

No, proj doesn't come with C# wrappers - but you wrote one!  That's the
wrapper Scott is using; see
http://lists.maptools.org/pipermail/proj/2004-September/001338.html for
the source.

	- Ed 

-----Original Message-----
From: proj-bounces at lists.maptools.org 
[mailto:proj-bounces at lists.maptools.org] On Behalf Of Eric Miller
Sent: Tuesday, February 21, 2006 12:23 PM
To: proj at lists.maptools.org 
Subject: Re: [Proj] Problems Migrating to .net 2.0

Since proj doesn't come with C# wrappers, we can't guess how the C#
function call imports are defined.

Nevertheless, you don't do any error checking.  Are you sure your
pj_init_plus calls are succeeding?  Their definitions look suspect to
me...

"""
IntPtr src0 = proj_api.Proj.pj_init_plus("+proj_api.Proj=latlong
+datum=NAD27"); """

>>> scott at topozone.com 2/21/2006 7:51:29 AM >>>
Hello,

 

I've recently moved my project from .net 1.1 to .net 2.0

 

I've tested this code on 1.1, but there are some added restrictions and
stuff that just won't compile in 2.0.  

 

This is the C# wrapper that I'm using

 


"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."


 

 

            public static int LLtoUTM(int datumIn, int datumOut, double
p_lat, double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
UTMZone)

            {

                  int errno;

                  //This is the formula for calculating which Zone a
point is in at a particular lat/long

                  int ZoneNumber = Convert.ToInt32((p_lon + 180) / 6) +
1;

                  double[] x = new double[1];

                  double[] y = new double[1];

                  double[] z = new double[1];

                  y[0] = p_lat*proj_api.Proj.DEG_TO_RAD;

                  x[0] = p_lon*proj_api.Proj.DEG_TO_RAD;

                  z[0] = 0.0;

                  IntPtr src0=
proj_api.Proj.pj_init_plus("+proj_api.Proj=latlong +datum=NAD27");

                  IntPtr src1 =
proj_api.Proj.pj_init_plus("+proj_api.Proj=latlong +datum=NAD83");

                  IntPtr dst0 =
proj_api.Proj.pj_init_plus("+proj_api.Proj=utm +zone=" + ZoneNumber + "
+datum=NAD27");

                  IntPtr dst1 =
proj_api.Proj.pj_init_plus("+proj_api.Proj=utm +zone=" + ZoneNumber + "
+datum=NAD83");

                  //This nice little bit of code below is designed to
execute pj_transfrom (the proj_api.Proj lib all around function)

                  //with the correct parameters so that a datumshift to
the correct datum is included.

                  if(datumIn==0)

                  {

                        if(datumOut==0)

                        {

                              errno = proj_api.Proj.pj_transform(src0,
dst0, 1, 1, x, y, z);//NAD27-NAD83

                        }

                        else

                        {

                              errno = proj_api.Proj.pj_transform(src0,
dst1, 1, 1, x, y, z);//NAD27-NAD27

                        }

                  }

                  else

                  {

                        if(datumOut==0)

                        {

                              errno = proj_api.Proj.pj_transform(src1,
dst0, 1, 1, x, y, z);//NAD83-NAD27

                        }

                        else

                        {

ERROR THROWN HERE    -> errno = proj_api.Proj.pj_transform(src1, dst1,
1, 1, x, y, z); //NAD83-NAD83

                        }

                  }

                  

                  proj_api.Proj.pj_free(dst1);

                  proj_api.Proj.pj_free(src1);

                  proj_api.Proj.pj_free(dst0);

                  proj_api.Proj.pj_free(src0);

                  UTMNorthing = y[0];

                  UTMEasting = x[0];

                  UTMZone = ZoneNumber;

                  return errno; 

            }

 

 


"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."


 

Any help would be appretiated.


Thanks!

 

-Scott

 

 

 



_______________________________________________
Proj mailing list
Proj at lists.maptools.org 
http://lists.maptools.org/mailman/listinfo/proj 

_______________________________________________
Proj mailing list
Proj at lists.maptools.org 
http://lists.maptools.org/mailman/listinfo/proj




More information about the Proj mailing list