Donnerstag, 7. Juli 2016

Map API - MgFeatureReader - improve speed

The developer example for reading features with MgFeatureReader looks like that:

 while (featureReader.ReadNext())  
      propertyCount = featureReader.GetPropertyCount();  
      for (int i = 0; i < propertyCount; i++)  
        propertyName = featureReader.GetPropertyName(i);  
        propertyType = featureReader.GetPropertyType(propertyName);  
        PrintPropertyValueFromReader(featureReader, propertyType, propertyName, ref sb);  

(form MapGuide Api Reference).

At least with Map this will be slow. Performance can be improved significantly if  the GetPropertyName and GetPropertyType calls are removed from within the FOR loop.

Example: a small application in order to displays feature attributes in a DataGrid. 


The sample SDF file contains 110'000 features and has 11 columns (text and numbers).

Using code similar to the one given above it takes 19 sec to populate and display the datagrid.

By removing the two calls the process takes less then 1 second and is even slightly faster then opening  Map's data table (mapdatatable):

 Finished in 0 seconds.

 Finished in 19 seconds.

All it takes is to get property name and property type for each column only once and store this information in an array (colProps) before iterating over the FeatureReader:

  while (featureReader.ReadNext())  
         newRow = dt.NewRow();          
         for (int i = 0; i < colProps.Length; i++)  
           propertyName = colProps[i].PropertyName;  
           propertyType = colProps[i].PropertyType;  

Map 2013, SP2

Keine Kommentare:

Kommentar veröffentlichen