def mexico_filter(latitude, longitude):
    geo = reverse_geocoder.RGeocoder(mode=1, verbose=True, stream=obj_data)
    coordinates = (latitude, longitude), (latitude, longitude)
    results = geo.query(coordinates)
    for response_dictionary in results:
        if [x for x in response_dictionary if response_dictionary[x] == 'US']:
            #logger.info("#######################  MX RECORD  ######################################################")
            return True
    return False
Exemplo n.º 2
0
def get_countries(coordinates):
    countries = defaultdict(lambda: 0)
    geo = rg.RGeocoder(mode=2,
                       verbose=True,
                       stream=io.StringIO(
                           open('./input/rg_cities1000.csv',
                                encoding='utf-8').read()))
    results = geo.query(coordinates)
    for i in results:
        countries[i['cc'].lower()] += 1
    return countries
Exemplo n.º 3
0
def mexico_filter(latitude, longitude):
    geo = reverse_geocoder.RGeocoder(mode=1, verbose=True, stream=obj_data)
    coordinates = (latitude, longitude), (latitude, longitude)
    results = geo.query(coordinates)
    for response_dictionary in results:
        if (response_dictionary['name'] == 'Manhattan'
                and response_dictionary['cc']
                == 'US') or (response_dictionary['name'] == 'San Francisco'
                             and response_dictionary['cc'] == 'US'):
            return True
        else:
            return False
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
"""
"""

import io
import csv
import reverse_geocoder as rg
from datetime import datetime

# Sets our own zip code data
geo = rg.RGeocoder(mode=1, verbose=True, stream=io.StringIO(open('ny_zip_coords_fixed.csv', encoding='utf-8').read()))

def getZips(coordinates):
    return geo.query(coordinates)

# Cleans time from datetime
# Reformats date to match NYPD complaint data
def cleanDate(string):
    date = string[:10]
    date = string[5:7] + "/" + string[8:10] + "/" + string[0:4]
    return date

def writeRows_TDP(numRows, neededInfo, result, outputCSV):
    for x in range(0, numRows):
        date = cleanDate(str(neededInfo[x][0]))
        outRow = [date, result[2*x]['name'], result[2*x+1]['name'], neededInfo[x][1]]
        outputCSV.writerow(outRow)
        
def writeRows_CDP(numRows, neededInfo, result, outputCSV):
    for x in range(0, numRows):
        #date = cleanDate(str(neededInfo[x][0]))
Exemplo n.º 5
0
import io
import reverse_geocoder as rg

from pyspark import SparkContext
from pyspark.sql import HiveContext

# start Spark and  Hive SQL contexts
sc = SparkContext("local", "demo app")
hc = HiveContext(sc)

# read GeoNames data file
geo = rg.RGeocoder(mode=2, verbose=True, stream=io.StringIO(open('/data/rohit/script/US_ascii.csv', 'r').read().decode('utf-8')))

print "Printing first 10 rows from rides table."
sqlQuery = "SELECT * FROM rides_yg limit 10"
hc.sql(sqlQuery).show()

coordinates = (40.742596,-74.153481),(41.316105,-74.127701),(40.786224,-74.043663),(40.736961,-74.038422),(40.748005,-74.032402),(41.031322,-74.02137 ),(40.647068,-74.010513),(40.708969,-74.010262),(40.720478,-74.010147)

print geo.query(coordinates)
Exemplo n.º 6
0
for venue_cat in venues_cat:
    if venue_cat not in cat_schema_mapping:
        print(venue_cat)
        cat_missing = True

assert cat_missing is False

# reverse geocode the venues
coords = []

for venue_id in venues_list:
    venue_lat = venues[venue_id]['lat']
    venue_lon = venues[venue_id]['lon']
    coords.append((venue_lat, venue_lon))

geo = rg.RGeocoder(mode=2, verbose=True, stream=io.StringIO(
    open('cities.csv', encoding='utf-8').read()))
venues_rg = geo.query(coords)

for index, venue_id in enumerate(venues_list):
    venues[venue_id]['geonames'] = 'geonames:' + venues_rg[index]['name']
    venues[venue_id]['city'] = venues_rg[index]['admin1']
    venues[venue_id]['country'] = venues_rg[index]['admin2']
    if venues_rg[index]['cc'] != '':
        venues[venue_id]['wikidata'] = 'wd:' + venues_rg[index]['cc']
    else:
        venues[venue_id]['wikidata'] = ''

assert len(venues_rg) == len(venues)
print("Geocoding", len(venues_rg), "venues...")

# load the checkins
Exemplo n.º 7
0
import reverse_geocoder as rg

files_list = os.listdir("BlackMarbleLandOnly")

county_light_vals = {}
num_exceptions = 0

# Processed every so iterations
querable_coords = list()

# List of float values
current_pixel_values = []

geo = rg.RGeocoder(mode=2,
                   verbose=True,
                   stream=io.StringIO(
                       open('rg_cities1000.txt', encoding='utf-8').read()))

for curr_file in files_list:
    curr_path = "BlackMarbleLandOnly/" + str(curr_file)

    with open(curr_path) as csv_file:
        # csv_reader = csv.reader(csv_file, delimiter = ',')

        # Ignore null bytes
        csv_reader = csv.reader((x.replace('\0', '') for x in csv_file),
                                delimiter=',')

        line_count = 0
        i = 0
        j = 0