Filling a shape with Geoplot
I am creating a polygon using coordinate points with geoplot, and I would like to fill the resultant shape in a partially transparent blue color. I am able to create the filled shape, and I can overlay the outline on the map with geoplot, but I cannot do both.
%% Plot
% Create a figure
figure;
% Create a geographic axes
gx = geoaxes;
hold(gx, ‘on’);
% Define the indices of visible points
visibleIndices = maxRadiusPerAngle > 0;
% Close the loop by adding the first point at the end
latTargetsClosed = [latTargets(visibleIndices) latTargets(visibleIndices(1))];
lonTargetsClosed = [lonTargets(visibleIndices) lonTargets(visibleIndices(1))];
% Plot the outline of the polygon using geoplot
geoplot(gx, latTargetsClosed, lonTargetsClosed, ‘b-‘, ‘LineWidth’, 2);
% Plot the central point
geoplot(gx, latCenter, lonCenter, ‘ro’, ‘MarkerSize’, 8, ‘MarkerFaceColor’, ‘r’);
% Plot the visible points
geoplot(gx, latTargets(visibleIndices), lonTargets(visibleIndices), ‘go’, ‘MarkerSize’, 6, ‘MarkerFaceColor’, ‘g’);
% Set the basemap
geobasemap(gx, ‘streets’);
title(‘Furthest Outward Points with Positive LOS’);
% Define the Web Mercator projection
projCRS = projcrs(3857); % EPSG:3857 Web Mercator
% Convert geographic coordinates to projected coordinates
[x, y] = projfwd(projCRS, latTargetsClosed, lonTargetsClosed);
% Create a new Cartesian plot for the filled polygon, ensuring it overlays the geographic axes
figure;
hold on;
% Create a filled polygon in the Cartesian plot
fill(x, y, ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’);
% Set Cartesian axes limits to match the geographic plot
axis equal;
xlabel(‘X (meters)’);
ylabel(‘Y (meters)’);
title(‘Filled Polygon in Projected Coordinates’);
% Adjust the limits to fit the geographic plot
latlim = gx.LatitudeLimits;
lonlim = gx.LongitudeLimits;
[xlim, ylim] = projfwd(projCRS, [latlim(1), latlim(2)], [lonlim(1), lonlim(2)]);
set(gca, ‘XLim’, xlim, ‘YLim’, ylim);
% Ensure the Cartesian plot is visible
set(gcf, ‘Visible’, ‘on’);I am creating a polygon using coordinate points with geoplot, and I would like to fill the resultant shape in a partially transparent blue color. I am able to create the filled shape, and I can overlay the outline on the map with geoplot, but I cannot do both.
%% Plot
% Create a figure
figure;
% Create a geographic axes
gx = geoaxes;
hold(gx, ‘on’);
% Define the indices of visible points
visibleIndices = maxRadiusPerAngle > 0;
% Close the loop by adding the first point at the end
latTargetsClosed = [latTargets(visibleIndices) latTargets(visibleIndices(1))];
lonTargetsClosed = [lonTargets(visibleIndices) lonTargets(visibleIndices(1))];
% Plot the outline of the polygon using geoplot
geoplot(gx, latTargetsClosed, lonTargetsClosed, ‘b-‘, ‘LineWidth’, 2);
% Plot the central point
geoplot(gx, latCenter, lonCenter, ‘ro’, ‘MarkerSize’, 8, ‘MarkerFaceColor’, ‘r’);
% Plot the visible points
geoplot(gx, latTargets(visibleIndices), lonTargets(visibleIndices), ‘go’, ‘MarkerSize’, 6, ‘MarkerFaceColor’, ‘g’);
% Set the basemap
geobasemap(gx, ‘streets’);
title(‘Furthest Outward Points with Positive LOS’);
% Define the Web Mercator projection
projCRS = projcrs(3857); % EPSG:3857 Web Mercator
% Convert geographic coordinates to projected coordinates
[x, y] = projfwd(projCRS, latTargetsClosed, lonTargetsClosed);
% Create a new Cartesian plot for the filled polygon, ensuring it overlays the geographic axes
figure;
hold on;
% Create a filled polygon in the Cartesian plot
fill(x, y, ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’);
% Set Cartesian axes limits to match the geographic plot
axis equal;
xlabel(‘X (meters)’);
ylabel(‘Y (meters)’);
title(‘Filled Polygon in Projected Coordinates’);
% Adjust the limits to fit the geographic plot
latlim = gx.LatitudeLimits;
lonlim = gx.LongitudeLimits;
[xlim, ylim] = projfwd(projCRS, [latlim(1), latlim(2)], [lonlim(1), lonlim(2)]);
set(gca, ‘XLim’, xlim, ‘YLim’, ylim);
% Ensure the Cartesian plot is visible
set(gcf, ‘Visible’, ‘on’); I am creating a polygon using coordinate points with geoplot, and I would like to fill the resultant shape in a partially transparent blue color. I am able to create the filled shape, and I can overlay the outline on the map with geoplot, but I cannot do both.
%% Plot
% Create a figure
figure;
% Create a geographic axes
gx = geoaxes;
hold(gx, ‘on’);
% Define the indices of visible points
visibleIndices = maxRadiusPerAngle > 0;
% Close the loop by adding the first point at the end
latTargetsClosed = [latTargets(visibleIndices) latTargets(visibleIndices(1))];
lonTargetsClosed = [lonTargets(visibleIndices) lonTargets(visibleIndices(1))];
% Plot the outline of the polygon using geoplot
geoplot(gx, latTargetsClosed, lonTargetsClosed, ‘b-‘, ‘LineWidth’, 2);
% Plot the central point
geoplot(gx, latCenter, lonCenter, ‘ro’, ‘MarkerSize’, 8, ‘MarkerFaceColor’, ‘r’);
% Plot the visible points
geoplot(gx, latTargets(visibleIndices), lonTargets(visibleIndices), ‘go’, ‘MarkerSize’, 6, ‘MarkerFaceColor’, ‘g’);
% Set the basemap
geobasemap(gx, ‘streets’);
title(‘Furthest Outward Points with Positive LOS’);
% Define the Web Mercator projection
projCRS = projcrs(3857); % EPSG:3857 Web Mercator
% Convert geographic coordinates to projected coordinates
[x, y] = projfwd(projCRS, latTargetsClosed, lonTargetsClosed);
% Create a new Cartesian plot for the filled polygon, ensuring it overlays the geographic axes
figure;
hold on;
% Create a filled polygon in the Cartesian plot
fill(x, y, ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’);
% Set Cartesian axes limits to match the geographic plot
axis equal;
xlabel(‘X (meters)’);
ylabel(‘Y (meters)’);
title(‘Filled Polygon in Projected Coordinates’);
% Adjust the limits to fit the geographic plot
latlim = gx.LatitudeLimits;
lonlim = gx.LongitudeLimits;
[xlim, ylim] = projfwd(projCRS, [latlim(1), latlim(2)], [lonlim(1), lonlim(2)]);
set(gca, ‘XLim’, xlim, ‘YLim’, ylim);
% Ensure the Cartesian plot is visible
set(gcf, ‘Visible’, ‘on’); geoplot, mapping toolbox MATLAB Answers — New Questions