colab Open in SageMaker Studio Lab Open in Planetary Computer

Creating Points From Queries

Tutorial created by **David Montero Loaiza**: GitHub | Twitter

Let’s start!

If required, please uncomment:

[1]:
#!pip install eemont
#!pip install geemap

Import the required packages.

[2]:
import ee, eemont, geemap

Authenticate and Initialize Earth Engine and geemap.

[3]:
Map = geemap.Map()

Creating a Single Point (ee.Geometry)

A query is a string representing a place that is geocoded in order to get its coordinates.

[4]:
query = 'Santa Marta, Magdalena, Colombia'

In eemont, a point can be constructed from a query using the geopy package.

NOTE: Neither eemont nor geopy are geocoding services.

An ee.Geometry.Point can be constructed using the ee.Geometry.PointFromQuery constructor (extended through eemont):

[5]:
pointFromQuery = ee.Geometry.PointFromQuery(query,user_agent = 'eemont-tutorial-010')

The user_agent argument must be specified: This is a string describing the name of the app that is using a geocoding service (you can use here your GEE username).

Let’s visualize our point (color blue):

[6]:
Map.addLayer(pointFromQuery,{'color':'blue'},'Nominatim')
Map.centerObject(pointFromQuery,10)
Map

By default, the geocoding service used is nominatim (Open Street Maps). But it can be modified using the geocoder parameter (let’s use the arcgis geocoding service):

[7]:
pointFromQuery = ee.Geometry.PointFromQuery(query,geocoder = 'arcgis',user_agent = 'eemont-tutorial-010')

Let’s visualize our point (color red):

[8]:
Map.addLayer(pointFromQuery,{'color':'red'},'Arcgis')
Map.centerObject(pointFromQuery,10)
Map

As you can see, different geocoding services may give different results.

Creating a Single Point with Properties (ee.Feature)

A feature can also be created using the ee.Feature.PointFromQuery constructor (extended through eemont):

[9]:
featureFromQuery = ee.Feature.PointFromQuery(query,user_agent = 'eemont-tutorial-010')

Let’s explore the feature:

[10]:
featureFromQuery.getInfo()
[10]:
{'type': 'Feature',
 'geometry': {'type': 'Point', 'coordinates': [-74.2046826, 11.2430534]},
 'properties': {'boundingbox': ['11.0830534',
   '11.4030534',
   '-74.3646826',
   '-74.0446826'],
  'class': 'place',
  'display_name': 'Santa Marta, Magdalena, 470004, Colombia',
  'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_place_city.p.20.png',
  'importance': 0.92123821435197,
  'lat': '11.2430534',
  'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
  'lon': '-74.2046826',
  'osm_id': 298024011,
  'osm_type': 'node',
  'place_id': 1101199,
  'type': 'city'}}

The raw properties of the place obtained from the geocoding service are converted into the feature properties. Let’s check the properties from the arcgis geocoder:

[11]:
featureFromQuery = ee.Feature.PointFromQuery(query,geocoder = 'arcgis',user_agent = 'eemont-tutorial-010')
featureFromQuery.getInfo()
[11]:
{'type': 'Feature',
 'geometry': {'type': 'Point',
  'coordinates': [-74.19873999999999, 11.226560000000063]},
 'properties': {'address': 'Santa Marta, Magdalena',
  'attributes': {},
  'extent': {'xmax': -73.89873999999999,
   'xmin': -74.49873999999998,
   'ymax': 11.526560000000064,
   'ymin': 10.926560000000062},
  'location': {'x': -74.19873999999999, 'y': 11.226560000000063},
  'score': 100}}

Different properties are obtained using different geocoders.

Creating a MultiPoint Geometry (ee.Geometry)

When a query is geocoded, usually more than one location is retrieved. To get all locations, the ee.Geometry.MultiPointFromQuery constructor (extended through eemont) can be used:

[12]:
query = 'Amazonas'
[13]:
multiPointFromQuery = ee.Geometry.MultiPointFromQuery(query,user_agent = 'eemont-tutorial-010')

Let’s visualize our new points (color green):

[14]:
Map.addLayer(multiPointFromQuery,{'color':'green'},'MultiPoint Nominatim')
Map.centerObject(multiPointFromQuery,5)
Map

Creating a MultiPoint with Properties (ee.FeatureCollection)

A set of features can be created using the ee.FeatureCollection.MultiPointFromQuery constructor (extended through eemont):

[15]:
multiPointFromQueryFC = ee.FeatureCollection.MultiPointFromQuery(query,user_agent = 'eemont-tutorial-010')

Let’s check the properties:

[16]:
multiPointFromQueryFC.getInfo()
[16]:
{'type': 'FeatureCollection',
 'columns': {'boundingbox': 'List<String>',
  'class': 'String',
  'display_name': 'String',
  'importance': 'Float',
  'lat': 'String',
  'licence': 'String',
  'lon': 'String',
  'osm_id': 'Number',
  'osm_type': 'String',
  'place_id': 'Integer',
  'system:index': 'String',
  'type': 'String'},
 'features': [{'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-63.5185396, -4.479925]},
   'id': '0',
   'properties': {'boundingbox': ['-9.8180459',
     '2.23011',
     '-73.7984196',
     '-56.097'],
    'class': 'boundary',
    'display_name': 'Amazonas, Região Norte, Brasil',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png',
    'importance': 0.7108827273241386,
    'lat': '-4.479925',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-63.5185396',
    'osm_id': 332476,
    'osm_type': 'relation',
    'place_id': 282617930,
    'type': 'administrative'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-78, -5]},
   'id': '1',
   'properties': {'boundingbox': ['-6.9867594',
     '-2.9860745',
     '-78.7121777',
     '-77.1323027'],
    'class': 'boundary',
    'display_name': 'Amazonas, Perú',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png',
    'importance': 0.5895702362113853,
    'lat': '-5',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-78',
    'osm_id': 1973462,
    'osm_type': 'relation',
    'place_id': 282618588,
    'type': 'administrative'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point',
    'coordinates': [-65.78662101199382, 3.4220146]},
   'id': '2',
   'properties': {'boundingbox': ['0.647529',
     '6.1964813',
     '-67.8643306',
     '-63.363197'],
    'class': 'boundary',
    'display_name': 'Amazonas, Venezuela',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png',
    'importance': 0.5885060158874998,
    'lat': '3.4220146',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-65.78662101199382',
    'osm_id': 2269815,
    'osm_type': 'relation',
    'place_id': 282668106,
    'type': 'administrative'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-66, 3.5]},
   'id': '3',
   'properties': {'boundingbox': ['0.9', '6.1', '-68.6', '-63.4'],
    'class': 'place',
    'display_name': 'Amazonas, Venezuela',
    'importance': 0.5885060158874998,
    'lat': '3.5',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-66',
    'osm_id': 313466992,
    'osm_type': 'node',
    'place_id': 1182452,
    'type': 'state'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-71.9383333, -1.0197136]},
   'id': '4',
   'properties': {'boundingbox': ['-4.2316872',
     '0.1117569',
     '-74.3901656',
     '-69.3952343'],
    'class': 'boundary',
    'display_name': 'Amazonas, Colombia',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png',
    'importance': 0.5882173390160759,
    'lat': '-1.0197136',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-71.9383333',
    'osm_id': 1303962,
    'osm_type': 'relation',
    'place_id': 282525735,
    'type': 'administrative'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point',
    'coordinates': [-78.79173712416429, -3.43124245]},
   'id': '5',
   'properties': {'boundingbox': ['-3.5494547',
     '-3.3141943',
     '-78.8804479',
     '-78.7077377'],
    'class': 'boundary',
    'display_name': 'Amazonas (Rosario de Cuyes), Gualaquiza, Morona Santiago, Ecuador',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png',
    'importance': 0.44999999999999996,
    'lat': '-3.43124245',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-78.79173712416429',
    'osm_id': 2661220,
    'osm_type': 'relation',
    'place_id': 282764830,
    'type': 'administrative'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-58.0778526, -2.8429261]},
   'id': '6',
   'properties': {'boundingbox': ['-4.4421898',
     '0.7065296',
     '-73.4501259',
     '-49.2759133'],
    'class': 'waterway',
    'display_name': 'Rio Amazonas, Região Norte, 69640–000, Brasil',
    'importance': 0.4,
    'lat': '-2.8429261',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-58.0778526',
    'osm_id': 2295651,
    'osm_type': 'relation',
    'place_id': 282665096,
    'type': 'river'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-73.5283314, -4.4601154]},
   'id': '7',
   'properties': {'boundingbox': ['-4.4801154',
     '-4.4401154',
     '-73.5483314',
     '-73.5083314'],
    'class': 'place',
    'display_name': 'Amazonas, Nauta, Loreto, Perú',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_place_village.p.20.png',
    'importance': 0.385,
    'lat': '-4.4601154',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-73.5283314',
    'osm_id': 5366208059,
    'osm_type': 'node',
    'place_id': 58751289,
    'type': 'village'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-77.6988449, -2.1629408]},
   'id': '8',
   'properties': {'boundingbox': ['-2.1829408',
     '-2.1429408',
     '-77.7188449',
     '-77.6788449'],
    'class': 'place',
    'display_name': 'Amazonas, Macuma, Cantón Taisha, Morona Santiago, Ecuador',
    'icon': 'https://nominatim.openstreetmap.org/ui/mapicons//poi_place_village.p.20.png',
    'importance': 0.385,
    'lat': '-2.1629408',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-77.6988449',
    'osm_id': 3967333427,
    'osm_type': 'node',
    'place_id': 46981332,
    'type': 'village'}},
  {'type': 'Feature',
   'geometry': {'type': 'Point', 'coordinates': [-52.8005505, -1.6305629]},
   'id': '9',
   'properties': {'boundingbox': ['-1.6442518',
     '-1.5801141',
     '-52.9194198',
     '-52.68734'],
    'class': 'waterway',
    'display_name': 'Rio Amazonas, Almeirim, Região Geográfica Imediata de Almeirim - Porto de Moz, Região Geográfica Intermediária de Altamira, Pará, Região Norte, Brasil',
    'importance': 0.375,
    'lat': '-1.6305629',
    'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
    'lon': '-52.8005505',
    'osm_id': 667790311,
    'osm_type': 'way',
    'place_id': 234988367,
    'type': 'river'}}]}