Map Feature Attributes
Each map feature can also have attributes. If the map feature is a town, its attributes can be its name, or the number of inhabitants. Attributes can be used, for example, for graphical rendering. In the section
Creating a Colored Line Renderer the color of polylines representing contour lines on a map is defined by the elevation attribute.
Attributes belong to the class
IlvFeatureAttribute. They are stored in the following two classes:
IlvFeatureAttributeInfo, which defines the attribute properties, such as name, type, mandatory, or optional characters.
The following code sample lists the attributes of an
IlvMapFeature object and displays them on the screen.
void
dumpAttributes(const IlvMapFeature* feature)
{
const IlvFeatureAttributeProperty* attributes =
feature->getAttributes();
if(!attributes)
return;
const IlvFeatureAttributeInfo* info =
attributes->getInfo();
if(info) {
IlvUInt count;
count = info->getAttributesCount();
for(IlvUInt i = 0; i < count; i++) {
const char* name = info->getAttributeName(i);
const IlvMapClassInfo* clsinfo = info->getAttributeClass(i);
const IlvFeatureAttribute* fa = attributes->getAttribute(i);
if(clsinfo->isSubtypeOf(IlvStringAttribute::ClassInfo())) {
const char *str = ((IlvStringAttribute*)fa)->getValue();
IlvPrint("%s %s", name ? name : "", str ? str : "");
} else if(clsinfo->isSubtypeOf(IlvIntegerAttribute::ClassInfo())){
int in = ((IlvIntegerAttribute*)fa)->getValue();
IlvPrint("%s %d", name ? name : "", in);
} else if(clsinfo->isSubtypeOf(IlvDoubleAttribute::ClassInfo())){
double dbl = ((IlvDoubleAttribute*)fa)->getValue();
IlvPrint("%s %g", name ? name : "", dbl);
} else if(clsinfo->isSubtypeOf(IlvBooleanAttribute::ClassInfo())){
IlvBoolean bo = ((IlvBooleanAttribute*)fa)->getValue();
IlvPrint("%s %s", name ? name : "",
bo ? "true" : "false");
}
}
}
}
The attributes are of different types, according to whether they represent whole numbers, floating-point values, character strings, and so on. The predefined attributes, all of the
IlvFeatureAttribute class, are in the
attribute package.
Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.