{"id":4864,"date":"2018-03-22T06:37:43","date_gmt":"2018-03-22T13:37:43","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4864"},"modified":"2025-06-13T23:43:11","modified_gmt":"2025-06-14T06:43:11","slug":"geospatial-queries-using-python-search-cities","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/","title":{"rendered":"Geospatial queries: Using Python to search cities"},"content":{"rendered":"<h3><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4863\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/03\/16665891_10211247083188500_2291386332147570222_o.jpg\" alt=\"16665891 10211247083188500 2291386332147570222 o\" width=\"247\" height=\"247\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o.jpg 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-300x300.jpg 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-1024x1024.jpg 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-150x150.jpg 150w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-768x768.jpg 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-65x65.jpg 65w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-50x50.jpg 50w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-20x20.jpg 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o-1320x1320.jpg 1320w\" sizes=\"auto, (max-width: 247px) 100vw, 247px\" \/><\/h3>\n<p>Daniel Ancuta is a software engineer with several years of experience using different technologies. He\u2019s a big fan of \u201cThe Zen of Python,\u201d which he tries to apply not only in his code but in his private life as well. You can find him on Twitter: <u><a href=\"https:\/\/twitter.com\/daniel_ancuta\" target=\"_blank\" rel=\"noopener noreferrer\">@daniel_ancuta<\/a><\/u><\/p>\n<h2><strong>Geospatial queries: Using Python to search cities<\/strong><\/h2>\n<p>Geolocation information is used every day in almost every aspect of our interaction with computers. Either it&#8217;s a website that wants to send us personalized notifications based on location, maps that show us the shortest possible route, or just tasks running in the background that checks the places we&#8217;ve visited.<\/p>\n<p>Today, I&#8217;d like to introduce you to <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.1\/fts\/fts-geospatial-queries.html\" target=\"_blank\" rel=\"noopener noreferrer\">geospatial queries<\/a><\/u>\u00a0that are used in Couchbase. <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.1\/fts\/fts-geospatial-queries.html\" target=\"_blank\" rel=\"noopener noreferrer\">Geospatial queries<\/a><\/u>\u00a0allow you to search documents based on their geographical location.<\/p>\n<p>Together, we will write a tool in Python that uses <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.1\/fts\/fts-geospatial-queries.html\" target=\"_blank\" rel=\"noopener noreferrer\">geospatial queries<\/a><\/u>\u00a0with <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/fts\/fts-query-types.html\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase REST API<\/a><\/u>\u00a0and <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/fts\/full-text-intro.html\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Full Text Search<\/a><\/u>, which will help us in searching a database of cities.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<h3><strong>Dependencies<\/strong><\/h3>\n<p>In this article I used <a href=\"https:\/\/www.couchbase.com\/downloads\/\">Couchbase Enterprise Edition<\/a> 5.1.0 build 5552\u00a0and <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/sdk\/python\/start-using-sdk.html\">Python<\/a> 3.6.4.<\/p>\n<p>To run snippets from this article you should install Couchbase\u00a02.3 (I am using 2.3.4) via pip.<\/p>\n<h3><strong>Couchbase<\/strong><\/h3>\n<ol>\n<li>Create a cities\u00a0bucket<\/li>\n<li>Create a cities\u00a0search with geo\u00a0field of type geopoint\u00a0type. You can read about it in the <u><a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.1\/fts\/fts-creating-indexes.html\" target=\"_blank\" rel=\"noopener noreferrer\">Inserting a Child Field<\/a><\/u>\u00a0part of the documentation.<\/li>\n<\/ol>\n<p>It should look like the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"1244\" class=\"wp-image-4862\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/03\/image_1.png\" alt=\"image 1\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1.png 1600w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-300x233.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-1024x796.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-768x597.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-1536x1194.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-20x16.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/image_1-1320x1026.png 1320w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<h2><strong>Populating Couchbase with data<\/strong><\/h2>\n<p>First of all, we need to have data for our exercise. For that, we will use a database of cities from <u><a href=\"https:\/\/www.geonames.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">geonames.org<\/a><\/u>.<\/p>\n<p>GeoNames contains two main databases: list of cities and list of postal codes.<\/p>\n<p>All are grouped by country with corresponding information like name, coordinates, population, time zone, country code, and so on. Both are in CSV format.<\/p>\n<p>For the purpose of this exercise, we will use the list of cities. I&#8217;ve used <u><a href=\"https:\/\/download.geonames.org\/export\/dump\/PL.zip\" target=\"_blank\" rel=\"noopener noreferrer\">PL.zip<\/a><\/u>\u00a0but feel free to choose whichever you prefer from the <u><a href=\"https:\/\/download.geonames.org\/export\/dump\/\" target=\"_blank\" rel=\"noopener noreferrer\">list of cities<\/a><\/u>.<\/p>\n<h3><strong>Data model<\/strong><\/h3>\n<p>City\u00a0class will be our representation of a single city that we will use across the whole application. By encapsulating it in a model, we unify the API and don&#8217;t need to rely on third-party data sources (e.g., CSV file) which might change.<\/p>\n<p>Most of our snippets are located (until said otherwise) in the core.py\u00a0file. So just remember to update it (especially when adding new imports) and not override the whole content.<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\nclass City:\r\n   def __init__(self, geonameid, feature_class, name, population, lat, lon):\r\n       self.geonameid = geonameid\r\n       self.feature_class = feature_class\r\n       self.name = name\r\n       self.population = population\r\n       self.lat = lat\r\n       self.lon = lon\r\n\r\n   @classmethod\r\n   def from_csv_row(cls, row):\r\n       return cls(row[0], row[7], row[1], row[12], row[4], row[5])<\/pre>\n<p>&nbsp;<\/p>\n<h3><strong>CSV iterator to process cities<\/strong><\/h3>\n<p>As we have a model class, it&#8217;s time to prepare an iterator that will help us to read the cities from the CSV file.<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\nimport csv\r\nfrom collections import Iterator\r\n\r\nclass CitiesCsvIterator(Iterator):\r\n   def __init__(self, path):\r\n       self._path = path\r\n       self._fp = None\r\n       self._csv_reader = None\r\n\r\n   def __enter__(self):\r\n       self._fp = open(self._path, 'r')\r\n       self._csv_reader = csv.reader(self._fp, delimiter='\\t')\r\n\r\n       return self\r\n\r\n   def __exit__(self, exc_type, exc_val, exc_tb):\r\n       self._fp.close()\r\n\r\n   def __next__(self):\r\n       return City.from_csv_row(next(self._csv_reader))\r\n<\/pre>\n<h3><strong>Insert cities to Couchbase bucket<\/strong><\/h3>\n<p>We have unified the way to represent a city, and we have an iterator that would read those from csv file.<\/p>\n<p>It&#8217;s time to put this data into our main data source, <u><a href=\"https:\/\/www.couchbase.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase<\/a><\/u>.<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\nimport logging\r\nimport sys\r\nfrom couchbase.cluster import Cluster, PasswordAuthenticator\r\n\r\n\r\nlogger = logging.getLogger()\r\nlogger.setLevel(logging.DEBUG)\r\nlogger.addHandler(logging.StreamHandler(sys.stdout))\r\n\r\n\r\ndef get_bucket(username, password, connection_string='couchbase:\/\/localhost'):\r\n   cluster = Cluster(connection_string)\r\n   authenticator = PasswordAuthenticator(username, password)\r\n   cluster.authenticate(authenticator)\r\n\r\n   return cluster.open_bucket('cities')\r\n\r\n\r\nclass CitiesService:\r\n   def __init__(self, bucket):\r\n       self._bucket = bucket\r\n\r\n   def load_from_csv(self, path):\r\n       with CitiesCsvIterator(path) as cities_iterator:\r\n           for city in cities_iterator:\r\n               if city.feature_class not in ('PPL', 'PPLA', 'PPLA2', 'PPLA3',\r\n                                             'PPLA4', 'PPLC'):\r\n                   continue\r\n\r\n               logger.info(f'Inserting {city.geonameid}')\r\n               self._bucket.upsert(\r\n                   city.geonameid,\r\n                   {\r\n                       'name': city.name,\r\n                       'feature_class': city.feature_class,\r\n                       'population': city.population,\r\n                       'geo': {'lat': float(city.lat),\r\n                               'lon': float(city.lon)}\r\n                   }\r\n               )\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>To check if everything we wrote so far is working, let&#8217;s load CSV content into Couchbase.<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\n\r\nbucket = get_bucket('admin', 'test123456')\r\ncities_service = CitiesService(bucket)\r\ncities_service.load_from_csv('~\/directory-with-cities\/PL\/PL.txt', bucket)<\/pre>\n<p>&nbsp;<\/p>\n<p>At this point you should have cities loaded into your Couchbase bucket. The time it takes depends on the country you have chosen.<\/p>\n<h2><strong>Search cities<\/strong><\/h2>\n<p>We have our bucket ready with data, so it&#8217;s time to come back to CitiesService\u00a0and prepare a few methods that would help us in searching cities.<\/p>\n<p>But before we start, we need to modify the City\u00a0class slightly, by adding the following method:<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\n\r\n@classmethod\r\ndef\u00a0from_couchbase_dict(cls, row):\r\nfields =\u00a0row['fields']\r\n\r\nreturn\u00a0cls(row['id'],\r\nfields['feature_class'],\r\nfields['name'],\r\nfields['population'],\r\nfields['geo'][1],\r\nfields['geo'][0])\r\n\r\n<\/pre>\n<p>That&#8217;s a list of methods we will implement in CitiesService:<\/p>\n<ul>\n<li>get_by_name(name, limit=10), returns cities by their names<\/li>\n<li>get_by_coordinates(lat, lon), returns city by coordinates<\/li>\n<li>get_nearest_to_city(city, distance=&#8217;10&#8217;, unit=&#8217;km&#8217;, limit=10), returns nearest city<\/li>\n<\/ul>\n<h3><strong>get_by_name<\/strong><\/h3>\n<pre class=\"lang:default decode:true \"># core.py\r\nfrom\u00a0couchbase.fulltext import\u00a0TermQuery\r\n\r\nINDEX_NAME\u00a0=\u00a0'cities'\r\n\r\ndef\u00a0get_by_name(self, name, limit=10):\r\nresult =\u00a0self._bucket.search(self.INDEX_NAME,\r\nTermQuery(name.lower(), field='name'),\r\nlimit=limit,\r\nfields='*')\r\n\r\nfor\u00a0c_city in\u00a0result:\r\nyield\u00a0City.from_couchbase_dict(c_city)<\/pre>\n<p>&nbsp;<\/p>\n<h3><strong>get_by_coordinates<\/strong><\/h3>\n<pre class=\"lang:default decode:true \"># core.py\r\nfrom\u00a0couchbase.fulltext import\u00a0GeoDistanceQuery\r\n\r\nINDEX_NAME\u00a0=\u00a0'cities'\r\n\r\ndef\u00a0get_by_coordinates(self, lat, lon):\r\nresult =\u00a0self._bucket.search(self.INDEX_NAME,\r\nGeoDistanceQuery('1km', (lon, lat)),\r\nfields='*')\r\n\r\nfor\u00a0c_city in\u00a0result:\r\nyield\u00a0City.from_couchbase_dict(c_city)<\/pre>\n<p>&nbsp;<\/p>\n<h3><strong>get_nearest_to_city<\/strong><\/h3>\n<pre class=\"lang:default decode:true \"># core.py\r\nfrom\u00a0couchbase.fulltext import\u00a0RawQuery, SortRaw\r\n\r\nINDEX_NAME\u00a0=\u00a0'cities'\r\n\r\ndef\u00a0get_nearest_to_city(self, city, distance='10', unit='km', limit=10):\r\nquery =\u00a0RawQuery({\r\n'location': {\r\n'lon': city.lon,\r\n'lat': city.lat\r\n},\r\n'distance': str(distance) +\u00a0unit,\r\n'field': 'geo'\r\n\r\n})\r\nsort =\u00a0SortRaw([{\r\n'by': 'geo_distance',\r\n'field': 'geo',\r\n'unit': unit,\r\n'location': {\r\n'lon': city.lon,\r\n'lat': city.lat\r\n}\r\n}])\r\n\r\nresult =\u00a0self._bucket.search(self.INDEX_NAME,\r\nquery,\r\nsort=sort,\r\nfields='*',\r\nlimit=limit)\r\n\r\nfor\u00a0c_city in\u00a0result:\r\nyield\u00a0City.from_couchbase_dict(c_city)\r\n\r\n<\/pre>\n<p>As you might notice in this example, we used RawQuery\u00a0and SortRaw\u00a0classes. Sadly, couchbase-python-client\u00a0API does not work correctly with the newest Couchbase and geo searches.<\/p>\n<h2><strong>Call methods<\/strong><\/h2>\n<p>As we now have all methods ready, we can call it!<\/p>\n<pre class=\"lang:default decode:true \"># core.py\r\n\r\nbucket =\u00a0get_bucket('admin', 'test123456')\r\n\r\ncities_service =\u00a0CitiesService(bucket)\r\n# cities_service.load_from_csv('\/my-path\/PL\/PL.txt')\r\n\r\nprint('get_by_name')\r\ncities =\u00a0cities_service.get_by_name('Pozna\u0144')\r\nfor\u00a0city in\u00a0cities:\r\nprint(city.__dict__)\r\n\r\nprint('get_by_coordinates')\r\ncities =\u00a0cities_service.get_by_coordinates(52.40691997632544,\r\n16.929929926276657)\r\nfor\u00a0city in\u00a0cities:\r\nprint(city.__dict__)\r\n\r\nprint('get_nearest_to_city')\r\ncities =\u00a0cities_service.get_nearest_to_city(city)\r\nfor\u00a0city in\u00a0cities:\r\nprint(city.__dict__)<\/pre>\n<h2><strong>Where to go from here?<\/strong><\/h2>\n<p>I believe this introduction will enable you to work on something more advanced.<\/p>\n<p>There are a few things that you could do:<\/p>\n<ul>\n<li>Maybe use a CLI tool or REST API to serve this data?Improve the way we load data, because it might not be super performant if we want to load ALL cities from ALL countries.<\/li>\n<\/ul>\n<p>You can find the whole code of core.py in <u><a href=\"https:\/\/gist.github.com\/whisller\/74b731270cd56937a6d821f6cbe773d9\" target=\"_blank\" rel=\"noopener noreferrer\">github gist<\/a><\/u>.<\/p>\n<p>If you have any questions, don\u2019t hesitate to tweet me <u><a href=\"https:\/\/twitter.com\/daniel_ancuta\" target=\"_blank\" rel=\"noopener noreferrer\">@daniel_ancuta<\/a><\/u>.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><em>This post is part of the <a href=\"https:\/\/www.couchbase.com\/community\/community-writers-program\/\" target=\"_blank\" rel=\"noopener noreferrer\">Community Writing program<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Python we are creating a tool that will use geospatial queries with Couchbase REST API and Couchbase Full Text Search, which will help us in searching a database of cities.<\/p>\n","protected":false},"author":53,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,8683,9139],"tags":[],"ppma_author":[9026],"class_list":["post-4864","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-geospatial","category-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Geospatial queries: Using Python to search cities - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Geospatial queries: Using Python to search cities\" \/>\n<meta property=\"og:description\" content=\"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-22T13:37:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T06:43:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1536\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Laura Czajkowski, Developer Community Manager, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\"},\"author\":{\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\"},\"headline\":\"Geospatial queries: Using Python to search cities\",\"datePublished\":\"2018-03-22T13:37:43+00:00\",\"dateModified\":\"2025-06-14T06:43:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\"},\"wordCount\":762,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Couchbase Server\",\"Geospatial\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\",\"name\":\"Geospatial queries: Using Python to search cities - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2018-03-22T13:37:43+00:00\",\"dateModified\":\"2025-06-14T06:43:11+00:00\",\"description\":\"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Geospatial queries: Using Python to search cities\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220\",\"name\":\"Laura Czajkowski, Developer Community Manager, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g\",\"caption\":\"Laura Czajkowski, Developer Community Manager, Couchbase\"},\"description\":\"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/laura-czajkowski\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Geospatial queries: Using Python to search cities - The Couchbase Blog","description":"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/","og_locale":"en_US","og_type":"article","og_title":"Geospatial queries: Using Python to search cities","og_description":"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.","og_url":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-03-22T13:37:43+00:00","article_modified_time":"2025-06-14T06:43:11+00:00","og_image":[{"width":1536,"height":1536,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/03\/16665891_10211247083188500_2291386332147570222_o.jpg","type":"image\/jpeg"}],"author":"Laura Czajkowski, Developer Community Manager, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Laura Czajkowski, Developer Community Manager, Couchbase","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/"},"author":{"name":"Laura Czajkowski, Developer Community Manager, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220"},"headline":"Geospatial queries: Using Python to search cities","datePublished":"2018-03-22T13:37:43+00:00","dateModified":"2025-06-14T06:43:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/"},"wordCount":762,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Couchbase Server","Geospatial","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/","url":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/","name":"Geospatial queries: Using Python to search cities - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2018-03-22T13:37:43+00:00","dateModified":"2025-06-14T06:43:11+00:00","description":"What are Geospatial queries? Check out how to write a tool in Python that uses geospatial queries\u00a0with Couchbase REST API\u00a0and Couchbase FullText Search.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/geospatial-queries-using-python-search-cities\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Geospatial queries: Using Python to search cities"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5f1a0ece4e644bc8c037686fbc8f3220","name":"Laura Czajkowski, Developer Community Manager, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/9deb07d5daaa00220534c31768bc4409","url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","caption":"Laura Czajkowski, Developer Community Manager, Couchbase"},"description":"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter.","url":"https:\/\/www.couchbase.com\/blog\/author\/laura-czajkowski\/"}]}},"authors":[{"term_id":9026,"user_id":53,"is_guest":0,"slug":"laura-czajkowski","display_name":"Laura Czajkowski, Developer Community Manager, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bc8eebaf25cbe39bc12fd7b1ef92550becc3953ab877a3f0285a59ec2d30b754?s=96&d=mm&r=g","author_category":"","last_name":"Czajkowski","first_name":"Laura","job_title":"","user_url":"","description":"Laura Czajkowski is the Snr. Developer Community Manager at Couchbase overseeing the community. She\u2019s responsible for our monthly developer newsletter."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4864"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4864\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4864"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}