[Gdal-dev] Re: Problem using EPSG in C#

Tomas R monshi at home.se
Sat May 12 15:17:09 EDT 2007


Ahh, it works!
Can it be as simple fact as that the proj.dll in FWTools is named 
proj_fw.dll and the binding in the gdal dll is towards proj.dll. I've 
read about that problem in other posts...

Yes, I guess it is so...

And yes - to the other branch of this thread - only viable solution in 
distribution of my application is to supply the necessary dlls together 
with the application.

Perhaps a small guideline in the wiki about the dlls required is in 
place? And links to where to find them, or compile them?

Thank you big time!
If you are into tracking your running or biking exercises with a GPS 
take a look at SportTracks. In a short time v 2.0 will be released, I 
hope, and soon thereafter my plugin will be released, I also hope.

/Tomas

Tamas Szekeres skrev:
> Tomas,
>
> I've eventually created a sample Windows application which executes
> the expected code when the button is clicked and the results are
> written into a textbox. I've attached the Visual Studio 2005 project
> to this mail including the necessary dll-s. You might alter
> SetConfigOption PushFinderLocation according to the place of your
> FWTools installation.
>
> In my experience when the proj.dll is removed from the application
> directory that memory corruption error may arise in that case when the
> %PATH% environment variable does not contain a proper location for the
> proj.dll in the system.
>
> Best regards,
>
> Tamas
>
>
> 2007/5/12, Tomas R <monshi at home.se>:
>> Oh, did I post that version when I tried to go from WGS84 to WGS84. Have
>> tried it before and then it changed nothing but still a test if the call
>> works.
>>
>> Tried your code and, no.. I have no idea why it won't work. But my guess
>> is something work with compilation of gdal... Perhaps. (some path that
>> perhaps needs to be set before compilation?)
>>
>> Worth mentioning  is perhaps that GDALinfo, the included example, work.
>> The include OSRTransform example give the same error as my own code.
>> Would have been a bit surprised if not.
>>
>> It works to allocate the SpatialReferences and the CoordinateTransform,
>> it is the call to transform the two points that fails.
>>
>> Call stack:
>> >      [External Code]
>> > >
>> >  
>> ogr_csharp.dll!OSGeo.OGR.CoordinateTransformation.TransformPoint(double[] 
>>
>> > argout = {Dimensions:[3]}, double x = 1620000.0, double y = 6597000.0,
>> > double z = 0.0) Line 57 + 0x2c bytes    C#
>> >      GdalTest1.exe!GdalTest.Form1.button5_Click(object sender = {Text
>> > = "button5"}, System.EventArgs e = {X = 54 Y = 11 Button = Left}) Line
>> > 101 + 0x2b bytes    C#
>> >      [External Code]
>> >      GdalTest1.exe!GdalTest.Program.Main() Line 17 + 0x1a bytes    C#
>> >      [External Code]
>> As you can see it is runs from a Window Application but that should not
>> have anything to do with.
>> The whole exception. A short translation of the message is, as previous
>> said, " A try to read to read or write to protected memory. This
>> indicates often that another memory is damaged."
>> > System.AccessViolationException was unhandled
>> >   Message="Det gjordes ett försök att läsa eller skriva till skyddat
>> > minne. Detta indikerar ofta att annat minne är skadat."
>> >   Source="ogr_csharp"
>> >   StackTrace:
>> >        vid
>> > 
>> OSGeo.OGR.OsrPINVOKE.CoordinateTransformation_TransformPoint__SWIG_1(HandleRef 
>>
>> > jarg1, Double[] jarg2, Double jarg3, Double jarg4, Double jarg5)
>> >        vid OSGeo.OGR.CoordinateTransformation.TransformPoint(Double[]
>> > argout, Double x, Double y, Double z) i c:\Documents and
>> > 
>> Settings\Tomas\Skrivbord\GDalDoc\trunk\gdal\swig\csharp\ogr\CoordinateTransformation.cs:rad 
>>
>> > 57
>> >        vid GdalTest.Form1.button5_Click(Object sender, EventArgs e) i
>> > d:\Documents and Settings\Tomas\Mina dokument\Visual Studio
>> > 2005\Projects\GdalTest1\GdalTest1\code\Form1.cs:rad 101
>> >
>>
>> I downloaded the latest trunk and compiled with no error. Set references
>> to the four CSharp-dlls and included gdal14.dll and the wrapper dlls in
>> the project, all files after compilation in same folder. But when I run
>> the code, same error.
>>
>> And as said before: Environment to compile in is Visual Studio Express
>> C++, 2005 environment for developing is Visual Studio Express C# 2005.
>> Nothing strange.. Version 1.4.1 I have managed to compile and run... But
>> of course not EPSG-codes in v 1.4.1
>>
>>
>>
>> Tamas Szekeres skrev:
>> > Tomas,
>> >
>> > I couldn't find out what is the actual value of your WGS variable in
>> > SpatialReference wgs84 = new SpatialReference(WGS);
>> >
>> > In addition CoordinateTransformation(wgs84, wgs84); doesn't seem to do
>> > anything with the coordinate values.
>> > Here is my equivalent code that worked:
>> >
>> > int rtX = 1620000;
>> >                 int rtY = 6597000;
>> >                 Gdal.SetConfigOption("GDAL_DATA",@"C:\Program
>> > Files\FWTools1.3.0\data");
>> >                 Gdal.PushFinderLocation(@"C:\Program
>> > Files\FWTools1.3.0\data");
>> >                 SpatialReference source = new SpatialReference("");
>> >
>> >                 int res = source.ImportFromEPSG(3021);
>> >                 string srcTest, dstTest;
>> >                 source.ExportToWkt(out srcTest);
>> >                 Console.WriteLine(srcTest);
>> >                 SpatialReference wgs84 = new SpatialReference("");
>> >                 wgs84.SetWellKnownGeogCS("WGS84");
>> >                 wgs84.ExportToWkt(out dstTest);
>> >                 Console.WriteLine(dstTest);
>> >
>> >
>> >                 CoordinateTransformation toWGS = new
>> > CoordinateTransformation(source, wgs84);
>> >                 double[] data = new double[3];
>> >                 toWGS.TransformPoint(data, rtX, rtY, 0);
>> >                 Console.WriteLine(data[0].ToString() + " " +
>> > data[1].ToString());
>> >
>> >
>> > However your memory corruption issue is somewhat frustrating, do you
>> > have a call stack for this error?
>> >
>> > Best regards,
>> >
>> > Tamas
>> >
>> >
>> > 2007/5/11, Tomas R <monshi at home.se>:
>> >> I have received two answers in my mailbox but don't see them here. I
>> >> reply to one of them:
>> >> The code I use to produce the error is:
>> >> >                 int rtX = 1620000;
>> >> >                 int rtY = 6597000;
>> >> >                 Gdal.SetConfigOption("GDAL_DATA",
>> >> > @"C:\Program\FWTools1.3.0\data");
>> >> >
>> >> Gdal.PushFinderLocation(@"C:\Program\FWTools1.3.0\data");
>> >> >                 SpatialReference source = new SpatialReference("");
>> >> >
>> >> >                 int res = source.ImportFromEPSG(3021);
>> >> >                 string srcTest, dstTest;
>> >> >                 source.ExportToWkt(out srcTest);
>> >> >                 put(srcTest);
>> >> >                 SpatialReference wgs84 = new SpatialReference(WGS);
>> >> >                 wgs84.ExportToWkt(out dstTest);
>> >> >                 put(dstTest);
>> >> >
>> >> >
>> >> >                 CoordinateTransformation toWGS = new
>> >> > CoordinateTransformation(wgs84, wgs84);
>> >> >                 double[] data = new double[3];
>> >> >                 toWGS.TransformPoint(data, rtX, rtY, 0);
>> >> >                 put(data[0].ToString() + " " + data[1].ToString());
>> >> Where Put is just a call to a routine which displays the text on 
>> screen.
>> >> Without gdal14.dll or all the wrapper dlls included in the project 
>> the
>> >> code halts at first call to Gdal. With the wrappers and the gdal dll
>> >> included in the project the SpatialRefernces are correctly 
>> initialized
>> >> (wgs from a WKT-string, just for testing, source from ESPG  (have 
>> tested
>> >> other than RT90)) but instead it halts at call to TransformPoint.  
>> The
>> >> exceptions InnerException is null, error in OGR/OSR_sharp.dll. I have
>> >> tested with both reference to OGR and OSR.
>> >> I have also tried copying all dlls from FWTool to the project but 
>> with
>> >> no difference.
>> >>
>> >> Thank you for your help! The time you take to clear this up is highly
>> >> appreciated!
>> >> Yours
>> >> Tomas
>> >>
>> >>
>> >> This was in answer to
>> >> > Could you post your example that produces this behaviour? I haven't
>> >> > found this issue when using a similar test you have mentioned.
>> >> >
>> >> > Tamas
>> >>
>> >>
>> >>
>> >> Tomas R skrev:
>> >> > Again I was a bit to quick when reporting success.
>> >> > Yes, now I am able to create a SpatialReference from an EPSG 
>> code and
>> >> > from Proj4 (not tested WKT)
>> >> > And I am able to create a CoordinaTransform object from those
>> >> > spatialreferences.
>> >> > But I'm not able to perform an actual coordinate transformation, an
>> >> > exception is thrown (trying to read or write to  protected (in
>> >> > ogr_sharp.dll).
>> >> >
>> >> > So, again I ask:
>> >> > Have I missed some step or is it still something in GDAL that 
>> doesn't
>> >> > work?
>> >> >
>> >> > /Tomas
>> >> >
>> >> > Tomas R skrev:
>> >> >> Ok Tamas, it kind of works...
>> >> >>
>> >> >> I followed the steps you have described for me and those I 
>> found on
>> >> >> the Wiki:
>> >> >> 1: Downloaded latest trunk
>> >> >> 2: Compiled  GDAL (how many of the steps must I do? All? Or 
>> just the
>> >> >> first, I guess just the first)
>> >> >> 3: Created the C# interface and compiled it.
>> >> >> 4: Copied the resulting *_wrap.dlls to Fwtool1.3.0\bin folder
>> >> >> 5: Added the new CSharp-dlls to my C# project.
>> >> >> 6: Checked that the system path contains FWTools1.3.0\bin folder
>> >> >> If I try running my project after those steps I get an 
>> exception when
>> >> >> trying to call GDAL, whatever *_wrap.dll that is called is not
>> >> >> found/not possible to load.
>> >> >>
>> >> >> When I add the wrap-dlls to the "root" of my C#-project, no 
>> apparent
>> >> >> change.
>> >> >> When I copy the GDAL-dll to my projects root and include it in the
>> >> >> build, together with the wrap-dlls, it works!
>> >> >> But is this how it now is supposed to be? I guess I with this 
>> setup
>> >> >> can use GDALs basic function but all the functions which rely on
>> >> >> other libs (which I have not tested/any knowledge of yet) are not
>> >> >> available? For example reading and writing of GeoTiff images? 
>> (That
>> >> >> is possible via the C#-bindings?)
>> >> >> For now I think I'm content with coordinate translation but I 
>> think I
>> >> >> want to try how efficient GDAL is to use when importing maps of
>> >> >> different formats. It would be nice to be able to rip directly 
>> from
>> >> >> GeoTiff (or RIK) with GDAL.
>> >> >>
>> >> >> Perhaps a bit OT but:
>> >> >> In basic it boils down to that I have now not a clear idea how to
>> >> >> distribute the plugin I am building. Demand that FWTools are
>> >> >> installed or include the nessecary dlls? O well, there is time 
>> left
>> >> >> to think about that.
>> >> >>
>> >> >> /Tomas
>> >> >>
>>
>> _______________________________________________
>> Gdal-dev mailing list
>> Gdal-dev at lists.maptools.org
>> http://lists.maptools.org/mailman/listinfo/gdal-dev
>>




More information about the Gdal-dev mailing list