Introduction to Geocoding
WHERE AM I?
Geocoding is all about coordinates, the x and y axis.
Converting an address like Lutheran Church Kisumu, Kenya to -0.107626,
34.768505.
Location has become key in data collection, accurate location being the key
word, and accurate location goes back to the definition of Geocoding.
Users want answers to questions like “Who is near me?”, “what is near me?”,
“how far am I from X?”
How can we answer the users such questions, in ms?
Users want answers
● “Who is near me?”
● “what is near me?”
● “how far am I from X?
What would happen if we relied on the
names of places instead of coordinates?
Introduction to Redis and Geo API
● Redis is an in-memory data structure store that's commonly used as a database, a
cache, and a message broker.
● Data structures in Redis are like Lego building blocks, helping developers achieve
specific functionalities with minimal complexity and at an amazing speed .
● Redis also minimizes network overhead and latency because operations are executed
extremely efficiently in memory, right next to where the data is stored.
● We’ll get to see geospatial functions that use two-dimensional indices built from
latitude and longitude data, and how we can use other Redis APIs to get the most out of
Redis to make our work easier, and most importantly, make our applications fast.
Write to the DB
Save the location by calling the GEOADD API
It takes in the longitude, latitude and member.
Updating the DB uses the same api.
Whether writing or updating the db, if everything goes well, response will always be
{:ok, val}
Write to the DB
Read from the DB Read from the DB
You can use hashes instead of coordinates.
GEOHASH returns a string, a unique, that is
user friendly and browser(url) friendly.
The longer the string, the more accurate it
is.
We can query coordinates of one place, a
member, in your table.
The output is something like this:
Read from DB
You can also use other APIs that Redis has to
query from DB.
Like ZRANGE – gives you list of members
within the range you specify.
If you query a non-existent table (sad path)
ZRANGE gives you a list of the locations, but
you can decide to get
Only the number of locations in your
database.
The ZCARD is a handy command when you
need that.
Important Points to Note
Redis supports data structures such as strings, hashes, lists, sets, sorted sets with range
queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.
Geospatial indexing uses sorted sets which adds an ordered view to members, sorted
by scores.
When we add our coordinates (longitudes and latitudes), they are hashed together to
make a numeric geohash and the label is saved in a sorted set with the geohash as a
score in a sorted set (ZSET).
This how scores are derived:
● If A and B are two elements with a different score, then A > B if A.score is > B.score.
● If A and B have exactly the same score, then A > B if the A string is lexicographically
greater than the B string. A and B strings can't be equal since sorted sets only have
unique elements.
Queries for Searching the DB
GEORADIUS
Searching within a circle given by its center and its radius and returns the members that
fall inside it.
We specify the distance we want to query with, like “Which hospitals are 500m away from
me?”
We can also ensure that the response comes with the distance, or coordinates or hash.
GEORADIUSBYMEMBER
Works exactly like GEORADIUS with additional information, it accepts one of the indexed
members as the circle’s center.
The difference between this and GEORADIUS is that here you specify a member, with the
latter you use coordinates of where your searching.
See:
Points to Note
Results are obtained in less than 10ms- for
little amount of data.
If you want want great performance
(speed), keep the radius as small as
possible.
The more points that the circle covers, the
slower the query.
GEODISTANCE
Calculates the distance between two members
By default, return value is in meters, but you can always specify the units you want.
Deleting from Database
You don’t need a location from your db anymore, then ZREM will work for you.
Response shows you the number of locations deleted.
RediSearch
Search engine that utilizes both its own datatype and the inbuilt Redis data types.
Best features:
● Auto-Complete and suggestions/ hints
● Simplicity and ease of use – define an index, add data then search.
Resources
Data Structures
- https://redislabs.com/why-redis/
- https://redis.io/topics/data-types-intro
Geo API
- https://redislabs.com/redis-best-practices/indexing-patterns/geospatial/
-

Introduction To Geocoding: Linda Achieng

  • 1.
  • 2.
  • 3.
    Geocoding is allabout coordinates, the x and y axis. Converting an address like Lutheran Church Kisumu, Kenya to -0.107626, 34.768505. Location has become key in data collection, accurate location being the key word, and accurate location goes back to the definition of Geocoding. Users want answers to questions like “Who is near me?”, “what is near me?”, “how far am I from X?” How can we answer the users such questions, in ms?
  • 4.
    Users want answers ●“Who is near me?” ● “what is near me?” ● “how far am I from X?
  • 5.
    What would happenif we relied on the names of places instead of coordinates?
  • 7.
  • 9.
    ● Redis isan in-memory data structure store that's commonly used as a database, a cache, and a message broker. ● Data structures in Redis are like Lego building blocks, helping developers achieve specific functionalities with minimal complexity and at an amazing speed . ● Redis also minimizes network overhead and latency because operations are executed extremely efficiently in memory, right next to where the data is stored. ● We’ll get to see geospatial functions that use two-dimensional indices built from latitude and longitude data, and how we can use other Redis APIs to get the most out of Redis to make our work easier, and most importantly, make our applications fast.
  • 11.
    Write to theDB Save the location by calling the GEOADD API It takes in the longitude, latitude and member. Updating the DB uses the same api. Whether writing or updating the db, if everything goes well, response will always be {:ok, val}
  • 12.
  • 13.
    Read from theDB Read from the DB You can use hashes instead of coordinates. GEOHASH returns a string, a unique, that is user friendly and browser(url) friendly. The longer the string, the more accurate it is. We can query coordinates of one place, a member, in your table. The output is something like this:
  • 15.
    Read from DB Youcan also use other APIs that Redis has to query from DB. Like ZRANGE – gives you list of members within the range you specify. If you query a non-existent table (sad path) ZRANGE gives you a list of the locations, but you can decide to get Only the number of locations in your database. The ZCARD is a handy command when you need that.
  • 16.
    Important Points toNote Redis supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Geospatial indexing uses sorted sets which adds an ordered view to members, sorted by scores. When we add our coordinates (longitudes and latitudes), they are hashed together to make a numeric geohash and the label is saved in a sorted set with the geohash as a score in a sorted set (ZSET). This how scores are derived: ● If A and B are two elements with a different score, then A > B if A.score is > B.score. ● If A and B have exactly the same score, then A > B if the A string is lexicographically greater than the B string. A and B strings can't be equal since sorted sets only have unique elements.
  • 17.
    Queries for Searchingthe DB GEORADIUS Searching within a circle given by its center and its radius and returns the members that fall inside it. We specify the distance we want to query with, like “Which hospitals are 500m away from me?” We can also ensure that the response comes with the distance, or coordinates or hash.
  • 18.
    GEORADIUSBYMEMBER Works exactly likeGEORADIUS with additional information, it accepts one of the indexed members as the circle’s center. The difference between this and GEORADIUS is that here you specify a member, with the latter you use coordinates of where your searching. See:
  • 20.
    Points to Note Resultsare obtained in less than 10ms- for little amount of data. If you want want great performance (speed), keep the radius as small as possible. The more points that the circle covers, the slower the query.
  • 21.
    GEODISTANCE Calculates the distancebetween two members By default, return value is in meters, but you can always specify the units you want.
  • 23.
    Deleting from Database Youdon’t need a location from your db anymore, then ZREM will work for you. Response shows you the number of locations deleted.
  • 24.
    RediSearch Search engine thatutilizes both its own datatype and the inbuilt Redis data types. Best features: ● Auto-Complete and suggestions/ hints ● Simplicity and ease of use – define an index, add data then search.
  • 25.
    Resources Data Structures - https://redislabs.com/why-redis/ -https://redis.io/topics/data-types-intro Geo API - https://redislabs.com/redis-best-practices/indexing-patterns/geospatial/ -