Clear Filters
Clear Filters

How can I reduce the size of polygon map from shapefile by some distance?

33 views (last 30 days)
Hello All,
I have a shape file from which i have Latitude and Logitude cordinates. In that map when I plot those cordinates using geoplot fuction.
I will put those cordinates here.
Longitude = [49.5307463706278 49.5307171760463 49.5304661019256 49.5302325434462 49.5299639498154 49.5298413304932 49.5297537450748 49.5292048728798 49.5288953996699 49.5282664017587 49.5282706081627 49.5282881257904 49.5283290002306 49.5283406786358 49.5283173218226 49.5282589297407 49.5282122160250 49.5281187884596 49.5281021034227 49.5282355728884 49.5287727776674 49.5292574247397 49.5296778375853 49.5298588475581 49.5302967721393 49.5304369071767 49.5304592844042 49.5304661019256 49.5304894577121 49.5306003975459 49.5308748265792 49.5308748265792 49.5308105986457 49.5308105986457 49.5308047597385 49.5307463706278 NaN];
Latitude = [7.92334633371693 7.92333733369920 7.92310333323818 7.92292333288354 7.92268033240478 7.92250033205015 7.92222133150046 7.92228433162458 7.92229333164232 7.92213669574119 7.92203233112809 7.92188833084439 7.92170833048975 7.92139332986914 7.92114132937265 7.92089832889389 7.92058332827328 7.91965632644691 7.91927486806551 7.91927832570217 7.91931432577310 7.91932332579083 7.91928732571990 7.91925132564897 7.91922432559578 7.91918832552485 7.91918465813742 7.91925132564897 7.91944932603907 7.92009732731576 7.92196933100397 7.92224833155366 7.92313033329137 7.92331033364601 7.92334633371693 7.92334633371693 NaN];
geoplot(Longitude,Latitude, "b")
So now I looking to create a border around these map on the inside and outside of this boundry. Let say a boundry which is 10 meter apart from the main boundry.
Here is a example of how I want to do it.
If you see in the figure blue line is the actual boundry and red and black boundry is that I am trying to find a function for it.
Is there a way to do it ? I have tried similar methods but those where on the images which can reduce size but not sure how to do it in actual map.
Thankyou in advance.

Answers (1)

Shubham on 27 May 2024 at 8:16
Hi Jay,
Creating a boundary that is a certain distance away from a given path on a map involves a process known as buffering. Buffering generates a new set of points that are a specified distance away from the original points, effectively creating a "buffer" around the original path. In geographic coordinate systems, this process takes into account the curvature of the Earth, as distances between points are not linear like they are in Cartesian coordinates.
For your specific case with MATLAB, while there isn't a direct geobuffer function similar to the buffer function for Cartesian coordinates, you can achieve a similar effect by using geographic calculations. Here's a method to create a buffer around your path using geographic coordinates:
Step 1: Convert to Geographic Coordinates
Ensure your latitude and longitude coordinates are in a format that can be used for geographic calculations. Your coordinates are already in the correct format.
Step 2: Calculate Buffer Points
To calculate the buffer points, you can use the referenceEllipsoid object along with functions like geodetic2enu and enu2geodetic to convert between geodetic and local east-north-up (ENU) coordinates. This allows you to perform the buffer calculation in a planar space that more closely approximates the Earth's surface locally.
Here's a conceptual approach:
  1. Set Up Reference Ellipsoid: This represents the Earth's shape and size.
ellipsoid = referenceEllipsoid('wgs84');
2. Calculate Buffer in ENU Coordinates:
For each point along your path, convert it to ENU coordinates, calculate the buffer points in ENU space, and then convert those points back to geodetic coordinates. This involves iterating over your path, applying an offset in the easting and northing directions, and then converting back.
Here's a simplified example for one point (this needs to be done in a loop for all points):
% Example for one point
lat0 = Latitude(1); % Reference latitude
lon0 = Longitude(1); % Reference longitude
h0 = 0; % Assuming sea level for simplicity
% Convert to ENU
[e, n, u] = geodetic2enu(Latitude, Longitude, zeros(size(Latitude)), lat0, lon0, h0, ellipsoid);
% Apply buffer (e.g., 10 meters)
e_buffered = e + 10; % Example of adding 10 meters to the easting
n_buffered = n + 10; % Example of adding 10 meters to the northing
% Convert back to geodetic
[latBuffered, lonBuffered] = enu2geodetic(e_buffered, n_buffered, u, lat0, lon0, h0, ellipsoid);
Step 3: Plotting the Buffer
After calculating the buffered points, you can plot them similarly to how you plotted the original path:
geoplot(latBuffered, lonBuffered, 'r'); % For the buffered path
hold on;
geoplot(Latitude, Longitude, 'b'); % Original path
  • Accuracy: This approach simplifies the problem by treating the buffer as a constant offset in the ENU coordinate system. For small distances (like 10 meters), this approximation is usually acceptable, but accuracy decreases with larger distances or near the poles.
  • Path Complexity: For complex paths, especially those that cross themselves or have sharp turns, a more sophisticated approach might be needed to ensure the buffer does not overlap itself inappropriately.
  • Looping Through Points: The example provided focuses on a single point for clarity. In practice, you would loop through your coordinates, applying the buffering process to each point. Additionally, you might need to generate points along the path between your original points to ensure the buffered path maintains a consistent distance from the original path.
This method requires a bit of manual work and understanding of geographic coordinate systems, but it's a robust way to create a buffered path for geographic data in MATLAB.
  1 Comment
Jay on 30 May 2024 at 8:35
Hello Shubham,
Thankyou for your answer.
Your answer was effective in way to create a boundry. As you said if we want to do this method for whole set of boundry points it needs to loop through all points. If the number of points are large then it would take much more manual work and time.
So in those number of points I cant diffrenciate which points are near corners such those points will need to reduce distance in one direction whicle add in another direction to make that point inside of the boundry.
As of now I have two methods which I have used. These methods are not as accurate as your method but this takes much less time.
  • In this method I used a polybuffer function. Here I reduced the buffer boundry by an average of 1m change in both direction.
long1m = 0.0000138139; % change in longitude degeree for 1 m.
lat1m = 0.0000089912; % chnage in latitude degeree for 1 m.
dist = 10; % gap between inner boundry and actual boundry.
polygon1 = polyshape([Longitude; Latitude]');
innerPolygon1 = polybuffer(polygon1, -((long1m + lat1m)/2)*(dist),'JointType','miter');
% Results generated using above function does not create a complete boundry
% innerPolygon1.Vertices = [innerPolygon1.Vertices(1:end,:);innerPolygon1.Vertices(end,:)];
% So here i am rearranginf those points to produce complete boundry.
InnerField = [innerPolygon1.Vertices(8:end,:);innerPolygon1.Vertices(1:8,:)];
  • In this method insead of using polybuffer function i used bufferm function. Here also I reduced the buffer boundry by an average of 1m change in both direction.
[innerLatitude, innerLongitude] = bufferm(Latitude, Longitude, ((long1m + lat1m)/2)*(dist), 'in');
These above two methods are not accurate enough but they produced a a quick result. In above metioned methods the results were close enough but not same.
I was looking for a method where I do not have to put an average of distance but rather a single distance which can produce accurate results.

Sign in to comment.


Find more on Geographic Plots in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!