hello
Is there a quick sample MapSuite Desktop 3.0 equivalent to CustomDataApp sample in 2.0 (with custom data with a break render) or a document explaining how to bind data to a layer ?
Thank you
Render Custom Data MapSuite Desktop 3.0
Eric,
In Map Suite 3.0, we use the event FeatureSource.CustomColumnFetch to bind data to a layer. There is a good sample in How Do I ->Feature Layers ->Add my own Custom data to a feature layer, please have a look.
Ben
Ben, thank you for your answer.
In my case, the data are stored in a datatable.
What is exactly "e.Id" (in the event sub) and how to link to the column of the layer containing the datatable key ?
In the case of a datatable with custom data, what is the best (fastest) method to query data :
- create an index on datatable + select this column for each event CustomColumnFetch
- others ...
Thank for your help.
Eric,
We can use a cached Dictionary<string, string> to store the custom data and speed it up, please have a look at the following codes:
private Dictionary<string, string> mColumnValues;
void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e)
{
if (mColumnValues == null) // executed at the first time
{
// I create an example data table, which stores the custom data.
DataTable table = new DataTable();
table.Columns.Add(new DataColumn(“ID”, typeof(string)));
table.Columns.Add(new DataColumn(“NAME”, typeof(string)));
for (int i = 0; i < 10000; i++)
{
DataRow row = table.NewRow();
// Init the row object,
table.Rows.Add(row);
}
// The table.Select(string.Format("[ID] == {0}", e.Id)); isn’t fast enough.
// Initialize a cache dictionary to help speed up.
mColumnValues = new Dictionary<string, string>();
for (int i = 0; i < 10000; i++)
{
mColumnValues.Add(table.Rows[i][“ID”].ToString(), table.Rows[i][“NAME”].ToString());
}
}
else
{
if (mColumnValues.ContainsKey(e.Id))
{
e.ColumnValue = mColumnValues[e.Id];
}
else
{
e.ColumnValue = string.Empty;
}
}
}
Thanks,
Ben
Ben,
Thank you for your reply and the sample.
Please, what is really e.Id (in the CustomColumnFetchEventArgs) ?
The values I receive in the event are a sequence of numbers 1, 2, 3, ... which is not a feature of the layer data.
How can I get the values of a feature of the layer, to query the PK in the custom data (through a cached Dictionary) ?
Thanks.
Eric,
The e.Id is the id of the feature in the feature Source. We need to bind this id with the custom data in database. For example, I have a shapefile with a column called “name”, and my custom Database has 2 columns “name” and “value”, and I want to link the column “value” using “name”.
Here is usually what I need to do. First, create a dictionary from the shape layer {feature.id, feature.name}; 2nd as we can get “value” from “name” using the custom database, I can change the dictionary to {feature.id, value}; 3rd in the event CustomColumnFetch, for every record, we can get the “value” from the feature.id by using the dictionary {feature.id, value}.
I hope that makes sense, let me know if you have any issues.
Thanks,
Ben
Ben,
Thank you for these explanations.
I understand that I must first create the relationship between Feature.Id and feature column "Name" in a dictionary.
I hoped to receive directly the column "Name" in the event.
What is the best method to create the dictionary (CustomColumnFetchEventArgs first event, as the custom data dictionary)?
and how to create (select Name from layer --> order = feature.Id)?
Is it necessary to save this dictionary to speed up future access?
(I can't find sample on this)
Thank you.
Eric,
For the case I listed in my last message, I think we can first, create a dictionary Dic1(feature.id, feature.name) from layer, 2nd create dictionary Dic2(name, value) from the custom data; 3rd, create the dictionary Dic3(feature.id, value) ( Dic3.Add(id, Dic2[Dic1[id]]) ) and Dic3 is the one we want.
It takes some time to generate the Dic3[id, value] but good thing is we only need to generate it once. Every time the event is raised, we just get the corresponding value according to the passed id. Sure we can cache it to speed up the loading for the next time, but one issue is that if the custom data is changed, we should make sure we know it and update the cached Dictionary, this is the cost.
Thanks,
Ben
Thank you Ben.
I don't know how to create the first dictionary Dic1(feature.id, feature.name) from layer.The feature.id (e.Id that I get in the event) is not present in the layer.
Please do you have a sample.
Thank you.
OK, I've found how to get the feature.id :
Layer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns)
Thanks for all.
Eric,
Sorry forgot to tell you every feature has an Id and by the way, instead of returning all the columns, you can only get the column you need with the code:
Layer.QueryTools.GetAllFeatures(new string[]{"name"});
This can give you some performance benefits.
Thanks,
Ben