GM_FindNearestFeatures Speed

dcoggindcoggin Global Mapper UserPosts: 259Trusted User
edited February 2010 in SDK
Mike,

When comparing my feature selection method on my custom application to Global Mapper, my feature selection is significantly slower. With a test shapefile with approx. 117,000 polylines, Global Mapper takes approx. 1/2 sec to select and redraw all the features with a drag rectangle. With my application, Intel's VTune analyzer says the single call to GM_FindNearestFeatures is taking just under 15 sec for the same drag rectangle selection. I am using VS2008 and am testing a release version of my application built with optimization. Am I going about this the wrong way or is there an expected difference of that magnitude between GlobalMapper selection and the FindNearestFeatures call? Thanks for your help.

David

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2010
    David,

    I would not expect a significant difference between the two assuming the same input. Can you show me how you are calling the GM_FindNearestFeatures function?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dcoggindcoggin Global Mapper User Posts: 259Trusted User
    edited February 2010
    Mike,

    Here's the call from my code. This call is just used for rectangle selection.

    GM_FindNearestFeatures
    (
    &gmPoint, m_pDoc->m_arrSelectableLayers,
    m_pDoc->m_uNumSelectableLayers,
    GM_FindFlags_GetAllFeatures | GM_FindFlags_FindAll,
    &theGroundSearchRect,
    &thePixelSearchRect,
    m_pFoundFeatures,
    m_uMaxDragFoundFeatures,
    &uNumFound,
    0
    );

    gmPoint is the last corner of the rectangle, but I believe it does not matter.

    m_pDoc->m_arrSelectableLayers is just a one element array with the shapefile layer handle

    m_pDoc->m_uNumSelectableLayers is 1

    theGroundSearchRect was checked and seems to have correct values that exceed the bounds of the shapefile

    thePixelSearchRect is the drag rectangle coordinates

    m_pFoundFeatures is a pointer to the FoundFeatures array with 1,000,000 elements

    m_uMaxDragFoundFeatures = 1,000,000

    I checked it again just timing in debug mode for the call and it also gave me 15 seconds. This shapefile is the only data loaded and I'm selecting all of the features. The call does correctly return all of the features. Thanks for looking at this.

    David
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2010
    David,

    I took a look at the GM_FindNearestFeatures code and I think I've found the culprit for the slow fetch. I have placed a new build of the SDK at http://www.globalmapper.com/GlobalMapperSDK_v133_beta.zip for you to try that will hopefully speed it up drastically.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dcoggindcoggin Global Mapper User Posts: 259Trusted User
    edited February 2010
    Mike,

    That did it. It's very fast now!

    I have a related question. I have implemented my selected features by deleting the original feature and adding a selected feature to a selected feature layer. I did this as an alternative to recording the original feature class and style for the original feature and then changing the feature class of the selected feature to a selected feature class. However, when adding the newly created selected features to a selected features layer, it's taking a long time. It's taking almost 10 seconds for just the calls to GM_AddLineToVectorLayer for the 117,000 line features. I've already rewritten the code to track the number of layer features myself outside of the SDK because calls to GM_GetLayerInfo were taking a very long time (with only one layer loaded).

    Thanks for your help.

    David
    David
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2010
    David,

    How often are you calling the GM_GetLayerInfo function? If you have added new features between calls to that the layer information is regenerated, which in some cases can take some time. I would make sure that you minimize your calls to GM_GetLayerInfo while adding the 117,000 new features and just call it when you are done with adding all of the features.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • dcoggindcoggin Global Mapper User Posts: 259Trusted User
    edited February 2010
    Mike,

    I am no longer calling the GetLayerInfo when adding a lot of features, but it still seems like the GM_AddLineToVectorLayer is taking a long time. I wouldn't think it should require 10 seconds for adding 117,000 features. It reads that many from disk a good bit faster than that. That 10 seconds was measured as just the time for the calls to the function using Intel's VTune.

    David
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2010
    David,

    I think what is happening is that the bounding box for the layer is recalculated whenever you add a feature to a layer and that feature isn't completely contained with the bounding box for the layer. So you are potentially getting many thousands of bounding box calculations that wouldn't happen when directly loading a file from disk. I will update the functions to add features to a vector layer to take a flags value rather than a boolean for the last parameter and allow you to pass in a flag to disable updating the bounding box. Then you can just clear that flag for the last feature that you are adding to get it calculated then. I'll point you at a new build when it is ready.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited February 2010
    David,

    I've posted a new SDK build at http://www.globalmapper.com/GlobalMapperSDK_v133_beta.zip for you to try. The last parameter of the GM_AddLineToVectorLayer (and same functions for area and point) has been changed from a boolean to a flag that supports multiple values. If you include the flag GM_AddFeature_MoreAddsToFollow for all but the last add, you should hopefully get much better performance.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
Sign In or Register to comment.