Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

mappoint class

Planar point vector

Syntax

p = mappoint()
p = mappoint(x,y)
p = mappoint(x,y,Name,Value)
p = mappoint(structArray)
p = mappoint(x,y,structArray)

Description

A mappoint vector is a container object that holds planar point coordinates and attributes. The points are coupled, such that the size of the X and Y coordinate arrays are always equal and match the size of any dynamically added attribute arrays. Each entry of a coordinate pair and associated attributes, if any, represent a discrete element in the mappoint vector.

Construction

p = mappoint() constructs an empty mappoint vector, p, with these default property settings:

p = 

 0x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: []
           Y: []
For an additional example, see Construct a Default mappoint Vector.

p = mappoint(x,y) constructs a new mappoint vector and assigns the X and Y properties to the numeric array inputs, lat and lon. For an example, see Construct a mappoint Vector from x and y Values.

p = mappoint(x,y,Name,Value) constructs a mappoint vector from input arrays x and y, and then adds dynamic properties to the mappoint vector using the Name, Value argument pairs.

  • If a specified name is Metadata and the corresponding Value is a scalar structure, then the value is copied to the Metadata property. Otherwise, an error is issued.

For an example, see Construct a mappoint Vector from x, y, and Temperature Values.

p = mappoint(structArray) constructs a new mappoint vector from the fields of the structure, structArray. See for an example.

  • If structArray is a scalar structure containing the field Metadata and the field value is a scalar structure, then the Metadata field is copied to the Metadata property. Otherwise, an error is issued if the Metadata field is not a structure, or ignored if structArray is not scalar.

  • Other fields of structArray are assigned to p and become dynamic properties. Field values in structArray that are not numeric values, character vectors, or cell arrays of numeric values or character vectors are ignored.

For an example, see Construct a mappoint Vector from a Structure Array.

p = mappoint(x,y,structArray) constructs a new mappoint vector and sets the X and Y properties equal to the numeric arrays, x and y, and sets dynamic properties from the field values of the structure, structArray.

  • If structArray is a scalar structure containing the field Metadata, and the field value is a scalar structure, then it is copied to the Metadata property. Otherwise, an error is issued if the Metadata field is not a structure, or ignored if structArray is not scalar.

For an example, see Construct a mappoint Vector from x and y Numeric Arrays and a Structure Array.

Input Arguments

expand all

Vector of latitude coordinates, specified as a numeric array.

Data Types: double | single

Vector of longitude coordinates, specified as a numeric array.

Data Types: double | single

Dynamic properties, specified as an array of structures containing fields to be assigned.

Name of dynamic property, specified as a character vector.

Data Types: char

Value associated with the dynamic property Name, specified as a numeric value, logical, character vector, or a cell array of character vectors.

Data Types: char | double | single | logical | cell

Output Arguments

expand all

New object, returned as a mappoint vector

Properties

expand all

Each element in a mappoint vector is considered a feature. Feature properties contain one value (a scalar number or a character vector) for each element in the mappoint vector. The Latitude and Longitude coordinate properties are feature properties as there is one value for each feature.

Geometry and Metadata are collection properties. These properties contain only one value per class instance. The term collection is used to distinguish these two properties from other feature properties which have values associated with each feature (element in a mappoint vector).

You can attach new dynamic feature properties to the object by using dot ‘.' notation. This is similar to adding dynamic fields to a structure. Dynamic feature properties apply to each individual feature in the mappoint vector. See Construct a mappoint Vector for Two Features and Add Features Dynamicallyfor an example.

Type of geometry, specified as 'point'. For mappoint, Geometry is always 'point'.

Data Types: char

Information for the entire set of mappoint vector elements, specified as a scalar structure. You can add any data type to the structure.

Data Types: struct

Planar X coordinate, specified as a numeric row or column vector.

Data Types: double | single

Planar Y coordinates, specified as a numeric row or column vector.

Data Types: double | single

You can attach new properties to the object using dot '.' notation. The class type of the values for the dynamic properties must be either numeric, logical, character vector, or a cell array of character vectors.

Methods

appendAppend features to mappoint vector
catConcatenate mappoint vectors
dispDisplay mappoint vector
fieldnamesDynamic properties of mappoint vector
isemptyTrue if mappoint vector is empty
isfieldReturns true if dynamic property exists
ispropReturns true if property exists
lengthNumber of elements in mappoint vector
propertiesproperties of a mappoint vector
rmfieldRemove dynamic property from mappoint vector
rmpropRemove properties from mappoint vector
sizeSize of mappoint vector
structConvert mappoint vector to scalar structure
vertcatVertical concatenation for mappoint vectors

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Class Behaviors

Examples

expand all

Dynamically set the X and Y property values, and dynamically add Vertex property Z.

p = mappoint();
p.X = 1:3;
p.Y = 1:3;
p.Z = [10 10 10]
p = 

 3x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1 2 3]
           Y: [1 2 3]
           Z: [10 10 10]

Create a mappoint.

x = [40 50 60];
y = [10, 11, 12];
p = mappoint(x, y)
p = 

 3x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [40 50 60]
           Y: [10 11 12]
x = 41:43;
y = 1:3;
temperature = 61:63;
p = mappoint(x, y, 'Temperature', temperature)
p = 

 3x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [41 42 43]
              Y: [1 2 3]
    Temperature: [61 62 63]

Create a structure array and then create a mappoint vector, specifying the array as input.

structArray = shaperead('boston_placenames')
p = mappoint(structArray)
structArray = 

13x1 struct array with fields:
    Geometry
    X
    Y
    NAME
    FEATURE
    COORD


p = 

 13x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1x13 double]
           Y: [1x13 double]
        NAME: {1x13 cell}
     FEATURE: {1x13 cell}
       COORD: {1x13 cell
[structArray, A] = shaperead('boston_placenames');
x = [structArray.X];
y = [structArray.Y];
p = mappoint(x, y, A)
p = 

 13x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1x13 double]
           Y: [1x13 double]
        NAME: {1x13 cell}
     FEATURE: {1x13 cell}
       COORD: {1x13 cell}
x = 1;
y = 1;
p = mappoint(x, y)
p = 

 1x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: 1
           Y: 1

Add a feature dynamic property with a character vector value.

p.FeatureName = 'My Feature'
p = 

 1x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: 1
              Y: 1
    FeatureName: 'My Feature'

Create a mappoint vector.

x = [1 2];
y = [10 10];
p = mappoint(x, y)
p = 

 2x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1 2]
           Y: [10 10]

Add a feature dynamic property.

p.FeatureName = {'Feature 1', 'Feature 2'}
p = 

 2x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2]
              Y: [10 10]
    FeatureName: {'Feature 1' 'Feature 2'}

Add a numeric feature dynamic property.

p.ID = [1 2]
p = 

 2x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2]
              Y: [10 10]
    FeatureName: {'Feature 1' 'Feature 2'}
             ID: [1 2]

Add a third feature. All properties are autosized so that all vector lengths match.

p(3).X = 3
p(3).Y = 10
p = 

 3x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2 3]
              Y: [10 10 10]
    FeatureName: {'Feature 1' 'Feature 2' ''}
             ID: [1 2 0]

Set the values for the ID feature dynamic property with more values than contained in X or Y. All properties are expanded to match in size.

p.ID = 1:4
p = 

 4x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2 3 0]
              Y: [10 10 10 0]
    FeatureName: {'Feature 1' 'Feature 2' '' ''}
             ID: [1 2 3 4]

Set the values for the ID feature dynamic property with less values than contained in X or Y. The ID property values expand to match the length of X and Y.

p.ID = 1:2
p = 

 4x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2 3 0]
              Y: [10 10 10 0]
    FeatureName: {'Feature 1' 'Feature 2' '' ''}
             ID: [1 2 0 0]

Set the values of either coordinate property (X or Y) with fewer values. All properties shrink in size to match the new length.

p.X = 1:2
p = 

 2x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1 2]
              Y: [10 10]
    FeatureName: {'Feature 1' 'Feature 2'}
             ID: [1 2]

Remove the FeatureName (or ID) property by setting its value to [ ].

p.FeatureName = []
p = 

 2x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1 2]
           Y: [10 10]
          ID: [1 2]

Remove all dynamic properties and set the object to empty by setting a coordinate property value to [ ].

p.X = []
 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: []
           Y: []
point = mappoint([42 44], [10, 11], 'Temperature', [63 65])
point = 

 2x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [42 44]
              Y: [10 11]
    Temperature: [63 65]

Load data from the seamount MAT-file and construct a mappoint vector to hold the coordinates.

seamount = load('seamount');
p = mappoint(seamount.x, seamount.y, 'Z', seamount.z);

Create a level list to use to bin the z values and create a list of color values for each level.

levels = [unique(floor(seamount.z/1000)) * 1000; 0];
colors = {'red', 'green', 'blue', 'cyan', 'black'};

Add a MinLevel and MaxLevel feature property to indicate the lowest and highest binned level. Add a dynamic feature property to indicate the Z coordinate. Add a dynamic feature property to indicate a binned level value and a color value for a given level. Include metadata information from the MAT-file.

for k = 1:length(levels) - 1
   index = levels(k) <= p.Z & p.Z < levels(k+1);
   p(index).MinLevel = levels(k);
   p(index).MaxLevel = levels(k+1) - 1;
   p(index).Color = colors{k};
end

Add metadata information. Metadata is a scalar structure containing information for the entire set of properties. Any type of data may be added to the structure.

p.Metadata.Caption = seamount.caption;
p.Metadata
ans = 

    Caption: [1x229 char]

Display the point data as a 2-D plot.

figure
minLevels = unique(p.MinLevel);
for k=1:length(minLevels)
  index = p.MinLevel == minLevels(k);
  mapshow(p(index).X, p(index).Y, ...
   'MarkerEdgeColor', p(find(index,1)).Color, ...
   'Marker', 'o', ...
   'DisplayType', 'point')
end
legend(num2str(minLevels'))

Display the point data as a 3-D scatter plot.

figure
scatter3(p.X, p.Y, p.Z)

structArray = shaperead('boston_placenames');
p = mappoint();
p.X = [structArray.X];
p.Y = [structArray.Y];
p.Name = {structArray.NAME}
p = 

 13x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1x13 double]
           Y: [1x13 double]
        Name: {1x13 cell}

Construct a mappoint vector from a structure array using the constructor syntax.

filename = 'boston_placenames.shp';
structArray = shaperead(filename);
p = mappoint(structArray)
p = 

 13x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1x13 double]
           Y: [1x13 double]
        NAME: {1x13 cell}
     FEATURE: {1x13 cell}
       COORD: {1x13 cell}

Add a Filename field to the Metadata structure. Display the first five points and the Metadata structure.

p.Metadata.Filename = filename;
p(1:5)
p.Metadata
ans = 

 5x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [2.3403e+05 2.3357e+05 2.3574e+05 2.3627e+05 2.3574e+05]
           Y: [900038 9.0019e+05 9.0113e+05 9.0097e+05 9.0036e+05]
        NAME: {1x5 cell}
     FEATURE: {'PPL-SUBDVSN' ' MARSH' ' HILL' ' PPL' ' PENINSULA'}
       COORD: {1x5 cell}

ans = 

    Filename: 'boston_placenames.shp'

Append Paderborn Germany to the vector of world cities.

p = mappoint(shaperead('worldcities.shp'));
x = 51.715254;
y = 8.75213;
p = append(p, x, y, 'Name', 'Paderborn');
p(end)
ans = 

 1x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: 51.7153
           Y: 8.7521
        Name: 'Paderborn'

You can also add a point to the end of the vector using linear indexing. Add Arlington, Virginia to the end of the vector.

p(end+1).X = 38.880043;
p(end).Y = -77.196676;
p(end).Name = 'Arlington';
p(end-1:end)
ans = 

 2x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [51.7153 38.8800]
           Y: [8.7521 -77.1967]
        Name: {'Paderborn' 'Arlington'}

% Plot the points
figure
mapshow(p.X, p.Y, 'DisplayType', 'point')

Construct a mappoint vector and sort the dynamic properties.

p = mappoint(shaperead('tsunamis'));
p = p(:, sort(fieldnames(p)))
p = 

 162x1 mappoint vector with properties:

 Collection properties:
       Geometry: 'point'
       Metadata: [1x1 struct]
 Feature properties:
              X: [1x162 double]
              Y: [1x162 double]
          Cause: {1x162 cell}
     Cause_Code: [1x162 double]
        Country: {1x162 cell}
            Day: [1x162 double]
    Desc_Deaths: [1x162 double]
         Eq_Mag: [1x162 double]
           Hour: [1x162 double]
       Iida_Mag: [1x162 double]
      Intensity: [1x162 double]
       Location: {1x162 cell}
     Max_Height: [1x162 double]
         Minute: [1x162 double]
          Month: [1x162 double]
     Num_Deaths: [1x162 double]
         Second: [1x162 double]
       Val_Code: [1x162 double]
       Validity: {1x162 cell}
           Year: [1x162 double]

Modify the mappoint vector to contain only the dynamic properties, 'Year', 'Month', 'Day', 'Hour', 'Minute'.

p = p(:, {'Year', 'Month', 'Day', 'Hour', 'Minute'})
p = 

 162x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1x162 double]
           Y: [1x162 double]
        Year: [1x162 double]
       Month: [1x162 double]
         Day: [1x162 double]
        Hour: [1x162 double]
      Minute: [1x162 double]

Display the first 5 elements.

p(1:5)
ans = 

 5x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [128.3000 -156 157.9500 143.8500 -155]
           Y: [-3.8000 19.5000 -9.0200 42.1500 19.1000]
        Year: [1950 1951 1951 1952 1952]
       Month: [10 8 12 3 3]
         Day: [8 21 22 4 17]
        Hour: [3 10 NaN 1 3]
      Minute: [23 57 NaN 22 58]

Input argument x and y values can be either Nx2 or 2xM arrays.

If you typically store x and y coordinate values in a N-by-2 or 2-by-M array, you can assign a mappoint object to these numeric values. If the values are stored in a N-by-2 array, then the X property values are assigned to the first column and the Y property values are assigned to the second column.

x = 1:10;
y = 21:30;
pts = [x' y'];
p = mappoint;
p(1:length(pts)) = pts
p = 

 10x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1 2 3 4 5 6 7 8 9 10]
           Y: [21 22 23 24 25 26 27 28 29 30]

If the values are stored in a 2-by-M array, then the X property values are assigned to the first row and the Y property values are assigned to the second row. pts = [x; y];

pts = [x; y];
p(1:length(pts)) = pts
p = 

 10x1 mappoint vector with properties:

 Collection properties:
    Geometry: 'point'
    Metadata: [1x1 struct]
 Feature properties:
           X: [1 2 3 4 5 6 7 8 9 10]
           Y: [21 22 23 24 25 26 27 28 29 30]
Was this topic helpful?