Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPS Region Selection within Matlab

Tags:

gps

matlab

I have a large set of GPS locations, however I am only interested in obtaining those GPS locations that fall within a specific region, for this example let's say England.

I currently approach the problem using Google API (with usage limits):

longitude = 2.2333;
latitude = 53.4667;
%Generate the string to Pass over to Google
url = sprintf('https://maps.googleapis.com/maps/api/geocode/xml?latlng=%.4f,%.4f&sensor=true', latitude, longitude);

Google returns an XML structure that is stored in a "buffer"

buffer = urlread(url);

With this information, I perform a search to identify if the XML file provides any mention of England.

%Obtain the formatted address
results = regexp(buffer, '<formatted_address>(.*?)<', 'tokens') ;
%Search and store any mention of 'England'
resOut = [];
for k = 1 : length(results)
    resOut = [resOut,strfind(results{k}{1}, 'England')];
end

Question: Is there a "cleaner" more efficient way of identifying GPS locations within a specific region?

like image 934
Dan Avatar asked Feb 18 '26 20:02

Dan


1 Answers

Do you have the mapping toolbox?

If yes it's pretty straightforward: you need a shape file for England, which you can get here. In my case, I downloaded Countries_(GB)_2014_Boundaries_(Full_Extent).

Unzip and change directory to the unzipped folder in Matlab.

Then you can simply do

e = shaperead('CTRY_DEC_2014_GB_BFE.shp');
x = e(1).X;
y = e(1).Y;
plot(x, y);

to get

enter image description here

Obviously, the coordinates are not gps coordinates, but there should be an easy transformation, maybe you are more of a map expert than I am. For example, you could use the westernmost/easternmost and southernmost/northernmost points of England. Once you've transformed you give your query points and use inpolygon() to check whether you are in England or not.

x_query = 51;  %Query coordinates
y_query = 0;

is_included = inpolygon(x_query, y_query, x, y);

Note: There are maps (I checked one for Germany for example), which give you the coordinates in degrees, so you wouldn't need to transform. Maybe you can find one of those for England too.

like image 80
lhcgeneva Avatar answered Feb 20 '26 22:02

lhcgeneva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!