How can I plot polygons with different colors using KMLWRITELINE in Mapping Toolbox 3.7 (R2013a)?

6 views (last 30 days)
I am using KMLWRITELINE to make KML files showing muliptle polygons. I separate those polygons using NaN values. However, all those polygons are the same color. Is there a way to make a KML with polygons of different colors?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Oct 2013
A simple solution is to create a geoshape object to hold your data and then specify a color for each segment with the existing KMLWRITELINE interface. You would use the function POLYSPLIT which returns the NaN-delimited segments of the input vectors.
Here is an example that shows how to do that:
>> lat = [1:3 NaN 4:6 NaN 7:9];
>> lon = [1:3 NaN 4:6 NaN 7:9];
>> [latcell, loncell] = polysplit(lat, lon);
>> S = geoshape(latcell, loncell); % Creates a geoshape with 3 features, one for each line segment
>> kmlwrite(filename, S, 'Color', {'r', 'g', 'b'})
or
kmlwrite(filename, S, 'Color', [1,0,0;0,1,0;0,0,1])
where 'filename' is the names of your KML file (e.g: 'myKMLfile.kml').
Additional information about the function POLYSPLIT can be found by executing the following at the MATLAB prompt:
>> doc polysplit

More Answers (0)

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!