Skip to content

Commit 7ee1b1b

Browse files
authored
Merge pull request #23 from swails/win32
Fix reverse_geocoder to work on Windows.
2 parents e64de47 + a30e0ca commit 7ee1b1b

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

reverse_geocoder/__init__.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import os
66
import sys
77
import csv
8-
csv.field_size_limit(sys.maxsize)
8+
if sys.platform == 'win32':
9+
# Windows C long is 32 bits, and the Python int is too large to fit inside.
10+
# Use the limit appropriate for a 32-bit integer as the max file size
11+
csv.field_size_limit(2**31-1)
12+
else:
13+
csv.field_size_limit(sys.maxsize)
914
import zipfile
1015
from scipy.spatial import cKDTree as KDTree
1116
from reverse_geocoder import cKDTree_MP as KDTree_MP
@@ -17,32 +22,32 @@
1722
GN_ADMIN2 = 'admin2Codes.txt'
1823

1924
GN_COLUMNS = {
20-
'geoNameId': 0,
21-
'name': 1,
25+
'geoNameId': 0,
26+
'name': 1,
2227
'asciiName': 2,
23-
'alternateNames': 3,
24-
'latitude': 4,
25-
'longitude': 5,
28+
'alternateNames': 3,
29+
'latitude': 4,
30+
'longitude': 5,
2631
'featureClass': 6,
2732
'featureCode': 7,
2833
'countryCode': 8,
29-
'cc2': 9,
34+
'cc2': 9,
3035
'admin1Code': 10,
31-
'admin2Code': 11,
32-
'admin3Code': 12,
33-
'admin4Code': 13,
34-
'population': 14,
35-
'elevation': 15,
36-
'dem': 16,
37-
'timezone': 17,
36+
'admin2Code': 11,
37+
'admin3Code': 12,
38+
'admin4Code': 13,
39+
'population': 14,
40+
'elevation': 15,
41+
'dem': 16,
42+
'timezone': 17,
3843
'modificationDate': 18
3944
}
4045

4146
ADMIN_COLUMNS = {
4247
'concatCodes': 0,
4348
'name': 1,
4449
'asciiName': 2,
45-
'geoNameId': 3
50+
'geoNameId': 3
4651
}
4752

4853
RG_COLUMNS = [
@@ -77,7 +82,7 @@ def __init__(self,mode=2,verbose=True):
7782
self.tree = KDTree(coordinates)
7883
else: # Multi-process
7984
self.tree = KDTree_MP.cKDTree_MP(coordinates)
80-
85+
8186

8287
def query(self,coordinates):
8388
try:
@@ -207,7 +212,7 @@ def search(geo_coords,mode=2,verbose=True):
207212
raise TypeError('Expecting a tuple or a tuple/list of tuples')
208213
elif type(geo_coords[0]) != tuple:
209214
geo_coords = [geo_coords]
210-
215+
211216
rg = RGeocoder(mode=mode,verbose=verbose)
212217
return rg.query(geo_coords)
213218

@@ -222,4 +227,4 @@ def search(geo_coords,mode=2,verbose=True):
222227
cities = [(51.5214588,-0.1729636),(9.936033, 76.259952),(37.38605,-122.08385)]
223228
print('Reverse geocoding %d cities...' % len(cities))
224229
results = search(cities)
225-
print(results)
230+
print(results)

0 commit comments

Comments
 (0)