How can I get latitude and longitude range for each US state in MATLAB?

Hello all.
I aim to draw contour lines showing a specific parameter in each state. For this, I need to create mesh across each state which requires knowing the bounding box (or latitude and longitude ranges for that state). Can anyone guide me how I can do it?

 Respuesta aceptada

With:
states = shaperead('usastatelo');
one for example gets 'BoundingBox', 'X', 'Y' among others for each US state
states(ismember ({states.Name}, 'Ohio')).BoundingBox;
and you can contine from there, tho using mapshow might be easier depending on what you need to do/plot
maxpar = 20;
for is = 1:numel(states), states(is).parameter = randi(maxpar,1); end
surfaceColors = makesymbolspec('Polygon', {'parameter', [1 maxpar], 'FaceColor', jet(numel(states))});
mapshow(states,'DisplayType', 'polygon', 'SymbolSpec', surfaceColors);

3 comentarios

clc
close all
clear all
A=shaperead("tl_2017_27_place.shp");
B={A.BoundingBox};
D=zeros(size(B,2),4);
for i=1:size(B,2)
D(i,:)=[B{i}(:,1)',B{i}(:,2)'];
end
min_lon=min(D(:,1));
max_lon=max(D(:,2));
min_lat=min(D(:,3));
max_lat=max(D(:,4));
thanks for your answer. I think if we can find the state boundry shape file, using the code above we can easily find the bounding box for that state
Sure, it seems you have your own shapes to read, then I'm not sure what they are. So I am not sure either about the 2nd part of the code above, not sure what the loop and min max are to archieve, just this might give the same result (it's already a bounding box):
states = shaperead('usastatelo');
D = states(ismember ({states.Name}, 'Ohio')).BoundingBox
Also look up readgeotable and geoshow if your shapes are in lat/longitude and to plot on a map instead. Also consider accepting the answer if that's what you were looking for or if it helped.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 4 de Abr. de 2023

Comentada:

el 6 de Abr. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by