Joins

AutoCAD Map 3D Geospatial Platform API

 
Joins
 
 
 

Joins extend a feature source by combining it with data from another feature source, similar to a database join. They are commonly used to combine GIS data with data from a database.

For example, an SDF file containing the following properties:

  • parcel geometry
  • parcel ID

could be joined with an ODBC database containing the following properties:

  • parcel ID
  • owner name
  • assessment value
  • land use designation

The join is defined in the feature source definition. Each join requires 2 feature classes. The primary feature class contains the geometry for display in AutoCAD Map 3D. The secondary feature class does not need geometry, but it must have a property that matches a property in the primary feature class. In the example above, the SDF file contains the primary feature class and the ODBC database contains the secondary feature class.

In most cases the feature classes will be from different feature sources, but it is possible to create a self-referencing join within 1 feature class or a join between 2 feature classes in the same feature source.

To create a joined feature source, begin with the secondary feature source. This does not require anything special. For example, the following is a simple connection to an ODBC database:

<FeatureSource 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xsi:noNamespaceSchemaLocation="MapFeatureSource-1.0.0.xsd" 
    version="1.0.0">
  <Provider>OSGeo.ODBC.3.2</Provider>
  <Parameter>
    <Name>Password</Name>
    <Value></Value>
  </Parameter>
  <Parameter>
    <Name>GenerateDefaultGeometryProperty</Name>
    <Value>false</Value>
  </Parameter>
  <Parameter>
    <Name>ConnectionString</Name>
    <Value></Value>
  </Parameter>
  <Parameter>
    <Name>DataSourceName</Name>
    <Value>OWNERS</Value>
  </Parameter>
  <Parameter>
    <Name>UserId</Name>
    <Value></Value>
  </Parameter>
  <ConfigurationDocument></ConfigurationDocument>
  <LongTransaction></LongTransaction>
</FeatureSource>

The primary feature source defines the join. It must identify the secondary feature source and which properties are to be used for the join. For example, the following is a feature source definition for an SDF file with a join to an ODBC database:

<FeatureSource 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xsi:noNamespaceSchemaLocation="MapFeatureSource-1.0.0.xsd" 
    version="1.0.0">
  <Provider>OSGeo.SDF.3.2</Provider>
  <Parameter>
    <Name>ReadOnly</Name>
    <Value>false</Value>
  </Parameter>
  <Parameter>
    <Name>File</Name>
    <Value>C:\some\folder\Parcels.sdf</Value>
  </Parameter>
  <ConfigurationDocument></ConfigurationDocument>
  <LongTransaction></LongTransaction>
  <Extension>
    <Name>Parcels_Joins1</Name>
    <FeatureClass>SHP_Schema:Parcels</FeatureClass>
    <AttributeRelate>
      <AttributeClass>Fdo:Parcels</AttributeClass>
      <ResourceId>Library://ODBC_1</ResourceId>
      <Name>Parcels</Name>
      <AttributeNameDelimiter>|</AttributeNameDelimiter>
      <RelateType>LeftOuter</RelateType>
      <ForceOneToOne>true</ForceOneToOne>
      <RelateProperty>
        <FeatureClassProperty>APN</FeatureClassProperty>
        <AttributeClassProperty>APN</AttributeClassProperty>
      </RelateProperty>
    </AttributeRelate>
  </Extension>
</FeatureSource>

The <Extension> element defines the join. <Name> is the name of the join, used in a layer definition that references the feature source. If a feature source defines more than one join they must have different names. <FeatureClass> is a feature class in the primary feature source.

<AttributeRelate> defines a join to a single feature source. It is possible for the primary feature source to have joins to more than one secondary feature source. This is represented by multiple <AttributeRelate> elements. As an example, the owner information could be in one database table and assessment information could be in another.

For each join, <AttributeClass> defines the schema and feature class in the secondary feature source. <ResourceId> is the resource identifier. <RelateType> is the type of join. This release of AutoCAD Map 3D supports left outer joins and inner joins.

The join can have multiple <RelateProperty> elements. These define the fields that must match for the join.

Store the feature source definition using MgResourceService.SetResource(), as described in Defining Feature Sources.