LinkTerritories method

Links data that defines a set of territories as a DataSet object; similar to the Link 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 .LinkTerritories(DataSourceMoniker, PrimaryKeyField, [ArrayOfFields], [Country], [Delimiter], [ImportFlags])

Parameters

Part Description
object Required. An expression that returns a DataSets collection.
DataSourceMoniker Required String. File name to link. Can also provide information on which part of the file to link. See the DataSourceMoniker syntax topic for the correct syntax to use for this parameter.
PrimaryKeyField Required Variant. Key field in the data file. Can be either the field name or the ordinal. Is always linked to, whether it is listed in ArrayOfFields or not. Must be a unique field of values (for example, customer number or order number).
ArrayOfFields Optional Variant. A two-column array:

The first column contains the field name or an integer representing the field index (which starts at 1) of each field to link. If a Field object is not listed in the array, then it is given a GeographicFieldType property of geoFieldSkipped.

The second column designates one of three ways to treat the record:

Use a GeoFieldType value of geoFieldTerritory, which MapPoint will use to determine the territory names.

Use a string, which MapPoint will interpret as the field name for geoFieldData.

Leave blank to have MapPoint determine the field's contents and title.

If this parameter is not supplied, then all fields in the data source are linked.

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 linking text files. Default is geoDelimiterDefault.
GeoDelimiter Value Description
geoDelimiterComma
44
Fields separated by commas (","). Default for .csv files.
geoDelimiterDefault
0
MapPoint determines the delimiter based on the file type.
File type Default Delimiter
.asc tab
.csv comma
.tab tab
.txt tab
geoDelimiterSemicolon
59
Fields separated by semicolons.
geoDelimiterTab
9
Fields 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 Visual Basic "Or" operator (for example, geoImportExcelNamedRange Or geoImportFirstRowIsNotHeadings).
GeoImportFlags Value Description
geoImportAccessQuery
4
DataSourceMoniker specifies an Access query.
geoImportAccessTable
0
DataSourceMoniker specifies an Access table. Default.
geoImportExcelA1
0
DataSourceMoniker specifies Excel A1 syntax. Default.
geoImportExcelNamedRange
4
DataSourceMoniker specifies an Excel named range.
geoImportExcelR1C1
2
DataSourceMoniker specifies Excel R1C1 syntax.
geoImportExcelSheet
0
DataSourceMoniker specifies an Excel worksheet. Default.
geoImportFirstRowIsHeadings
0
First row of the file contains field names. Default.
geoImportFirstRowNotHeadings
1
First row of the file does not contain field names.

Remarks

To open the Link Territories Wizard for user input, use the ShowLinkTerritoriesWizard 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.

Examples

Linking to a spreadsheet

  
    Sub CreateTerritoriesByLinkingData()

  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 = .LinkTerritories(szconn, "ID", geoCountryUnitedStates, , geoImportExcelA1)   End With
End Sub

Using an Array

  
    Sub CreateTerritoriesByLinkingData()

  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 = .LinkTerritories(szconn, 1, arArray, geoCountryUnitedStates, geoDelimiterTab, geoImportFirstRowNotHeadings)   End With
End Sub

Note  These samples are specific for use in MapPoint North America; they are for illustration purposes only.