GeoMedia Discussions

Search for an answer, post a question, or answer other users' questions in our GeoMedia support discussions. This discussion board is a great way to collaborate with industry peers around the world. It is intended for discussion and support of the GeoMedia Desktop and Add-on applications.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Contributor
Posts: 80
Registered: ‎05-30-2016
Accepted Solution

How to calculate size in pixels required to display map range at a given scale

[ Edited ]

I have to programmatically calculate the width and height in pixels required to display a map when given a range at a given scale. I'm using a map window to validate my efforts, but ultimately need to know how to do this without a map window.

 

So, for testing I take a range and scale from the mapView, and after performing my scaling and conversion logic expect to have the same width and height in pixels as the map window's map area.

 

I am using the USSampleData with storage type projected for debug purposes. The range is in meters.

 

Here's my approach.

 

  1. Use the MeasurementService object to measure the range width and height distances with the ReferenceSpace set to CSSReferenceSpaceConstants.gmcssGeographic.
  2. Multiply the distances by (storageToProjectionScale/scale).
  3. Use UnitsOfMeasure object to convert distance units from meters to inches.
  4. Compare results with a screen capture of the map view area in Paint application.  

Observations:

 

I've noticed the results differ if I change the monitor's screen resolution. The GeoMedia window remains the same size on screen yet the scale indicated differs. At 1920x1096 my calculations are about 63% of the map view area. At 1280x1024 they are close but not correct.

 

I use a third party sdk to convert from inches to pixels, but the thing is the inches calculated with my approach as outlined are incorrect to begin with.

 

Anyone know the trick to do this correctly?

Highlighted
Technical Evangelist
Posts: 539
Registered: ‎09-11-2015

Re: How to calculate size in pixels required to display map range at a given scale

I suggest you to look at the Windows API function GetDeviceCaps. You should query various capabilities of your display device such as HORZSIZE, HORZRES, VERTSIZE, VERTRES to get the correct ratio for your transformations. And note that the physical dimension of your screen may not be correct, especially if you have an old monitor with improper driver installed, or if you use some virtualization environment. But calculation based on those values should at least give you consistent results when you change the screen resolution.

 

Pavel

Highlighted
Contributor
Posts: 80
Registered: ‎05-30-2016

Re: How to calculate size in pixels required to display map range at a given scale

Thanks for your reply, I'll check that out.

 

In the meantime, can you tell me at least if my approach is correct, steps 1-3.

Highlighted
Contributor
Posts: 80
Registered: ‎05-30-2016

Re: How to calculate size in pixels required to display map range at a given scale

I think I have a solution.

 

First I figure out a width and height adjustment ratio by doing the following:

  1. Get Range of any window.
  2. Get Scale of the same window.
  3. Get pixel size of the same window, just the map area, without bars and borders. I have a win32 api call for that.
  4. Scale the range to pixels as described before.
  5. width ratio is pixel width of window / scaled pixel width, heigh ratio is pixel height of window / scaled pixel height

Then after I have obtained this ratio, I take the end-user provided range and scale and perform the scaling as described previously. Then multiply the results by the width and height adjustment ratios.

 

This way I always get a pixel size that matches GeoMedia. Question is, if I create a mapView with those values will they work together?