Hi every body.
I'm developing an add-on to Map3D 2013, using .net4.0.
To show non-spatial data of feature sources, I firstly used Map3D built-in form using "_+MapDataTable" command and passing my layer definition as it's argument, which works fine, but the problem was that the data table is editable (all fields but "OBJECTID"), but I need to allow user to view or view and edit on a specified layer. So I decided to develop my custom data view form, and fill data using the below code (based on MgFeatureReader class):
private void UpdateTable() { if (SelectedLayer == null) { return; } if (SelectedLayer == "") { return; } if (!AcMapMap.GetCurrentMap().GetLayers().Contains(SelectedLayer)) { return; } using (DocumentLock lck = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()) { Data = new System.Data.DataTable(); Data.Columns.Clear(); DataRow[] fldrs = FieldsTable.Select("layername='" + SelectedLayer + "'"); foreach (DataRow fldr in fldrs) { Data.Columns.Add(fldr["name"].ToString(), typeof(string)); } int propertyCount; String propertyName; MgLayerBase layer = AcMapMap.GetCurrentMap().GetLayers().GetItem(SelectedLayer); MgFeatureReader featureReader = layer.SelectFeatures(new MgFeatureQueryOptions()); while (featureReader.ReadNext()) { DataRow ndr = Data.NewRow(); propertyCount = featureReader.GetPropertyCount(); for (int i = 0; i < propertyCount; i++) { propertyName = featureReader.GetPropertyName(i); if (!Data.Columns.Contains(propertyName)) { continue; } ndr[propertyName] = featureReader.GetString(propertyName); } Data.Rows.Add(ndr); } dataGridView_list.DataSource = Data; } }
This code works without any error, but it takes so long time, based on number of fields of the data layer. (1 to 30 seconds even more!!!).
But Map3D's built-in interface, works rapid enough and without any delay.
Does anyone knows about this? or, is there any solution to make Map3D's built-in data view interface read-only? I'm really confused!!!
Any help would be appreciated greatly.
Solved! Go to Solution.
Hi every body.
I'm developing an add-on to Map3D 2013, using .net4.0.
To show non-spatial data of feature sources, I firstly used Map3D built-in form using "_+MapDataTable" command and passing my layer definition as it's argument, which works fine, but the problem was that the data table is editable (all fields but "OBJECTID"), but I need to allow user to view or view and edit on a specified layer. So I decided to develop my custom data view form, and fill data using the below code (based on MgFeatureReader class):
private void UpdateTable() { if (SelectedLayer == null) { return; } if (SelectedLayer == "") { return; } if (!AcMapMap.GetCurrentMap().GetLayers().Contains(SelectedLayer)) { return; } using (DocumentLock lck = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()) { Data = new System.Data.DataTable(); Data.Columns.Clear(); DataRow[] fldrs = FieldsTable.Select("layername='" + SelectedLayer + "'"); foreach (DataRow fldr in fldrs) { Data.Columns.Add(fldr["name"].ToString(), typeof(string)); } int propertyCount; String propertyName; MgLayerBase layer = AcMapMap.GetCurrentMap().GetLayers().GetItem(SelectedLayer); MgFeatureReader featureReader = layer.SelectFeatures(new MgFeatureQueryOptions()); while (featureReader.ReadNext()) { DataRow ndr = Data.NewRow(); propertyCount = featureReader.GetPropertyCount(); for (int i = 0; i < propertyCount; i++) { propertyName = featureReader.GetPropertyName(i); if (!Data.Columns.Contains(propertyName)) { continue; } ndr[propertyName] = featureReader.GetString(propertyName); } Data.Rows.Add(ndr); } dataGridView_list.DataSource = Data; } }
This code works without any error, but it takes so long time, based on number of fields of the data layer. (1 to 30 seconds even more!!!).
But Map3D's built-in interface, works rapid enough and without any delay.
Does anyone knows about this? or, is there any solution to make Map3D's built-in data view interface read-only? I'm really confused!!!
Any help would be appreciated greatly.
Solved! Go to Solution.
Hi,
first of all I can confirm your observations - and I don't have an explanation nor solution.
To me it seems the FeatureReader itself is not the limiting factor but accessing the "properties" makes it slow.
Does anyone else have some information on this?
Rob
Hi,
first of all I can confirm your observations - and I don't have an explanation nor solution.
To me it seems the FeatureReader itself is not the limiting factor but accessing the "properties" makes it slow.
Does anyone else have some information on this?
Rob
Hi,
it looks like calling GetPropertyType and GetPropertyName within the FOR loop slows things down.
Here are some further details:
http://raumpatrouille3d.blogspot.ch/2016/07/map-api-mgfeaturereader-improve-speed.html
....
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;
Hi,
it looks like calling GetPropertyType and GetPropertyName within the FOR loop slows things down.
Here are some further details:
http://raumpatrouille3d.blogspot.ch/2016/07/map-api-mgfeaturereader-improve-speed.html
....
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;
Hi dead Robert.
I tried this and it worked greatly. Thanks a lot, I appreciate kindly.
I tested this on a large data layer containing over than 13000 rows on 90 fields. It took about 15 seconds to respond. However, before applying this solution, it took along time about 30 minutes!!! So, that would be a great victory!!!
Hi dead Robert.
I tried this and it worked greatly. Thanks a lot, I appreciate kindly.
I tested this on a large data layer containing over than 13000 rows on 90 fields. It took about 15 seconds to respond. However, before applying this solution, it took along time about 30 minutes!!! So, that would be a great victory!!!
Hi,
there is one thing to keep in mind though - as we do not check property name and property type for each record we assume that the order of attributes is always the same for all records whilst iterating over the FeatureReader.
I don't know if that is the case, I just hope it is - no good foundation for building applications. The documentation doesn't give any clue and one would need to look into the FDO source code to find out...
Rob
Hi,
there is one thing to keep in mind though - as we do not check property name and property type for each record we assume that the order of attributes is always the same for all records whilst iterating over the FeatureReader.
I don't know if that is the case, I just hope it is - no good foundation for building applications. The documentation doesn't give any clue and one would need to look into the FDO source code to find out...
Rob
Can't find what you're looking for? Ask the community or share your knowledge.