You are here: Popular Formats > XML (Extensible Markup Language) Reader/Writer > xfMap > Feature Mapping Rules > Geometry Traits (trait element)

Geometry Traits (trait element)

A <geometry> element may have any number of optional <trait> elements. These elements specify any number of geometry traits for the geometry that is under construction. Geometry traits passed to the geometry builder in this manner will appear on the geometry currently being constructed, but will not affect any component geometries in the case that the traits are passed to a composite builder.

The geometry traits supplied are represented as name and value pairs, both of which have expression sequences as their values. They are represented in the xfMap by the <trait>, <name>, and <value> elements:

<trait required=”true|false” nillable=”true|false”>
	<name> <!-- an expression sequence --> </name>
	<value> <!-- an expression sequence --> </value>
</trait>
...
<trait>
	...
</trait>

The optional required attribute on the trait element defaults to true, if set to false then the trait is added to the geometry only if the trait value is not the empty string.

The optional nillable attribute on the trait element defaults to false. If nillable is not specified, or if it is false, FME will interpret an empty trait element as an empty string trait and add it to the geometry. If nillable is true, FME will interpret an empty trait element as a null trait value and add it to the gemetry.

Once again, if the <geometry> element does not have an activate attribute, then the traits will pass to the currently suspended geometry builder, reactivating it to receive traits.

The following xfMap document, traits.xmp contains a mapping rule which matches a <point> element from the points1.xml document. The mapping rule contains a geometry element with a couple of simple traits.

points1.xml

<?xml version="1.0"?>
<points>
	<point name="myPoint" num="0">
		<color>
			<red>0.324</red>
			<green>0.233</green>
			<blue>0.596</blue>
		</color>
		<location x="10.0" y="0.0" />
	</point>
	<point name="myPoint" num="1">
		<color>
			<red>0.874</red>
			<green>0.948</green>
			<blue>0.554</blue>
		</color>
		<location x="5.0" y="5.0" />
	</point>
</points>

traits.xmp

<?xml version=“1.0”?>
<xfMap>
	<feature-map>
		<mapping match=“point”>
			<feature-type>
				<extract expr=“@name” />
				<literal expr=“_” />
				<extract expr=“@num” />
			</feature-type>
			<geometry activate=“xml-point”>
				<data name=“data-string”>
					<extract expr=“./location[@x]” />
					<literal expr=“,” />
					<extract expr=“./location[@y]” />
				</data>
				<trait>
					<name>
						<literal expr=“my_geometry_trait” />
					</name>
					<value>
						<!-- We set the “my_geometry_trait” trait to be
							  “sample_value” -->
						<literal expr=“sample_value” />
					</value>
				</trait>
				<trait>
					<name>
						<literal expr=“point_num” />
					</name>
					<value>
						<!-- The expression sequence below constructs the
							  value of “point_num” to be the value of the num
							  attribute in points1.xml -->
						<extract expr=“@num” />
					</value>
				</trait>
			</geometry>
		</mapping>
	</feature-map>
</xfMap>

When the above points1.xml and traits.xmp documents are fed into the XML Reader, the following FME features are constructed:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: myPoint_0'
Attribute(string): fme_feature_type' has value myPoint_0'
Attribute(string): fme_geometry' has value fme_point'
Attribute(string): fme_type' has value fme_point'
Attribute(string): xml_type' has value xml_point'
Coordinate System: '
Geometry Type: IFMEPoint
Number of Geometry Traits: 2
GeometryTrait(string): my_geometry_trait' has value sample_value'
GeometryTrait(string): point_num' has value 0'
Coordinate Dimension: 2
(10,0)
============================================================================

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: myPoint_1'
Attribute(string): fme_feature_type' has value myPoint_1'
Attribute(string): fme_geometry' has value fme_point'
Attribute(string): fme_type' has value fme_point'
Attribute(string): xml_type' has value xml_point'
Coordinate System: '
Geometry Type: IFMEPoint
Number of Geometry Traits: 2
GeometryTrait(string): my_geometry_trait' has value sample_value'
GeometryTrait(string): point_num' has value 1'
Coordinate Dimension: 2
(5,5)
============================================================================