ResultsMotivated.com

How many towns named 'Paris' are in the United States?

<2024-06-16>

1. Paris, USA

Paris, Texas is probably the most famous Paris in the United States. But what other towns called Paris exist in the USA? Here is a script that demonstrates how to use Nominatim to answer this question.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2024-06-13T15:34:20-04:00

@author: nate
"""
from geopy.geocoders import Nominatim
import argparse
import geojson
import shapely
import os
import sys

parser = argparse.ArgumentParser()
parser.add_argument("nominatim_query", type=str)
args = parser.parse_args()

nom = Nominatim(user_agent="nateapp1")
res0 = nom.geocode('Paris, USA', exactly_one=False, limit=40, geometry='wkt')

features = []
for item in res0:
    props = filter(lambda pair: pair[0] != "geotext", item.raw.items())
    props = dict([pair for pair in props])
    geom = item.raw['geotext']
    geom = shapely.from_wkt(geom)
    feature = geojson.Feature(properties=props, geometry=geom)
    features.append(feature)

features = geojson.FeatureCollection(features)

basedir = os.path.dirname(__file__)
outpath = os.path.join(basedir, "result.geojson")
with open(outpath, "w+") as fp:
    fp.write(geojson.dumps(features))

print(f"Found {len(features['features'])} results for '{args.nominatim_query}':")
for i, item in enumerate(features['features']):
    print(f"{i:4}: {item['properties']['display_name']}")

sys.exit(0)

To find the answer, call the script as follows:

(base) nate@nate-Kudu:~/spyder_projects/ohsome$ ./nominatim_search.py 'Paris, USA'
Found 27 results for 'Paris, USA':
   0: Paris, Lamar County, Texas, United States
   1: Paris, Bourbon County, Kentucky, 40361, United States
   2: Paris, Henry County, West Tennessee, Tennessee, United States
   3: Paris, Edgar County, Illinois, 61944, United States
   4: Paris, Oxford County, Maine, 04281, United States
   5: Town of Paris, Oneida County, New York, United States
   6: Paris, Logan County, Arkansas, 72855, United States
   7: Paris, Monroe County, Missouri, 65275, United States
   8: Paris, Bear Lake County, Idaho, 83261, United States
   9: Paris, Hanover Township, Washington County, Pennsylvania, United States
  10: Paris, Fauquier County, Virginia, United States
  11: Paris, Lane County, Oregon, United States
  12: Paris, Linn County, Iowa, 52218, United States
  13: Paris, Paris Township, Stark County, Ohio, 44669, United States
  14: Paris, Jennings County, Indiana, 47230, United States
  15: Paris, Dummer, Coös County, New Hampshire, United States
  16: Paris, Fauquier County, Virginia, 20130, United States
  17: Paris, Town of Paris, Kenosha County, Wisconsin, United States
  18: Paris, Calvert County, Maryland, 20758, United States
  19: Paris, California, 93510, United States
  20: Paris, Green Charter Township, Mecosta County, Michigan, United States
  21: Paris, Lafayette County, Mississippi, 38949, United States
  22: Paris, Davis County, Iowa, United States
  23: Paris, Lamar County, Texas, United States
  24: Paris, Bear Lake County, Idaho, 83261, United States
  25: Paris, Wade Hampton, Greenville County, South Carolina, 29614, United States
  26: Paris, Paris Township, Portage County, Ohio, 44285, United States

Keywords: geospatial, geo, python

Modified: 2024-09-10 10:09:59 EDT

Emacs 29.1.50 (Org mode 9.7.6)