ImportTerritories method
Imports data that defines a set of territories as a DataSet object; similar to the Import Territories Wizard. Fails if the map already contains a DataSet object with a DataMapType property of geoDataMapTypeTerritory.
Applies to
Collections: DataSets
Syntax
Click a parameter to jump to its description below.
object.ImportTerritories(DataSourceMoniker, [ArrayOfFields], [Country], [Delimiter], [ImportFlags])
Parameters
Part |
Description |
---|---|
object |
Required. An expression that returns a DataSets collection |
DataSourceMoniker |
Required String. File name to import. Can also provide information on which part of the file to import. See the DataSourceMoniker syntax topic for the correct syntax to use for this parameter. |
ArrayOfFields |
Optional Variant. A two-column array:
|
Country |
Optional GeoCountry. Country associated with the data. Default is geoCountryDefault. See the GeoCountry values topic for a list of GeoCountry values and their descriptions. |
Delimiter |
Optional GeoDelimiter. Characters that separate individual fields. Can be one or more characters. Required for importing text files. Default is geoDelimiterDefault. GeoDelimiterValueDescription geoDelimiterComma44Fields separated by commas (","). Default for .csv files. geoDelimiterDefault0 MapPoint determines the delimiter based on the file type. File typeDefaultDelimiter .asctab .csvcomma .tabtab .txttab geoDelimiterSemicolon59Fields separated by semicolons. geoDelimiterTab9Fields separated by tabs ("\t"). Default for .tab, .txt, and .asc files.
|
ImportFlags |
Optional Long. Provides information about the DataSourceMoniker and the data in the file. Multiple values can be passed by using the Microsoft Visual Basic "Or" operator (for example, geoImportExcelNamedRange Or geoImportFirstRowIsNotHeadings). GeoImportFlagsValueDescription geoImportAccessQuery4DataSourceMoniker specifies an Access query. geoImportAccessTable0DataSourceMoniker specifies an Access table. Default. geoImportExcelA10DataSourceMoniker specifies Excel A1 syntax. Default. geoImportExcelNamedRange4DataSourceMoniker specifies an Excel named range. geoImportExcelR1C12DataSourceMoniker specifies Excel R1C1 syntax. geoImportExcelSheet0DataSourceMoniker specifies an Excel worksheet. Default. geoImportFirstRowIsHeadings0First row of the file contains field names. Default. geoImportFirstRowNotHeadings1First row of the file does not contain field names.
|
Remarks
To open the Import Territories Wizard for user input, use the ShowImportTerritoriesWizard method on the DataSets collection.
To learn more about mapping data, see the Getting started with data sets and data mapping reference topic.
For information on territories in MapPoint, see the About territories reference topic.
Example
Importing data from a spreadsheet
Sub CreateTerritoriesMap()
Dim objApp As New MapPoint.Application
objApp.Visible = True
objApp.UserControl = True
Dim szconn As String
Dim oDS As MapPoint.DataSet
With objApp.ActiveMap.DataSets
'Excel sheet
szconn = objApp.Path & "\Samples\Terrs.xls!Sheet1!A1:E127"
Set oDS = .ImportTerritories(szconn, , geoCountryUnitedStates, , geoImportExcelA1)
End With
End Sub
Using an Array
[Visual Basic 6.0]
Sub CreateTerritoriesMap()
Dim objApp As New MapPoint.Application
objApp.Visible = True
objApp.UserControl = True
Dim szconn As String
Dim oDS As MapPoint.DataSet
Dim arArray(1 To 4, 1 To 2) As Variant
arArray(1, 1) = 2
arArray(1, 2) = geoFieldRegion2
arArray(2, 1) = 3
arArray(2, 2) = geoFieldRegion1
arArray(3, 1) = 4
arArray(3, 2) = geoFieldCountry
arArray(4, 1) = 5
arArray(4, 2) = geoFieldTerritory
With objApp.ActiveMap.DataSets
'Text file with tab and no headings
szconn = objApp.Path & "\Samples\Terrs.txt"
Set oDS = .ImportTerritories(szconn, arArray, geoCountryUnitedStates, geoDelimiterTab, geoImportFirstRowNotHeadings)
End With
End Sub
[C#]
void CreateTerritoriesMap()
{
MapPoint.ApplicationClass objApp = new MapPoint.ApplicationClass();
objApp.Visible = true;
objApp.UserControl = true;
string szconn;
MapPoint.DataSet oDS;
object [,] arArray = new object [4, 2];
arArray[0, 0] = 2;
arArray[0, 1] = MapPoint.GeoFieldType.geoFieldRegion2;
arArray[1, 0] = 3;
arArray[1, 1] = MapPoint.GeoFieldType.geoFieldRegion1;
arArray[2, 0] = 4;
arArray[2, 1] = MapPoint.GeoFieldType.geoFieldCountry;
arArray[3, 0] = 5;
arArray[3, 1] = MapPoint.GeoFieldType.geoFieldTerritory;
//Text file with tab and no headings
szconn = objApp.Path + "\\Samples\\Terrs.txt";
oDS = objApp.ActiveMap.DataSets.ImportTerritories(szconn,
arArray,
MapPoint.GeoCountry.geoCountryUnitedStates,
MapPoint.GeoDelimiter.geoDelimiterTab,
MapPoint.GeoImportFlags.geoImportFirstRowNotHeadings);
}
Note These samples are specifically for use in MapPoint North America; they are for illustration purposes only.