Feature Request:Manually and interactively draw custom areas in geographic axes

4 Ansichten (letzte 30 Tage)
As far as I know, MATLAB or matlab mapping toolbox can draw geometries based on known static geographic data, such as geopointshape, geolineshape, mappointshape, maplineshape, mappolyshape objects, which were introduced in R2021b, but cannot draw geometries interactively by mouse and get some geometries. mappolyshape objects, which extend the freedom of drawing, but it is not possible to draw geometric shapes interactively with the mouse and to get some statistical information, such as the length and distance of line segments and the perimeter and area of polygonal areas.
Similarly,In the Image Processing Toolbox, R2018b already has interactive functions such as drawpoint, drawline, drawpolygon, etc., which are very convenient and easy to use, while the mapping toolbox is not so convenient. Therefore, I expect the future version to introduce similar interactive drawing functions for geographic image interactive processing statistics.
For example, I would like to interactively draw the area of the playground in the following image, so that I can easily count its area and perimeter.
lat = [22.6827 22.6873];
lon = [114.0641 114.0704];
geoplot(lat,lon)
geobasemap("satellite")
% Next, how do you draw the playground area interactively?
---------------------------------------------------Updating the dividing line-------------------------------------------
Note: I'd prefer to see an elegant way of using it, instead of the low-level, slightly tricky "dumb" .

Antworten (1)

Hassaan
Hassaan am 1 Jan. 2024
To interactively draw shapes and compute areas on a geographic map, you might need to use a combination of callbacks and custom functions.:
  1. Display a geographic map using functions like geobasemap.
  2. Use interactive functions to capture mouse clicks and draw polygons on the map.
  3. Calculate the area and perimeter of the drawn polygons using spatial or geographic functions that can handle the calculations on a curved surface like the Earth.
A rough example using pseudo-code would be:
% Display the map
lat = [22.6827 22.6873];
lon = [-114.0641 114.0704];
geoplot(lat, lon)
geobasemap('satellite')
% Set up a callback for mouse clicks on the map
set(gcf, 'WindowButtonDownFcn', @clickCallback);
% Function to handle mouse clicks and draw polygons
function clickCallback(src, event)
% Get the current point on the map
pt = src.CurrentPoint;
% You would need additional logic here to store points and create a polygon
% This is a placeholder for illustrative purposes
disp(pt);
% Once a polygon is created, calculate its area and perimeter
% You might need to convert lat/lon to a projected coordinate system first
% Calculate area and perimeter here
end
Keep in mind that to calculate the area and perimeter accurately on a geographic map, considering the Earth's curvature, you might need to use specific geospatial functions or convert latitude and longitude to a planar coordinate system before performing the calculations.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems
  • Electrical and Electronics Engineering
  2 Kommentare
cui,xingxing
cui,xingxing am 1 Jan. 2024
Thank you for your detailed answer, in a way, the method you described can indeed theoretically solve my problem interactively, the only extra work is to convert the 2D pixel coordinates of the mouse point to geographic coordinates, and then consider the influence of the Earth's arc to further calculate the total length of the curve or the area of the closed area.
Note that the src.CurrentPoint coordinates via the button down[1] callback function[2] are relative to the lower left corner of the figure as the origin, this is a little tricky to convert to GeographicAxes as the spacing between the axes and the figure will change as the figure window edge size changes.
However, the above is a "last resort" solution, and even built-in functions like inputm can be used to solve the problem of interactively selecting geographic coordinates until an advanced interactive function like drawPolygon is formally introduced in the future.
In any case, I'd prefer to see an elegant way of using it, instead of the low-level, slightly tricky "dumb" way.Obviously, the official functions for drawing interactions with geographic maps are not up-to-date, and are rather scarce, basically staying at the pre-R2006a functions.
Again, thanks for your answer and the sample code.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by