I'm new to GDAL and am currently trying to hit a WMS using gdal. I need a way to save the image to my desktop. I currently have an xml file with the WMS description syntax that gdal wants -> http://www.gdal.org/frmt_wms.html. How would I save the returned image to my desktop? Thanks
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;
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();
Dataset ds_in = Gdal.Open("<GDAL_WMS><Service name=\"WMS\"><Version>1.3.0</Version><Layers></Layers><CRS>CRS:84</CRS><ServerUrl>http://geoint.lmic.state.mn.us/cgi-bin/mncomp?</ServerUrl></Service><Path>./gdalwmscache</Path><DataWindow><Projection>EPSG:4326</Projection><SizeX>600</SizeX><SizeY>600</SizeY></DataWindow></GDAL_WMS>", Access.GA_ReadOnly);
}
}
}
I'm currently using GDAL version 1.10.1. This is all the code that I have. It's currently filling the Dataset variable because I can see the properties when I debug. If there's a better way to do this please feel free to tell me. Like I said before I am REALLY new to gdal, but I really want to get this done. Thanks in advance!
EDIT: Hey I've changed my code a little bit. Now I have my wms request inside of a separate xml file.The request that I'm replicating inside of my 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. I load that xml file and use gdal.open to access the image that should be returned.
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 keep getting this error:
Any suggestions to fix this?