Share via


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 Microsoft 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.

GeoDelimiterValueDescription
geoDelimiterComma44Fields separated by commas (","). Default for .csv files.
geoDelimiterDefault0
MapPoint determines the delimiter based on the file type.
File typeDefault Delimiter
.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

Examples

Linking to a spreadsheet

[Visual Basic 6.0]
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

[C#]
void CreateTerritoriesByLinkingData()
{
  MapPoint.ApplicationClass objApp = new MapPoint.ApplicationClass();
  objApp.Visible = true;
  objApp.UserControl = true;
  string szconn;
  MapPoint.DataSet oDS;

  //Excel sheet
  szconn = objApp.Path + "\\Samples\\Terrs.xls!Sheet1!A1:E127";
  oDS = objApp.ActiveMap.DataSets.LinkTerritories(szconn, "ID",
    Type.Missing,
    MapPoint.GeoCountry.geoCountryUnitedStates,
    MapPoint.GeoDelimiter.geoDelimiterDefault,
    MapPoint.GeoImportFlags.geoImportExcelA1);
}

Using an Array

[Visual Basic 6.0]
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 specifically for use in MapPoint North America; they are for illustration purposes only.