Thread: DisplayDataMap
View Single Post

  #7 (permalink)  
Old 09-20-2006
Loggy Loggy is offline
Junior Member
White Belt
 
Join Date: Aug 2006
Posts: 3
Multiple Symbol Map

I encountered lots of problems with the DataSet.DisplayDataMap() method. I am using MapPoint 2006 and C# with VS 2005, but I will write here what I learned. I got the all-explaining "The parameter is incorrect." message, but I believe I know what causes it for the multiple symbol map.

Firstly, all of the arrays must be properly sized. If you pass the parameter stating that there are 5 ranges, then in the array where you define the ranges (myranges[] below), it must have 6 numbers (array size = 6) to create the bounds on the 5 ranges. In that case, you must then pass an array of size 5 for the range names (myrangenames[]) and an array of size 5 for the symbols (symbols[]). If these sizes are off, it may throw the "parameter is incorrect" message, or it might just not work as you think. If you want 8 ranges, the symbols[] and myrangenames[] arrays should be size=8 and the myranges[] array should be size=9.

In addition, the myranges[] array MUST be ascending order. If it is in descending order (I didn't test no order), it does not throw an error, but it does not work properly either.

Also, if possible, step through the debugger and make sure the 2nd parameter to the method, the field parameter, is a proper MapPoint.Field object. This can also cause the "parameter is incorrect" message.

This applies to a 5 column CSV file. I encountered problems when my fieldSpecifications array did not have the proper dimensions (for a 10 column CSV file, it should be size = [10][2]) that matched the CSV file. In addition, I made sure the headings in the first column of my csv file matched the names I gave in the fieldSpecifications, but that is probably not necessary.

Here's my CSV file I'm importing:
Latitude,Longitude,Field1,Field2,Field3
32.90,-117.2,1152558003,10,100
32.91,-117.3,1152558004,11,101
...

Code:
//Define field specification
object[,] fieldSpecifications = {
            {"Latitude", MapPoint.GeoFieldType.geoFieldLatitude},
            {"Longitude", MapPoint.GeoFieldType.geoFieldLongitude},
            {"Field1", MapPoint.GeoFieldType.geoFieldData},
            {"Field2", MapPoint.GeoFieldType.geoFieldData},
            {"Field3", MapPoint.GeoFieldType.geoFieldData}
};

// Import the CSV file
MapPoint.DataSet objDataSet = map.DataSets.ImportData(
                                "c:\\tmp.csv",
                                fieldSpecifications,
                                 MapPoint.GeoCountry.geoCountryUnitedStates,
                                MapPoint.GeoDelimiter.geoDelimiterDefault,
                                0
);

//Define data map columns
// This will be the index for "Field2"
object fieldIndex = 4;

//Now get fields
MapPoint.Field datafield;
datafield = objDataSet.Fields.get_Item(ref fieldIndex);

// This creates 5 ranges
// -100 through -90, -90 through -80, and so on
object[] myranges = new object[6] { -100, -90, -80, -70, -60, 0 };

// This names the 5 ranges
object[] myrangenames = new object[5] { "-100 to -90",
                                        "-90 to -80",
                                        "-80 to -70",
                                        "-70 to -60",
                                        "-60 to 0"
};

// This creates symbols for the 5 ranges in order
// These are the symbol IDs
// Symbol 16 applies to the range -100 to -90
object[] symbols = new object[5] {  
                                    16,
                                    17,
                                    18,
                                    19,
                                    20  
};

//Now display datamap
try
{
    // Display the imported data set using this mapping technique
    MapPoint.DataMap datamap = objDataSet.DisplayDataMap(
                            MapPoint.GeoDataMapType.geoDataMapTypeMultipleSymbol,
                            datafield,
                            MapPoint.GeoShowDataBy.geoShowByLatLong,
                            MapPoint.GeoCombineDataBy.geoCombineByDefault,
                            MapPoint.GeoDataRangeType.geoRangeTypeDefault,
                            MapPoint.GeoDataRangeOrder.geoRangeOrderDefault,
                            MapPoint.GeoDataConstants.geoColorSchemeDefault,
                            5,              // This should be the # of ranges        
                            myranges,       // Should be an array of size(# of ranges +1)    
                            myrangenames,   // An array of range names size(# of ranges)
                            System.Reflection.Missing.Value,
                            System.Reflection.Missing.Value,
                            symbols         // Array of symbols corresponding to the ranges
        );

    // Legend name
    datamap.LegendTitle = "My Legend: Field2";

    // Display legend pane
    datamap.Application.PaneState = MapPoint.GeoPaneState.geoPaneLegend;

    // Zoom to the imported data set
    objDataSet.ZoomTo();
}
catch (Exception except)
{
    MessageBox.Show(except.ToString());
}
Reply With Quote