Re[mapguide-users] nderingService and DPI (How to change DPI before rendering)

simon hope simonh at geobiz.co.nz
Thu Jan 3 15:35:08 EST 2008


Luis,

Find attached file which contains my code. 

The methods that may help are:

getImageByMapAgent()
getImageUsingRenderService()

The first method basically constructs a request to the cgi - I was playing
around with dpi and display width and height to get the quality of image i
wanted - I seem to remember 'loosing' data when i tried to produce a large
image (for example I would try to create a large image using parcel boundary
data and aerial photography and the rasters would not appear in the output -
note the GetImageFromURL() method has code included to timeout (when
producing a large image then you may want to comment this out).

In the second method I had to use a round about way to get the extent of the
map, i also tried to preserve selection in the map - if i remember correctly
the RenderMap() method is overloaded and I tried a number of versions but
wasn't quite getting the results i wanted which i why i looked at the direct
route to MapAgent.

Hope this helps

S

http://www.nabble.com/file/p14604759/OutputImage.aspx.cs OutputImage.aspx.cs 




lmbap wrote:
> 
> I'm trying to use your code and the problem with the rendering service is
> that the image is created empty.
> With the size of the map displyed but without any contents inside. 
> Can you, as you said, look again to see what is happening?
> ty
> Luis
> 
> 
> 
> simon hope wrote:
>> 
>> Scott,
>> 
>> I was looking at creating PDF's a couple of months back and I used a
>> couple of methods -  both the rendering service and the direct call to
>> mapagent via http - i ended up using the direct call to mapagent as my
>> preferred method - here is some sample code that i used (c#)
>> 
>> Method 1 - rendering service
>> 
>>         //method for getting extent
>>         int dpi = map.GetDisplayDpi();
>>         double metPerUnit = 100000;
>>         double metPerPxl = 0.0254 / dpi;
>>         double sesMapScale = map.GetViewScale();
>>         int sesScrnW = map.GetDisplayWidth();
>>         int sesScrnH = map.GetDisplayHeight();
>>         double midX = map.GetViewCenter().GetCoordinate().GetX();
>>         double midY = map.GetViewCenter().GetCoordinate().GetY();
>> 
>>         double sesLLX = midX - ((sesMapScale * sesScrnW * metPerPxl) /
>> metPerUnit) / 2;
>>         double sesURX = ((sesMapScale * sesScrnW * metPerPxl) /
>> metPerUnit) / 2 + midX;
>>         double sesLLY = midY - ((sesMapScale * sesScrnH * metPerPxl) /
>> metPerUnit) / 2;
>>         double sesURY = ((sesMapScale * sesScrnH * metPerPxl) /
>> metPerUnit) / 2 + midY;
>> 
>> 
>>         //get the map envelope
>>         MgEnvelope env = new MgEnvelope(sesLLX, sesLLY, sesURX, sesURY);
>> 
>>         //set the selection
>>         MgSelection sel = new MgSelection(map);
>> 
>>         //set the rendering service
>>         MgRenderingService renderingSrvc =
>> siteConnection.CreateService(MgServiceType.RenderingService) as
>> MgRenderingService;
>> 
>>         //set the colour
>>         MgColor bgcolor = new MgColor(0, 0, 0, 0);
>> 
>>         MgByteReader byteReader = renderingSrvc.RenderMap(map, sel, env,
>> sesScrnW, sesScrnH, bgcolor, "png");
>>         MgGeometryFactory gFactory = new MgGeometryFactory();
>>         MgCoordinate coord =
>> gFactory.CreateCoordinateXY(map.GetViewCenter().GetCoordinate().GetX(),
>> map.GetViewCenter().GetCoordinate().GetY());
>> 
>>         long byteReaderSize = byteReader.GetLength();
>>         //Create an MgByteSink and save to the file system
>>         MgByteSink byteSink = new MgByteSink(byteReader);
>>         string fileName = "c:\\temp\\RenderMap.png";
>>         byteSink.ToFile(fileName);
>> 
>> Method 2 - http request
>> 
>> call.....
>> 
>> System.Drawing.Image bmp =
>> GetImageFromURL("http://localhost/mapguide/mapagent/mapagent.fcgi?OPERATION=GETMAPIMAGE&VERSION=1.0.0&SESSION="
>> + tbSessionID.Text + "&MAPNAME=" + tbMapName.Text + "&LOCALE=en&FORMAT="
>> + format + "&SETVIEWCENTERX=" + Convert.ToString(x) + "&SETVIEWCENTERY="
>> + Convert.ToString(y) + "&SETVIEWSCALE=" + Convert.ToString(scale) +
>> "&SETDISPLAYDPI=" + strDpi + "&SETDISPLAYWIDTH=" + dispW +
>> "&SETDISPLAYHEIGHT=" + dispH);
>> 
>> method....
>> 
>>     private System.Drawing.Image GetImageFromURL(string strURL)
>>         {
>> 
>>             System.Drawing.Image retVal = null;
>> 
>>             try
>>             {
>> 
>>                 HttpWebRequest request =
>> (HttpWebRequest)HttpWebRequest.Create(strURL);
>>                 //request.Timeout = 15000; // 5 seconds in milliseconds
>>                 //request.ReadWriteTimeout = 20000; // allow up to 20
>> seconds to elapse
>> 
>>                 // execute the request
>>                 HttpWebResponse response =
>> (HttpWebResponse)request.GetResponse();
>>                 retVal =
>> System.Drawing.Image.FromStream(response.GetResponseStream());
>> 
>>             }
>> 
>>             catch (Exception)
>>             {
>>                 retVal = null;
>>             }
>>             return retVal;
>> 
>>         }
>> 
>> I can't remember quite where i was experiencing problems with the
>> rendering service but could looki again if you need more help
>> 
>> Cheers
>> 
>> Simon
>> 
>> 
>> 
>> Kenneth, GEOGRAF A/S wrote:
>>> 
>>> I see your point.
>>> The runtime map has a DisplayDPI property, but it is readonly.
>>> I also assumed that the API had the same parameters as the actual 
>>> service call, but not in this case.
>>> You can use the "SETDATAEXTENT" call to set the DPI, but it does change 
>>> current DPI.
>>> 
>>> You should be able to save a copy of the runtime map though.
>>> 
>>> Regards, Kenneth, GEOGRAF A/S
>>> 
>>> 
>>> 
>>> Scott Hameister skrev:
>>>>
>>>> That is true...But that is using an FCGI call and not the Rendering 
>>>> Service API...The API has no mention of DPI...I would think the API 
>>>> would have all the same capabilities that an FCGI call has?
>>>>
>>>>  
>>>>
>>>> I started using the FCGI calls...but it became annoying because 
>>>> changing the FCGI DPI...caused the Current maps DPI to change...
>>>>
>>>> If I created a new Session to call the FCGI on, then my selection XML 
>>>> from the original Sessions map didn't work in the New Session, because 
>>>> the Layer ID changed...etc.
>>>>
>>>>  
>>>>
>>>> *From:* mapguide-users-bounces at lists.osgeo.org 
>>>> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of 
>>>> *Kenneth, GEOGRAF A/S
>>>> *Sent:* Monday, November 12, 2007 1:21 PM
>>>> *To:* MapGuide Users Mail List
>>>> *Subject:* Re: [mapguide-users] RenderingService and DPI (How to 
>>>> change DPI before rendering)
>>>>
>>>>  
>>>>
>>>> I have no used the ColdFusion stuff that you are using, but the call 
>>>> to GetMapImage does have a DPI parameter, that you can use.
>>>> I have no trouble getting the images as I want, although the PDF 
>>>> format usually reduces quality a bit.
>>>>
>>>> Try looking at the code in the viewer for "Printable Page", as it 
>>>> shows how to use the calls.
>>>>
>>>>
>>>> Regards, Kenneth, GEOGRAF A/S
>>>>
>>>>
>>>>
>>>> Scott Hameister skrev:
>>>>
>>>> I can send anyone interested sample PDFs of the same map stream at 
>>>> different screen resolutions
>>>>
>>>>  
>>>>
>>>> *From:* mapguide-users-bounces at lists.osgeo.org 
>>>> <mailto:mapguide-users-bounces at lists.osgeo.org> 
>>>> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Scott 
>>>> Hameister
>>>> *Sent:* Monday, November 12, 2007 12:00 PM
>>>> *To:* 'MapGuide Users Mail List'
>>>> *Subject:* [mapguide-users] RenderingService and DPI (How to change 
>>>> DPI before rendering)
>>>>
>>>>  
>>>>
>>>> How do I change the DPI that The  Rendering Service Uses when Creating 
>>>> a map...
>>>>
>>>> The Streamed Image from the rendering service is being poured into a 
>>>> PDF file...the problem is that the quality of the PDF varies based on 
>>>> the Resolution my Screen is at when I render the Stream, instead of 
>>>> being consistent in the PDF. If I'm at 1024 x 768 the PDF map is 
>>>> grainier than if I'm at 1920x1200 resolution when  I stream the image 
>>>> How can I address this to make the PDF quality the same for all users?
>>>>
>>>>  
>>>>
>>>> <cfset newMap = 
>>>> renderingSrvc.rendermap(map,mgselection,realCenter,Javacast("DOUBLE",SesMapScale),Javacast
>>>>
>>>> ("INT",SesScrnW),Javacast("INT",SesScrnH),mapcolor,"PNG")>
>>>>
>>>>  
>>>>
>>>> Above Is my Coldfusion call...
>>>>
>>>>  
>>>>
>>>>  
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>>   
>>>>  
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>   
>>>> ------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>   
>>> 
>>> _______________________________________________
>>> mapguide-users mailing list
>>> mapguide-users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/RenderingService-and-DPI-%28How-to-change-DPI-before-rendering%29-tp13710681s16610p14604759.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list