フィルターのクリア

Generating 50 Random locations inside geo map data

4 ビュー (過去 30 日間)
matthew
matthew 2014 年 5 月 17 日
回答済み: Kelly Kearney 2017 年 5 月 26 日
I have a function called map() which takes a string input and uses it to generate a particulare map
function map(Name)
worldmap({Name})
land = shaperead('landareas.shp', 'UseGeoCoords', true);
geoshow(land, 'FaceColor', [0.15 0.5 0.15])
what I would like to do is randomly generate from a seed 50 locations and place them on land or within the regions border,
such as i run map('Australia') and i get 50 randomly generated locations in australia.
  1 件のコメント
Omar Elsayed
Omar Elsayed 2017 年 5 月 26 日
Can you please elaborate on what exactly you want your code to do? How big do the locations have to be, Points or Regions ?

サインインしてコメントする。

回答 (1 件)

Kelly Kearney
Kelly Kearney 2017 年 5 月 26 日
Do you want the points to be specifically located in the named land mass? Or anywhere on land within the designated map limits? For example, the map limits for Australia also include bits on Indonesia and New Zealand.
If you're okay with any land mass, then the easiest way to do this would be to generate some points, test whether they're within the land polygons ( inpolygon ), and keep only those that are. Repeat until you get enough points.
Name = 'Australia';
h = worldmap({Name});
land = shaperead('landareas.shp', 'UseGeoCoords', true);
geoshow(land, 'FaceColor', [0.15 0.5 0.15])
latlim = getm(h, 'MapLatLimit');
lonlim = getm(h, 'MapLonLimit');
npt = 50;
nin = 0;
x = [];
y = [];
while nin < npt
xtmp = rand(npt,1)*diff(lonlim) + lonlim(1);
ytmp = rand(npt,1)*diff(latlim) + latlim(1);
isin = inpolygon(xtmp,ytmp, [land.Lon], [land.Lat]);
x = [x; xtmp(isin)];
y = [y; ytmp(isin)];
nin = length(x);
end
x = x(1:npt); % get rid of extra
y = y(1:npt);
plotm(y,x,'yo');
If you want to restrict the points to a specific land mass, then you'll need to filter out the correct polygons first. Using the Name property would be the easiest way to do this, but that only works for worldmap areas that share a name with the landareas.shp polygons. So Name = 'Australia' would be easy to do... for something like Name = 'Europe', you'd have to crop the 'Africa and Eurasia' polygon to your map limits before running the inpolygon test.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by