From: Tianchan on
Hi there,

I have a pair of Lon and Lat and I would like to know which state it belongs to on a certain map, for example, USA map. Therefore, the return value should be a state name. How can I achieve this? Can anyone help?

Thank you,
Tianchan
From: Rob Comer on
> I have a pair of Lon and Lat and I would like to know which state it belongs to on a certain map, for example, USA map. Therefore, the return value should be a state name. How can I achieve this? Can anyone help?

If your state outlines are represented appropriately -- longitudes and latitude (or x and y) vectors for vertex coordinates with multiple parts (e.g., upper and lower peninsulas of Michigan) separated by NaN -- you can iterate over all the states and make a call to the MATLAB inpolygon function for each state. And if you actually have many point locations to test, rather than just one, you can pass them as a single vector to inpolygon. So there's no need to iterate over point locations, just states. Presumably you have a list of names to match your state outline polygons (perhaps they are already in a Mapping Toolbox mapstruct or geostruct); it seems like getting the names should be the easy part.

Rob Comer
Mapping Toolbox Development
MathWorks