Possible optimization

Sep 14, 2007 at 11:42 PM
Hi, trying the library for the .NET Compact Framework i've found it's somehow slow rendering maps. Well, the method WorldtoMap(Point p, Map map) (SharpMap.Utilities.WorldtoMap.cs) is called once for each point in each geometry in each layer of the map.

The first lines:

double Height = (map.Zoom * map.Size.Height) / map.Size.Width;
double left = map.Center.X - map.Zoom / 2;
double top = map.Center.Y + Height / 2;
double pxSize = map.Zoom / map.Size.Width;

are therefore called in each invocation. But they will produce always the same result as far as the map doesn't change. Maybe i'm missing something, but moving those values to the Map class as instances that change whenever Zoom, Center change, would make a saving of 5 complex operations each time.

On the example from SharpMap20alphasrc\UnitTests\Providers\TestData\mexico\states.shp (just 50KB) that's 3124 calls to the method and 21868 operations. It's not noticeable in my 2GHz laptop, but the iPaq is another story.

Best regards
javier tellez
Coordinator
Sep 15, 2007 at 12:37 AM
Hi Javier -

Thanks for the careful examination of this. I'm glad other eyes are looking at the code.

SharpMap rendering and presentation has been completely redone in v2.0 Beta 1, which is likely going to be posted as a release on 9/17. View-to-world transformations are now done using a series of concatenated matrix transforms which only change when the view metrics change, as you describe.

Currently, there is building interest for a CF version of SharpMap. I could provide assistance with navagating and converting the v2.0 code if the initiative gets off the ground.