Main Content

makeattribspec

Create attribute specification

Description

attribspec = makeattribspec(S) creates an attribute specification for use with the kmlwrite, wmmarker, wmline, and wmpolygon functions based on the vector geographic features stored in S.

The kmlwrite function creates an HTML table from attribute fields. The first column of the table includes attribute labels and the second column includes attribute values as text. Use an attribute specification with the kmlwrite function and Description name-value argument to specify which attribute fields to include in the HTML table and the format of the attribute values.

When you plot features using wmmarker, wmline, or wmpolygon, you can view feature balloons with attribute information by clicking on features. Use an attribute specification with wmmarker, wmline, or wmpolygon and the Description name-value argument to specify which attribute fields to include in the feature balloons and the format of the attribute values.

example

Examples

collapse all

Import a shapefile representing tsunami events reported over several decades, tagged geographically by source location, as a geospatial table. Create an attribute specification from the table.

GT = readgeotable("tsunamis.shp","CoordinateSystemType","geographic");
attribspec = makeattribspec(GT)
attribspec = struct with fields:
           Year: [1x1 struct]
          Month: [1x1 struct]
            Day: [1x1 struct]
           Hour: [1x1 struct]
         Minute: [1x1 struct]
         Second: [1x1 struct]
       Val_Code: [1x1 struct]
       Validity: [1x1 struct]
     Cause_Code: [1x1 struct]
          Cause: [1x1 struct]
         Eq_Mag: [1x1 struct]
        Country: [1x1 struct]
       Location: [1x1 struct]
     Max_Height: [1x1 struct]
       Iida_Mag: [1x1 struct]
      Intensity: [1x1 struct]
     Num_Deaths: [1x1 struct]
    Desc_Deaths: [1x1 struct]

Remove all attributes from the specification, except for the attributes describing the maximum height, cause, year, location, and country.

desiredAttributes = {'Max_Height','Cause','Year','Location','Country'};
allAttributes = fieldnames(attribspec);
attributes = setdiff(allAttributes,desiredAttributes);
attribspec = rmfield(attribspec,attributes)
attribspec = struct with fields:
          Year: [1x1 struct]
         Cause: [1x1 struct]
       Country: [1x1 struct]
      Location: [1x1 struct]
    Max_Height: [1x1 struct]

Rename the Max_Height attribute to Maximum Height and highlight each attribute label in bold font.

attribspec.Max_Height.AttributeLabel = "<b>Maximum Height</b>";
attribspec.Cause.AttributeLabel = "<b>Cause</b>";
attribspec.Year.AttributeLabel = "<b>Year</b>";
attribspec.Location.AttributeLabel = "<b>Location</b>";
attribspec.Country.AttributeLabel = "<b>Country</b>";

Add Meters to the format of the maximum height attribute. Set the format of the year attribute to include no decimal places.

attribspec.Max_Height.Format = "%.1f Meters";
attribspec.Year.Format = "%.0f";

Export the selected attributes and tsunami source locations to a KML file.

kmlwrite("tsunamis.kml",GT,"Description",attribspec,"Name",GT.Location)

Import a shapefile representing tsunami events reported over several decades, tagged geographically by source location.

GT = readgeotable("tsunamis.shp","CoordinateSystemType","geographic");

Create an attribute specification for use in the feature balloons. Modify the specification so that it defines a table of values, including year, cause, country, location, and maximum height. The attribute specification defines the format of the expected value for each field.

attribspec = makeattribspec(GT);

desiredAttributes = ...
       {'Max_Height','Cause','Year','Location','Country'};
allAttributes = fieldnames(attribspec);
attributes = setdiff(allAttributes,desiredAttributes);
attribspec = rmfield(attribspec,attributes);
attribspec.Max_Height.AttributeLabel = "<b>Maximum Height</b>";
attribspec.Max_Height.Format = "%.1f Meters";
attribspec.Cause.AttributeLabel = "<b>Cause</b>";
attribspec.Year.AttributeLabel = "<b>Year</b>";
attribspec.Year.Format = "%.0f";
attribspec.Location.AttributeLabel = "<b>Location</b>";
attribspec.Country.AttributeLabel = "<b>Country</b>";

Create a web map with a base layer containing ocean details. Add the marker overlay. Display the table data you specified in the attribute specification by selecting a marker.

webmap("ocean basemap");
wmmarker(GT,"Description",attribspec,... 
	     "OverlayName","Tsunami Events")
wmzoom(2)

World map with red markers that represent tsunami events. A balloon displays information about one of the markers.

Input Arguments

collapse all

Vector geographic features, specified as one of these:

  • A geospatial table containing geopointshape, geolineshape, or geopolyshape objects. The makeattribspec function does not support geospatial tables containing more than one type of shape object. For more information about geospatial tables, see Create Geospatial Tables.

  • A geopoint vector.

  • A geoshape vector with no dynamic vertex properties.

  • A geographic structure array (geostruct) with Lat and Lon fields.

Output Arguments

collapse all

Attribute specification, returned as a structure array with two levels. The top level contains a field for each attribute in S. Each field in the top level contains a scalar structure with two fields.

Field

Description

AttributeLabel

Attribute label for the kmlwrite function to use in the first column of the HTML table, returned as a character vector. By default, the label is identical to the name of the corresponding attribute field.

Format

Format for the kmlwrite function to use when converting the attribute value to text, returned as a character vector. For more information about formatting data, see the sprintf function.

You can change the structure array before using it with the kmlwrite function. For example, you can remove attributes from the structure or change the AttributeLabel field to include spaces.

Version History

Introduced before R2006a

expand all