Showing posts with label Map API. Show all posts
Showing posts with label Map API. Show all posts

Thursday, 7 July 2016

Map API - MgFeatureReader - improve speed

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


 while (featureReader.ReadNext())  
    {  
      featureCount++;  
      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. 

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):


Befehl: MAPDATATABLE2
 Finished in 0 seconds.
Befehl: MAPDATATABLE3

 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())  
       {  
         counter++;  
         newRow = dt.NewRow();          
         for (int i = 0; i < colProps.Length; i++)  
         {  
           propertyName = colProps[i].PropertyName;  
           propertyType = colProps[i].PropertyType;  
                          ....  


Map 2013, SP2


Thursday, 24 April 2014

Map API - MapButton

I tried to use a MapButton but Map crashed after clicking on it. MapButton allows the user to click or draw a rectangle in the drawing area and returns the coordinates for further processing. See developer sample #30.

As alternative one can use the following call:

Autodesk.Map.IM.Graphic.Polygon poly = this.Application.Documents.Active.Map.GetRectangle("first point:", "second point:");

further details Map API Doc: MapLogic.GetRectangle Method

Map 2103, SP2

Map API - MapButton

In Map 2013 SP2 funktioniert der MappButton nicht - es kommt zum Absturz. Über den MapButton kann man dem Benutzer ermöglichen z.B. ein Punkt oder ein Rechteck im Zeichenbereich aufzuziehen und dann die entsprechende Koordinaten auszuwerten (siehe Developer Sample 30_MapButton).

Als Alternative kann man folgenden Aufruf verwenden (Beispiel Rechteck):

Autodesk.Map.IM.Graphic.Polygon poly = this.Application.Documents.Active.Map.GetRectangle("Erster Eckpunkt:", "Zweiter Eckpunkt:");

siehe Map API Doc: MapLogic.GetRectangle Method

Map 2013, SP2