This project is read-only.

ApplyExpressions in 4.9

Feb 9, 2016 at 12:47 PM

We have recently upgraded from 4.8.6 to the latest 4.9 version on the .ocx and one issue we've encountered is that:


seems much slower than it was before - can you think of anything that has changed that could explain this. I haven't measured it exactly but it seems about 10 times slower!

Happy to provide any further information required. We are creating up to 70 categories and applying them to a shapefile to show 16x16 images.


Rob H
Feb 9, 2016 at 1:49 PM
Could you show some code how you are using ApplyExpressions?
We've made a lot of changes between v4.8.6 and v4.9 but I'm not sure what was changed to ApplyExpressions.

Feb 9, 2016 at 4:15 PM
Thanks for the reply Paul.

Here is a simplified version of what we are doing (this is still just as slow). Please note, the bit before the "ApplyExpressions" statement is quick to execute, so that isn't the bottleneck.
                MapWinGIS.ShapefileCategories shpcat = new MapWinGIS.ShapefileCategories();
                var iconPath = Application.StartupPath + @"\MapIcons";
                string[] files = System.IO.Directory.GetFiles(iconPath);

                foreach (string file in files.Distinct())  // there are about 70 of these
                    string name = Path.GetFileNameWithoutExtension(file);
                    if (Path.GetExtension(file).ToLower() == ".png")
                        MapWinGIS.Image img = new MapWinGIS.Image();
                        if (img.Open(file, MapWinGIS.ImageType.USE_FILE_EXTENSION, true, null))
                            img.TransparencyColor = RGBpack.ColorToUInt(System.Drawing.Color.Yellow);
                            img.TransparencyColor2 = RGBpack.ColorToUInt(System.Drawing.Color.Yellow);
                            img.TransparencyPercent = 0.0;
                            img.UseTransparencyColor = true;

                            MapWinGIS.ShapefileCategory ct = sf.Categories.Add(name);

                            ct.Expression = "[Type] = \"" + name + "\"";                            
                            var symbol = CurrentNetwork.GetSymbolTypeFromImageName(name);                           
                            ct.DrawingOptions.AlignPictureByBottom = false;
                            ct.DrawingOptions.PointType = MapWinGIS.tkPointSymbolType.ptSymbolPicture;

                            ct.DrawingOptions.Picture = img;



Rob H
Feb 11, 2016 at 11:13 AM
An update - I seem to have solved my problem.

I changed the code so that rather than call "ApplyExpressions" after I have added all the categories, I call, "sf.Categories.ApplyExpression(sf.Categories.Count -1)" in each iteration of the loop. This is many, many times faster, I didn't really expect it to be though.


Rob H
Marked as answer by pmeems on 2/18/2016 at 8:11 AM
Feb 11, 2016 at 11:21 AM
Thanks Rob,

I see you use more or less the same code as in the example:
So that is not the problem.

I see in the C++ code we've made several changes to the ApplyExpressions() function.
I'll contact Sergei if he has some idea how to optimize this more.

Or are you a C++ developer?


Feb 15, 2016 at 1:18 PM
Hi Paul,

I took over this bit of the code, so I didn't realise it was based on your example.

I am principally a C# developer these days, my C++ skills are limited... I took a look last week at the (C++) code and didn't see anything obvious, but wondered if "ParseNeeded" was possibly being set to true erroneously and causing delays.

Thanks for looking at it.

Feb 18, 2016 at 4:11 PM
Hi Rob,

Thanks for sharing your solution. I reported it as so we don't forget.