Skip to content

Commit 4e54aea

Browse files
authored
Merge pull request #1 from Zulko/zulko/sql-queries
Zulko/sql queries
2 parents 372dd0d + 2c76b99 commit 4e54aea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6128
-669
lines changed

README.md

Lines changed: 2 additions & 2 deletions

geodata_curation/geodata_curation.ipynb

Lines changed: 638 additions & 67 deletions
Large diffs are not rendered by default.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
def encode_hybrid(lat, lon, base4_precision=8):
2+
# Start with base32 encoding for the first character
3+
lat_range = [-90, 90]
4+
lon_range = [-180, 180]
5+
_base32 = "0123456789bcdefghjkmnpqrstuvwxyz"
6+
7+
hashcode = ""
8+
bits = [16, 8, 4, 2, 1]
9+
bit = 0
10+
ch = 0
11+
12+
# First char (base32, 5 bits)
13+
for i in range(5):
14+
if bit % 2 == 0:
15+
mid = (lon_range[0] + lon_range[1]) / 2
16+
if lon > mid:
17+
ch |= bits[i]
18+
lon_range[0] = mid
19+
else:
20+
lon_range[1] = mid
21+
else:
22+
mid = (lat_range[0] + lat_range[1]) / 2
23+
if lat > mid:
24+
ch |= bits[i]
25+
lat_range[0] = mid
26+
else:
27+
lat_range[1] = mid
28+
bit += 1
29+
hashcode += _base32[ch]
30+
31+
# Now subsequent chars: base4 encoding (quadtree)
32+
for _ in range(base4_precision):
33+
mid_lat = (lat_range[0] + lat_range[1]) / 2
34+
mid_lon = (lon_range[0] + lon_range[1]) / 2
35+
36+
quadrant = 0
37+
if lat >= mid_lat:
38+
quadrant += 2 # north
39+
lat_range[0] = mid_lat
40+
else:
41+
lat_range[1] = mid_lat
42+
43+
if lon >= mid_lon:
44+
quadrant += 1 # east
45+
lon_range[0] = mid_lon
46+
else:
47+
lon_range[1] = mid_lon
48+
49+
hashcode += str(quadrant)
50+
51+
return hashcode
52+
53+
54+
def decode_hybrid(hashcode):
55+
"""
56+
Decode a hybrid geohash (base32 + base4) to its bounding box.
57+
58+
Args:
59+
hashcode (str): The hybrid geohash to decode
60+
61+
Returns:
62+
tuple: (minLat, minLon, maxLat, maxLon) representing the bounding box
63+
"""
64+
65+
# Initialize coordinate ranges
66+
lat_range = [-90, 90]
67+
lon_range = [-180, 180]
68+
69+
# Base32 decoding for first character
70+
_base32 = "0123456789bcdefghjkmnpqrstuvwxyz"
71+
first_char = hashcode[0].lower()
72+
73+
try:
74+
ch = _base32.index(first_char)
75+
except ValueError:
76+
raise ValueError(f"Invalid base32 character: {first_char}")
77+
78+
# Decode the first character (base32, 5 bits)
79+
bits = [16, 8, 4, 2, 1]
80+
bit = 0
81+
82+
for i in range(5):
83+
if bit % 2 == 0: # Even bits encode longitude
84+
mid = (lon_range[0] + lon_range[1]) / 2
85+
if ch & bits[i]:
86+
lon_range[0] = mid
87+
else:
88+
lon_range[1] = mid
89+
else: # Odd bits encode latitude
90+
mid = (lat_range[0] + lat_range[1]) / 2
91+
if ch & bits[i]:
92+
lat_range[0] = mid
93+
else:
94+
lat_range[1] = mid
95+
bit += 1
96+
97+
# Decode the remaining characters (base4 quadtree)
98+
for char in hashcode[1:]:
99+
try:
100+
quadrant = int(char)
101+
if quadrant < 0 or quadrant > 3:
102+
raise ValueError
103+
except ValueError:
104+
raise ValueError(f"Invalid base4 character: {char}")
105+
106+
mid_lat = (lat_range[0] + lat_range[1]) / 2
107+
mid_lon = (lon_range[0] + lon_range[1]) / 2
108+
109+
# Decode quadrant
110+
# 0: SW, 1: SE, 2: NW, 3: NE
111+
if quadrant & 2: # North (2 or 3)
112+
lat_range[0] = mid_lat
113+
else: # South (0 or 1)
114+
lat_range[1] = mid_lat
115+
116+
if quadrant & 1: # East (1 or 3)
117+
lon_range[0] = mid_lon
118+
else: # West (0 or 2)
119+
lon_range[1] = mid_lon
120+
121+
return {
122+
"min_lat": lat_range[0],
123+
"min_lon": lon_range[0],
124+
"max_lat": lat_range[1],
125+
"max_lon": lon_range[1],
126+
}

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<meta name="description" content="Explore Wikipedia articles on an interactive map. Discover landmarks, cities, natural features and historical sites around the world through a geographic interface to Wikipedia." />
88
<meta name="keywords" content="wikipedia, map, geography, landmarks, cities, exploration, interactive map, world map" />
9-
<meta property="og:title" content="World of Wikipedia" />
9+
<meta property="og:title" content="Landnotes" />
1010
<meta property="og:description" content="Explore Wikipedia articles on an interactive map. Discover landmarks, cities, natural features and historical sites around the world." />
1111
<meta property="og:type" content="website" />
1212
<meta name="twitter:card" content="summary" />
13-
<meta name="twitter:title" content="World of Wikipedia" />
13+
<meta name="twitter:title" content="Landnotes" />
1414
<meta name="twitter:description" content="Explore Wikipedia articles on an interactive map. Discover landmarks, cities, natural features and historical sites around the world." />
15-
<title>World of Wikipedia</title>
15+
<title>Landnotes</title>
1616
</head>
1717
<body>
1818
<div id="app"></div>

package-lock.json

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "world_of_wikipedia",
2+
"name": "landnotes",
33
"private": true,
44
"version": "0.1.0",
55
"type": "module",
@@ -14,10 +14,7 @@
1414
"vite": "^6.2.0"
1515
},
1616
"dependencies": {
17-
"fuse.js": "^7.1.0",
18-
"latlon-geohash": "^2.0.0",
19-
"leaflet": "^1.9.4",
20-
"ngeohash": "^0.6.3",
21-
"pako": "^2.1.0"
17+
"jszip": "^3.10.1",
18+
"leaflet": "^1.9.4"
2219
}
2320
}

public/geodata/0.csv.gz

-9.35 KB
Binary file not shown.

public/geodata/1.csv.gz

-8.58 KB
Binary file not shown.

public/geodata/2.csv.gz

-28.7 KB
Binary file not shown.

public/geodata/3.csv.gz

-3.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)