Re: [mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-31 Thread frieda
Thank you both. Unfortunately I'm using MapGuide 32 bit. I will look into it.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users

Re: [mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-27 Thread Benoit Begin
I can definitely confirm that rendering large map images via the API is
definitely memory intensive on the Mapguide site. Then when you get the
image out into .NET, you might even go into deeper problems with the way the
Large Object Heap collection works and so on. You can end up with pretty
massive amounts of memory in there if your code is running in a service or
something where memory collection can be more harduous.

You could look into creating smaller tiles and stiching them up for the
resulting image. It might keep memory usage under control. Perhaps limiting
the map images to boxes of 2048x2048 and then tiling them back into a single
image. It does require a bit of math and finagling, but definitely worth the
trouble.

There might also be some issues on depending on what kind of app this code
runs. If it's a web app, if 2-3 users end up asking for the same large image
within a similar timespan, it could get crazy. So that's something that
generating smaller tiles might help out with.

Hope the idea helps out!



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users

Re: [mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-27 Thread Jackie Ng
I can tell you right now, if you're expecting a 80MB png to be rendered, it
will not take 80MB of memory to render said PNG. It takes much much more
memory.

I did a little test just to see how much memory is being used to render the
Sheboygan sample map at full map extents with an image size of 9922 x 14302
pixels.

~610MB memory is allocated to set up the raw image buffer for the AGG
renderer
Another ~670MB memory is allocated to set up the PNG pixel buffer for
converting the AGG renderer result to PNG.
The resulting PNG image is ~33MB

So at least ~1.24GB of memory is used to produce a 9922 x 14302 PNG image
that is 33MB.

This does not include any extra memory allocations from whatever user code
that is calling this RenderMap API.

This is with the Sheboygan map that only has 10 layers.

Take the numbers outlined here and scale appropriately to your particular
map. Not the most scientific method, but at least it will give you a rough
number in terms of memory usage.

Are you on 64-bit MapGuide at least? If so, how much physical RAM does that
machine have? You probably need to throw more RAM at it if you're going to
be plotting images of this size on a regular basis.

If it's 32-bit MapGuide, forget it. Windows only allows a 32-bit process to
address 2GB of memory (ref:
https://stackoverflow.com/questions/639540/how-much-memory-can-a-32-bit-process-access-on-a-64-bit-operating-system)

- Jackie



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users

Re: [mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-26 Thread frieda
It's DIN A2, so I pass 9922 x 14032 pixel to that function. I'm not sure why
that's too much, if I'm not wrong then 9922 x 14032 pixel is something about
80 MB for a PNG.



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users

Re: [mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-26 Thread Jackie Ng
What kind of image sizes are you dealing with here out of curiosity?

- Jackie



--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users

[mapguide-users] RenderMap: MgOutOfMemoryException

2020-08-24 Thread frieda
Hello I'm using MapGuide v.2.5.2.7949 in an ASP.NET Application.

I'm facing an out of memory exception throwed by this function (RenderMap):

http://cmnmaps.ca/mapguide/help/webapi/de/dbd/class_mg_rendering_service_a7767628fe456bfd90e9010a19ed83e04.htm#a7767628fe456bfd90e9010a19ed83e04

In my App I'm trying to print the map to a PNG format and if I set 600 DPI I
get the exception. What's wrong here? If I set lower DPI, like 300 it works
fine.

My Code:

 Public Sub InitializeMapImage(ByRef pr_objMapGuide As
MapGuide, ByVal pv_Plotbox As MgEnvelope,
ByVal pv_dblPageWidth As Double,
ByVal pv_dblPageHeight As Double, Optional ByVal pv_strFormat As String =
"PNG")
Try
Dim Map As MgMap = pr_objMapGuide.Map

Dim selection As New MgSelection()
selection.Save(pr_objMapGuide.ResourceService, Map.Name)
selection.Open(pr_objMapGuide.ResourceService, Map.Name)
Dim SelXML As String = selection.ToXml
Dim white As New MgColor(255, 255, 255)

Dim pxMapWidth As Double = (pv_dblPageWidth / inch) * DPI
Dim pxMapHeight As Double = (pv_dblPageHeight / inch) * DPI

Dim byteReader As MgByteReader =
pr_objMapGuide.RenderingService.RenderMap(Map, selection, pv_Plotbox,
pxMapWidth, pxMapHeight, white, "PNG")
Dim memBuff As New IO.MemoryStream
Dim byteBuffer(1024 ^ 2) As Byte
Dim intBytes As Integer = byteReader.Read(byteBuffer, 1024 ^ 2)
While intBytes > 0
memBuff.Write(byteBuffer, 0, intBytes)
intBytes = byteReader.Read(byteBuffer, 1024 ^ 2)
End While

Dim BitMap As New Drawing.Bitmap(memBuff)
BitMap.SetResolution(Convert.ToSingle(DPI),
Convert.ToSingle(DPI))
Dim imgMap As Image = BitMap

m_Map = imgMap
Catch exRange As MgOutOfRangeException
Throw New Exception("", exRange)
Catch exMemory As MgOutOfMemoryException
Throw New Exception("", exMemory)
Catch ex As Exception
Throw New Exception("", ex)
End Try
End Sub




--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html
___
mapguide-users mailing list
mapguide-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/mapguide-users