Identify data points at a shortest distance from the coast

19 views (last 30 days)
Hello:
I want to identify the city locations that are located within 100 km distance from the coast line. I have tried the following code: https://stackoverflow.com/questions/3576169/determine-distance-from-coastline-in-matlab
But it still unable to identify the points that are within nearest location from the coast. Can any one help me to identify cities that are located at the closest proximity to coast line?

Answers (1)

Gayatri Rathod
Gayatri Rathod on 27 Apr 2023
Hi Poulomi,
To identify cities that are located within 100 km distance from the coastline in MATLAB, you can follow these steps:
  • Obtain a shapefile of the coastline for the region you are interested in. Obtain a list of city locations with their coordinates. You can find such files from various sources such as OpenStreetMap, Natural Earth and GeoNames.
  • Load both the coastline and city data into MATLAB using the shaperead function to read the shapefile.
% Load coastline and city data
coastline = shaperead('coastline.shp');
cities = shaperead('cities.shp');
  • Use the distance function in MATLAB’s Mapping Toolbox to calculate the distance between each city location and the coastline.
% Create a geographic point for each city
city_points = geopoint(latitude, longitude); %pass latitude and longitude of cities appropriately.
% Calculate the distance between each city and the coastline
distances = distance (coastline.Lat, coastline.Lon, city_points.Latitude, city_points.Longitude);
  • Create a logical index of cities that are within 100 km distance from the coastline by checking if the distance between each city and the coastline is less than or equal to 100 km.
  • Use the logical index to select the cities that are within 100 km distance from the coastline.
  • In this example, the coastline.shp and cities.shp files represent the coastline and city data, respectively. The geopoint function is used to create a geographic point for each city location. The distance function is used to calculate the distance between each city location and the coastline.
You can read more about the shaperead , geopoint and distance functions from the following documentations: shaperead function , geopoint function, distance function.
Hope it helps!

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!