[gdal-dev] How to Use Gdal in Microsoft Visual Studio C++

Gigas002 gigas002 at yandex.ru
Fri Nov 23 08:58:50 PST 2018


Athin wrote
> If possible can you share with some guide how to use the gdal nuget and
> how
> can i view the map on wpf not on console?

Sure. You should right-click on "References" in your open project in VS and
choose "Manage nuget packages". Then search for "GDAL.NET" and install it.
Necessary references and GdalConfigurator class will automatically be added
to your project.

If you don't have internet on your PC to download nuget packages directly
from VS, you can download GDAL.NET package from nuget:
https://www.nuget.org/packages/GDAL.NET/. Then, you should change you nuget
search path, here's good answer on stackoverflow how to do it:
https://stackoverflow.com/questions/10240029/how-do-i-install-a-nuget-package-nupkg-file-locally.

After you build your project once, compiled gdal bindings will be placed in
your dubug/release directory near .exe file. 

Now you should call "GdalConfigurator.ConfigureGdal()" (or ConfigureOgr(),
depends on what you need) method in you program. If it doesn't throw any
exceptions, then gdal is found and all EnvironmentVariables set correctly.
If it throws exceptions, try changing solution platform on x64 and change
the following line in GdalConfiguration class from:

var executingAssemblyFile = new
Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;

to

string executingAssemblyFile = Assembly.GetExecutingAssembly().Location;

The thing is, that original version works bad, if path contains some special
symbols, like "#", etc.

After you made your ConfigureGdal() method work correctly, you should add
"using OSGeo.*" namespaces to your code files, and now you can use all
gdal's c# bindings.

Unfortunately, I can't answer to your second question, I haven't done it
before. If I'll have time, I'll check it out and write you about results.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list