"

6 Exploring Vector Data

(Note: A video tutorial is available at the end of this chapter.)

Before we go too far, it’s important to understand the difference between the two basic types of data we can access, and create in a Geographic Information System (GIS).  GEE is one tool in the GIS world that allows us to view, and analyze, these two types of data.  This data is housed within the Earth Engine Catalog.

Vector data makes up subjects that can be described as points, lines, and polygons.  For example, a dataset of fire hydrants within a municipality would best be described as points within a map. The centerline of a road would best be described as a series of lines.  Polygons have multiple vertices, so they can be used to describe an area.  For example, the area a park encompasses would best be described as a polygon.  Vector data also contains attributes.  This could be such information as the name of the park or the last date a fire hydrant was tested.  We can display these attributes by applying different symbols and colors.  This is referred to as symbology. Symbology allows us to see through large amounts of data to help in decision making.  It is one of GIS’s super powers! The chapters in this section will help you understand how to access data and also symbolize it in the GEE API.

If you’re familiar with any of the ESRI products, you’re likely aware of how a catalog works.  If you’re unfamiliar with this, do not be dismayed.  There are many types of data that are available to use within GEE.  There are assets, which are data that you have added from your own sources and collections found within the data catalog.  We’ll discuss assets later so as not to add greater confusion.  Believe it or not you’ve already used the data catalog!  Recall in the previous section, where we found the center of Austria, we used this function:

Example 2.1

  1. var austria = ee.FeatureCollection(‘USDOS/LSIB_SIMPLE/2017’)
  2. .filter(ee.Filter.eq(‘country_na’, ‘Austria’));

 

We’ve done a lot here in just a couple lines of text.  Focus! Concentrate! Don’t overcomplicate this.  All we are doing here is calling up the US Department of State (USDOS) Simple Country Boundaries from 2017.  It just happens to be found in the Data Catalog under USDOS/LSIB_SIMPLE/2017.  You’re probably wondering, how in the world did I know where to find that!  Remember, Sensei Jeff is all knowing in the ways of GEE.  I wish that was the case, but in fact, all I did was head over to Earth Engine’s Data Catalog and do a search for country boundaries.    Before moving on, complete the following:

Exercise 2.1

  1. Why, exactly, did we use this resource from the data catalog?
  2. Briefly explain what each of the following statements does:
    1. var austria
    2. =
    3. ee.FeatureCollection(‘’)

Go back and look at that last script.  I could, in fact, leave things here with just the first line (var austria = ee.FeatureCollection(‘USDOS/LSIB_SIMPLE/2017’)).  This would just load the entire collection of all the political boundaries of the countries of the world.  It would be a bit strange to call it a variable austria, since it represents all of the boundaries, but it would still work. It would probably be more suitable to call it a variable like all_countries.  If you’re feeling daring, go ahead and try to load the /USDOS/LSIB_SIMPLE/2017 data from the data catalog and call it a variable all_countries.  It should look something like this:

Example 2.2

  1. var all_countries = ee.FeatureCollection(‘/USDOS/LSIB_SIMPLE/2017’);

 

Go ahead and run it.  You forgot the semicolon, didn’t you?  Don’t worry, we all do it.  In fact, it most likely even ran for you.  But let’s not get sloppy.  We’re looking for quality here.  You’re probably wondering why you didn’t see any data.  Did you ask the computer to show you the data?  GEE enlightenment will only come when you realize you have to ask the computer to do things for you. So how do we display the data?  Recall the function Map.addLayer() from before.  Let’s use this to display the data:

Example 2.3

  1. var all_countries = ee.FeatureCollection(‘/USDOS/LSIB_SIMPLE/2017’);
  2. Map.addLayer(all_countries);

 

It probably took a moment, even for the supercomputer, to add this data.  A couple of rules to follow to greater GEE enlightenment:

  1. Only display data when you need to.
  2. Only display the data you need.

Don’t waste resources for a quick fix of visual gratification.  There are many people trying to use GEE and we want to be thoughtful in what we’re doing.  That doesn’t mean we can’t use Map.addLayer to learn or even debug a line of script.  Keeping in harmony with display on the data you need, how do we refine the data down to one area?  Remember, in spatial analyses, half of the task is just to narrow the data down to a specific area.  This helps with clarity. If I ask you to list all the species of trees in the world and assign a color to each one, you’d run out of colors quickly.  But if I asked you to list all the species within one square kilometer of Michigan, and assign each a color, you could do this and successfully be able to see them on a map.  Getting the bigger picture here?  Great.  Let’s take a close look at the second line of the original script:

  • .filter(ee.Filter.eq(‘country_na’, ‘Austria’));

Looks complicated doesn’t it?  Let’s break it down into its pieces:

  • filter(): tells the computer we don’t want to see everything.
  • ee.Filter.eq(): ee is from the Earth Engine library.  Filter.eq is a function from the Earth Engine library telling the computer to filter when equal to a user defined parameter.
  • ‘country_na’: tells the computer we want to filter using the country_na (country name) attribute, or field.  You can find the field by looking at the description for the dataset in the GEE data catalog.
  • ‘Austria’: is the name by which the country of Austria is called in the country_na field. Note that a common is required to separate the field and what we want it to be equal to.

Understanding how to reduce the data down to what you want to view is half the battle.  Look how we used Map.addLayer() in Example 2.3 to display the data.  Do you see how we had to place the variable all_countries in the brackets?  We did the same in Example 1.11, were we used Map.addLayer(point) for the point we created at the geographic center of Austria.  If you want to see the data on the map, you will use this function:

Example 2.4

  1. var austria = ee.FeatureCollection(‘USDOS/LSIB_SIMPLE/2017’)
  2. .filter(ee.Filter.eq(‘country_na’, ‘Austria’));
  3. Map.addLayer(austria);

 

Now that your GEE prowess has increased, perform the following actions:

Exercise 2.2

  1. Write a function that brings up the country of Chile and assign it to a variable SouthAmerica1
  2. Write a function that brings up the country of Egypt and assign it to a variable NorthAfrica1
  3. Display both of the countries as a layer

When you’re done here, head to the next chapter to learn about symbolizing the vector data.

Below is a video tutorial to help you work through this chapter.

License

Icon for the Creative Commons Attribution-NonCommercial 4.0 International License

Zen and the Art of Scripting in Google Earth Engine Copyright © by College of Southern Idaho is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License, except where otherwise noted.