[gdal-dev] GDAL WMS In C#

jwill222 jwill222 at hotmail.com
Fri Feb 14 12:02:42 PST 2014


I'm currently trying to grab a map image from a wms using gdal and save it to
my local machine. The call that I'm trying to replicate inside of my wms xml
file is ->
http://geoint.lmic.state.mn.us/cgi-bin/mncomp?request=GetMap&service=WMS&bbox=-102,30,-85,51&version=1.1.1&layers=mncomp&width=1000&height=1000&SRS=EPSG:4326

Here is what my XML looks like: 
<GDAL_WMS>
  <Service name ="WMS">
    <Version>1.1.1</Version>
    <ServerUrl>geoint.lmic.state.mn.us/cgi-bin/mncomp?</ServerUrl>
    <ImageFormat>image/jpeg</ImageFormat>
    <SRS>EPSG:4326</SRS>
    <Layers>mncomp</Layers>
    <Styles></Styles>
  </Service>
  <DataWindow>
    <Projection>EPSG:4326</Projection>
    <UpperLeftX>-102</UpperLeftX>
    <UpperLeftY>30</UpperLeftY>
    <LowerRightX>-85</LowerRightX>
    <LowerRightY>51</LowerRightY>
    <SizeX>1000</SizeX>
    <SizeY>1000</SizeY>
  </DataWindow>
</GDAL_WMS>


Here is what my code looks like :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OSGeo.GDAL;
using OSGeo.OGR;
using OSGeo.OSR;
using System.IO;
using System.Drawing.Imaging;
using System.Xml;
using GDALRD;

namespace GDAL_TEST_WMS
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Ogr.RegisterAll();
            Gdal.AllRegister();

            XmlDocument doc = new XmlDocument();
            doc.Load(@"./WMS_Description_File.xml");

            Dataset ds = Gdal.Open(doc.InnerXml, Access.GA_ReadOnly);
            string outfile = "./test.jpeg";
            OSGeo.GDAL.Driver drive = Gdal.GetDriverByName("JPEG");
            Dataset dso = drive.CreateCopy(outfile, ds, 0, null, null,
null);
        }
    }
}


However I get this error :

<http://osgeo-org.1560.x6.nabble.com/file/n5103908/Exception.png> 

Any Suggestions. BTW I am really new to GDAL. 




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/GDAL-WMS-In-C-tp5103908.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list