This project is read-only.

Export SHP file to WMF/EMF

Feb 14, 2011 at 3:00 PM

Hi

I am trying to build a small utility to read SHP files and export it to WMF/EMF which I can import into Excel/Powerpoint.

Is there an easy way to do this? I am guessing I should be able to override the export function?  Or maybe the draw commands to the map window?

Any help/guidance is appreciated.  I have not been able to find an (easy) answer in the available documentation.

regards

Malan

Feb 16, 2011 at 3:39 AM

Hi Malan,

I also need to be able to save my map as WMF file. Please let me know if you find any information on this topic.

Regards,

Bruno

Feb 16, 2011 at 4:02 AM

Malan,

I am doing the following :

Bitmap MyBitmap = new Bitmap(map1.MapFrame.ImageRectangle.Width, map1.MapFrame.ImageRectangle.Height);
map1.DrawToBitmap(MyBitmap, map1.ClientRectangle);
Image MyImage = MyBitmap;
MyImage.Save("Path", System.Drawing.Imaging.ImageFormat.Wmf);

Feb 21, 2011 at 5:26 PM

hi Bruno

Thanks for the help - the code does work.  This saves it in the right format, but it is still a bitmap.  I am trying to get to the vector data, i.e. I was hoping to capture the actual WMF commands when the window redraws.  I will do some research when I get a chance again.

regards

Malan

Mar 4, 2011 at 12:23 PM
Goose997 wrote:

hi Bruno

Thanks for the help - the code does work.  This saves it in the right format, but it is still a bitmap.  I am trying to get to the vector data, i.e. I was hoping to capture the actual WMF commands when the window redraws.  I will do some research when I get a chance again.

regards

Malan

I did a workaround in the end.  The OpenJUMP package can write SVG files, and then Inkscape can save SVG to EMF.

Mar 4, 2011 at 8:39 PM

Hi Goose997,

If you're still looking for a way to export directly to a WMF/EMF here is how in pure .NET

Graphics gr;
gr = Graphics.FromImage(new Bitmap(100,100));
IntPtr hdc = gr.GetHdc;
Metafile mf = New Metafile("Path", hdc, MetafileFrameUnit.Pixel);
gr.ReleaseHdc(hdc)
map1.DrawToBitmap(Metafile, map1.ClientRectangle);  //Technically its not drawing to a bitmap, its drawing to a GDI+ image object which are either bitmaps or WMF vector/bitmap hybrids
gr.Dispose();
mf.Dispose();

I haven't tested this code but I use very similar code but I've used very similar code else where.

Brian M.