makeattribspec

Attribute specification from geographic data structure

Syntax

attribspec = makeattribspec(S)

Description

attribspec = makeattribspec(S) creates an attribute specification from S suitable for use with kmlwrite. S can be any of the following:

  • geopoint vector

  • geoshape vector, with 'point' Geometry and no dynamic vertex properties

  • geostruct with 'Lat' and 'Lon' coordinate fields

The return value, attribspec, is a scalar MATLAB® structure with two levels. The top level consists of a field for each attribute in S. Each of these fields contains a scalar structure with a fixed pair of fields:

AttributeLabelA character vector that corresponds to the name of the attribute field in S. With kmlwrite, the character vector is used to label the attribute in the first column of the HTML table. The character vector may be modified prior to calling kmlwrite. You might modify an attribute label, for example, because you want to use spaces in your HTML table, but the attribute field names in S must be valid MATLAB variable names and cannot have spaces themselves.
FormatThe sprintf format character specification that converts the attribute value to a character vector.

Examples

  1. Import a shapefile representing tsunami (tidal wave) events reported between 1950 and 2006 and tagged geographically by source location, and construct a default attribute specification (which includes all the shapefile attributes):

    s = shaperead('tsunamis', 'UseGeoCoords', true);
    attribspec = makeattribspec(s)
    attribspec = 
    
               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]

  2. Modify the attribute specification to

    • Display just the attributes Max_Height, Cause, Year, Location, and Country

    • Rename the Max_Height field to Maximum Height

    • Display each attribute's label in bold type

    • Set to zero the number of decimal places used to display Year

    • Add “Meters” to the Height format, given independent knowledge of these units

    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>';

  3. Use the attribute specification to export the selected attributes and source locations to a KML file as a Description:

    filename = 'tsunami.kml';
    kmlwrite(filename, s, 'Description', attribspec, ...
       'Name', {s.Location})

Tips

  • The easiest way to construct an attribute specification is to create one, using makeattribspec, and then modify the output, removing attributes or changing the Format field for one or more attributes.

  • You can use an attribute specification with kmlwrite as the value of the Description parameter. kmlwrite constructs an HTML table that consists of a label for the attribute in the first column and the value of the attribute in the second column. You can modify the attribute specification to control which attribute fields are written to the HTML table and their format.