Create Map Displays with Geographic Data - MATLAB & Simulink Example - MathWorks Australia (2024)

Open Live Script

There are many geospatial data sets that contain data with coordinates in latitude and longitude in units of degrees. This example illustrates how to import geographic data with coordinates in latitude and longitude, display geographic data in a map display, and customize the display.

In particular, this example illustrates how to

  • Import specific geographic vector and raster data sets

  • Create map displays and visualize the data

  • Display multiple data sets in a single map display

  • Customize a map display with a scale ruler and north arrow

  • Customize a map display with an inset map

Example 1: Import Polygon Geographic Vector Data

Geographic vector data can be stored in a variety of different formats, for example shapefile and GPS Exchange (GPX) formats. This example imports polygon geographic vector data from a shapefile. Vertices in a shapefile can be either in geographic coordinates (latitude and longitude) or in a projected coordinate reference system.

Read USA state boundaries from the usastatehi.shp file included with the Mapping Toolbox™ software. The state boundaries are in latitude and longitude.

states = shaperead('usastatehi.shp','UseGeoCoords',true);

Example 2: Display Polygon Geographic Vector Data

Display the polygon geographic vector data onto an axesm-based map (previously referred to as map axes). Since the geographic extent is in the United States, you can use usamap to set up the map. Use geoshow to project and display the geographic data onto the map. Display an ocean color in the background by setting the frame's face color.

figureax = usamap('conus');oceanColor = [0.3010 0.7450 0.9330];landColor = [0.9290 0.6940 0.1250];setm(ax,'FFaceColor',oceanColor)geoshow(states,'FaceColor',landColor)title({'Conterminous USA State Boundaries', ... 'Polygon Geographic Vector Data'})

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (1)

Example 3: Import Point and Line Geographic Vector Data

Import point geographic vector data from the boston_placenames.gpx file included with the Mapping Toolbox™ software. The file contains latitude and longitude coordinates of geographic point features in part of Boston, Massachusetts, USA. Use the readgeotable function to read the GPX file and return a geospatial table with one row for each point and its attributes.

placenames = readgeotable('boston_placenames.gpx');

Import line vector data from the sample_route.gpx file included with the Mapping Toolbox™ software. The file contains latitude and longitude coordinates for a GPS route from Boston Logan International Airport to The MathWorks, Inc in Natick Massachusetts, USA. Use the readgeotable function to read the GPX file and return a geospatial table contains each point along the route.

route = readgeotable('sample_route.gpx');

Example 4: Display Point and Line Geographic Vector Data

Display the geographic vector data in an axesm-based map centered around the state of Massachusetts, using the data from the state boundaries and the GPX files. The coordinates for all of these data sets are in latitude and longitude.

Find the state boundary for Massachusetts.

stateName = 'Massachusetts';ma = states(strcmp({states.Name},stateName));

Use usamap to setup a map for the region surrounding Massachusetts. Color the ocean by setting the frame's face color. Display the state boundaries and highlight Massachusetts by using geoshow to display the geographic data onto the map. Since the GPX route is a set of points stored in a geopointshape vector, supply the latitude and longitude coordinates to geoshow to display the route as a line.

figureax = usamap('ma');maColor = [0.4660 0.6740 0.1880];setm(ax,'FFaceColor',oceanColor)geoshow(states,'FaceColor',landColor)geoshow(ma,'FaceColor',maColor)geoshow(placenames);geoshow(route.Shape.Latitude,route.Shape.Longitude);title({'Massachusetts and Surrounding Region','Placenames and Route'})

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (2)

Example 5: Set Latitude and Longitude Limits Based on Data Extent

Zoom into the map by computing new latitude and longitude limits for the map using the extent of the placenames and route data. Extend the limits by 0.05 degrees.

lat = [route.Shape.Latitude; placenames.Shape.Latitude];lon = [route.Shape.Longitude; placenames.Shape.Longitude];[latlim,lonlim] = geoquadpt(lat,lon);[latlim,lonlim] = bufgeoquad(latlim,lonlim,0.05,0.05);

Construct an axesm-based map with the new limits and display the geographic data.

figureax = usamap(latlim,lonlim);setm(ax,'FFaceColor',oceanColor)geoshow(ma,'FaceColor',maColor)geoshow(placenames)geoshow(route.Shape.Latitude,route.Shape.Longitude)title('Closeup of Placenames and Route')

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (3)

Example 6: Import Geographic Raster Data

Geographic raster data can be stored in a variety of different formats, for example GeoTIFF, Esri Grid, DTED, and ENVI formats. To read data in these formats, use the readgeoraster function.

To read an image associated with a worldfile, use the imread and worldfileread functions instead. Use imread to read the image and worldfileread to read the worldfile and construct a spatial referencing object. For this example, import data for the region surrounding Boston, Massachusetts. The coordinates of the image are in latitude and longitude.

filename = 'boston_ovr.jpg';RGB = imread(filename);R = worldfileread(getworldfilename(filename),'geographic',size(RGB));

Example 7: Display Geographic Raster Data

Display the RGB image onto an axesm-based map. The limits of the map are set to the limits defined by the spatial referencing object, R. The coordinates of the data are in latitude and longitude.

figureax = usamap(RGB,R);setm(ax,'MLabelLocation',0.05,'PLabelLocation',0.05, ... 'MLabelRound',-2,'PLabelRound',-2)geoshow(RGB,R)title('Boston Overview')

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (4)

Example 8: Display Geographic Vector and Raster Data

You can display raster and vector data in a single map display. Since the coordinates for all of these data sets are in latitude and longitude, use geoshow to display them in a single map display. Setup new limits based on the limits of the route, placenames, and the overview image.

lat = [route.Shape.Latitude' placenames.Shape.Latitude' R.LatitudeLimits];lon = [route.Shape.Longitude' placenames.Shape.Longitude' R.LongitudeLimits];[latlim,lonlim] = geoquadpt(lat,lon);
figureax = usamap(latlim,lonlim);setm(ax,'GColor','k','PLabelLocation',0.05,'PLineLocation',0.05)geoshow(RGB,R)geoshow(ma.Lat,ma.Lon,'LineWidth',2,'Color','y')geoshow(placenames)geoshow(route.Shape.Latitude,route.Shape.Longitude)title('Boston Overview and Geographic Vector Data')

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (5)

Example 9: Customize a Map Display with a Scale Ruler

Customize a map display by including a scale ruler. A scale ruler is a graphic object that shows distances on the ground at the correct size for the projection. This example illustrates how to construct a scale ruler that displays horizontal distances in international miles.

Compute latitude and longitude limits of Massachusetts and extend the limits by 0.05 degrees by using the bufgeoquad function.

[latlim,lonlim] = geoquadline(ma.Lat,ma.Lon);[latlim,lonlim] = bufgeoquad(latlim,lonlim,0.05,0.05);

Display the state boundary, placenames, route, and overview image onto the map.

figureax = usamap(latlim,lonlim);setm(ax,'FFaceColor',oceanColor)geoshow(states,'FaceColor',landColor)geoshow(ma,'LineWidth',1.5,'FaceColor',maColor)geoshow(RGB,R)geoshow(placenames)geoshow(route.Shape.Latitude,route.Shape.Longitude)titleText = 'Massachusetts and Surrounding Region';title(titleText)

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (6)

Insert a scale ruler. You can determine a location for the scale ruler by using the ginput function as shown below:

[xLoc,yLoc] = ginput(1);

A location previously chosen is set below.

xLoc = -127800;yLoc = 5014700;scaleruler('Units','mi','RulerStyle','patches', ... 'XLoc',xLoc,'YLoc',yLoc);title({titleText,'with Scale Ruler'})

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (7)

Example 10: Customize a Map Display with a North Arrow

Customize the map by adding a north arrow. A north arrow is a graphic element pointing to the geographic North Pole.

Use latitude and longitude values to position the north arrow.

northArrowLat = 42.5;northArrowLon = -70.25;northarrow('Latitude',northArrowLat,'Longitude',northArrowLon);title({titleText,'with Scale Ruler and North Arrow'})

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (8)

Example 11: Customize a Map Display with an Inset Map

Customize the map by adding an inset map. An inset map is a small map within a larger map that enables you to visualize the larger geographic region of your main map. Create a map for the surrounding region as an inset map. Use the axes function to contain and position the inset map. In the inset map:

  • Display the state boundaries for the surrounding region

  • Plot a red box to show the extent of the main map

h2 = axes('Position',[0.15 0.6 0.2 0.2],'Visible','off');usamap({'PA','ME'})plabel offmlabel offsetm(h2,'FFaceColor','w')geoshow(states,'FaceColor',[0.9 0.9 0.9],'Parent',h2)plotm(latlim([1 2 2 1 1]),lonlim([2 2 1 1 2]), ... 'Color','red','LineWidth',2)title(ax,{titleText,'with Scale Ruler, North Arrow, and Inset Map'})

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (9)

Data Set Information

The file boston_placenames.gpx is from the Bureau of Geographic Information (MassGIS), Commonwealth of Massachusetts, Executive Office of Technology and Security Services. For more information about the data sets, use the command type boston_placenames_gpx.txt.

The file boston_ovr.jpg includes materials copyrighted by GeoEye, all rights reserved. GeoEye was merged into the DigitalGlobe corporation on January 29th, 2013. For more information about the data set, use the command type boston_ovr.txt.

See Also

usamap | geoshow | scaleruler | northarrow | geoplot | geoscatter

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Create Map Displays with Geographic Data- MATLAB & Simulink Example- MathWorks Australia (10)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Create Map Displays with Geographic Data
- MATLAB & Simulink Example
- MathWorks Australia (2024)
Top Articles
NBA 2K23 Badges: List of All Badges | 2K23 Badges - Outsider Gaming
All badges in NBA 2K23 - Full list
Funny Roblox Id Codes 2023
Www.mytotalrewards/Rtx
San Angelo, Texas: eine Oase für Kunstliebhaber
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Steamy Afternoon With Handsome Fernando
fltimes.com | Finger Lakes Times
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
978-0137606801
Nwi Arrests Lake County
Missed Connections Dayton Ohio
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
How to Create Your Very Own Crossword Puzzle
Apply for a credit card
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Dashboard Unt
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Receptionist Position Near Me
Gopher Carts Pensacola Beach
Duke University Transcript Request
Nikki Catsouras: The Tragic Story Behind The Face And Body Images
Kiddie Jungle Parma
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
The Latest: Trump addresses apparent assassination attempt on X
In Branch Chase Atm Near Me
Appleton Post Crescent Today's Obituaries
Craigslist Red Wing Mn
American Bully Xxl Black Panther
Ktbs Payroll Login
Jail View Sumter
Thotsbook Com
Funkin' on the Heights
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Marcel Boom X
Www Pig11 Net
Ty Glass Sentenced
Michaelangelo's Monkey Junction
Game Akin To Bingo Nyt
Ranking 134 college football teams after Week 1, from Georgia to Temple
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 5649

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.