quantaroute-geocoding 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of quantaroute-geocoding might be problematic. Click here for more details.
- quantaroute_geocoding/__init__.py +32 -0
- quantaroute_geocoding/cli.py +281 -0
- quantaroute_geocoding/client.py +312 -0
- quantaroute_geocoding/csv_processor.py +415 -0
- quantaroute_geocoding/exceptions.py +42 -0
- quantaroute_geocoding/offline.py +280 -0
- quantaroute_geocoding-1.0.0.dist-info/METADATA +349 -0
- quantaroute_geocoding-1.0.0.dist-info/RECORD +12 -0
- quantaroute_geocoding-1.0.0.dist-info/WHEEL +5 -0
- quantaroute_geocoding-1.0.0.dist-info/entry_points.txt +2 -0
- quantaroute_geocoding-1.0.0.dist-info/licenses/LICENSE +21 -0
- quantaroute_geocoding-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Offline DigiPin processing using the official DigiPin library
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from typing import Dict, Tuple, Optional, List
|
|
7
|
+
from .exceptions import OfflineProcessingError, ValidationError
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import digipin
|
|
11
|
+
DIGIPIN_AVAILABLE = True
|
|
12
|
+
except ImportError:
|
|
13
|
+
DIGIPIN_AVAILABLE = False
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class OfflineProcessor:
|
|
17
|
+
"""
|
|
18
|
+
Offline DigiPin processor using the official DigiPin library
|
|
19
|
+
|
|
20
|
+
This class provides offline DigiPin operations without requiring API calls.
|
|
21
|
+
Perfect for processing large datasets or when internet connectivity is limited.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self):
|
|
25
|
+
"""Initialize the offline processor"""
|
|
26
|
+
if not DIGIPIN_AVAILABLE:
|
|
27
|
+
raise OfflineProcessingError(
|
|
28
|
+
"DigiPin library not available. Install with: pip install digipin"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def coordinates_to_digipin(self, latitude: float, longitude: float) -> Dict:
|
|
32
|
+
"""
|
|
33
|
+
Convert coordinates to DigiPin code (offline)
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
latitude: Latitude coordinate
|
|
37
|
+
longitude: Longitude coordinate
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Dict containing DigiPin and coordinates
|
|
41
|
+
"""
|
|
42
|
+
if not isinstance(latitude, (int, float)) or not isinstance(longitude, (int, float)):
|
|
43
|
+
raise ValidationError("Latitude and longitude must be numbers")
|
|
44
|
+
|
|
45
|
+
if not (-90 <= latitude <= 90):
|
|
46
|
+
raise ValidationError("Latitude must be between -90 and 90")
|
|
47
|
+
|
|
48
|
+
if not (-180 <= longitude <= 180):
|
|
49
|
+
raise ValidationError("Longitude must be between -180 and 180")
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
digipin_code = digipin.getDIGIPINFromLatLon(latitude, longitude)
|
|
53
|
+
|
|
54
|
+
if not digipin_code or digipin_code == "Invalid coordinates":
|
|
55
|
+
raise OfflineProcessingError("Unable to generate DigiPin from coordinates")
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
'digipin': digipin_code,
|
|
59
|
+
'coordinates': {
|
|
60
|
+
'latitude': latitude,
|
|
61
|
+
'longitude': longitude
|
|
62
|
+
},
|
|
63
|
+
'source': 'offline'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
except Exception as e:
|
|
67
|
+
raise OfflineProcessingError(f"Failed to generate DigiPin: {str(e)}")
|
|
68
|
+
|
|
69
|
+
def digipin_to_coordinates(self, digipin_code: str) -> Dict:
|
|
70
|
+
"""
|
|
71
|
+
Convert DigiPin code to coordinates (offline)
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
digipin_code: The DigiPin code to convert
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Dict containing coordinates
|
|
78
|
+
"""
|
|
79
|
+
if not digipin_code or not digipin_code.strip():
|
|
80
|
+
raise ValidationError("DigiPin code is required")
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
result = digipin.getLatLonFromDIGIPIN(digipin_code.strip())
|
|
84
|
+
|
|
85
|
+
if result == "Invalid DIGIPIN":
|
|
86
|
+
raise OfflineProcessingError("Invalid DigiPin code")
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
'digipin': digipin_code.strip(),
|
|
90
|
+
'coordinates': {
|
|
91
|
+
'latitude': result.latitude,
|
|
92
|
+
'longitude': result.longitude
|
|
93
|
+
},
|
|
94
|
+
'source': 'offline'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
except Exception as e:
|
|
98
|
+
raise OfflineProcessingError(f"Failed to convert DigiPin: {str(e)}")
|
|
99
|
+
|
|
100
|
+
def validate_digipin(self, digipin_code: str) -> Dict:
|
|
101
|
+
"""
|
|
102
|
+
Validate DigiPin format (offline)
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
digipin_code: The DigiPin code to validate
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
Dict containing validation results
|
|
109
|
+
"""
|
|
110
|
+
if not digipin_code or not digipin_code.strip():
|
|
111
|
+
return {
|
|
112
|
+
'isValid': False,
|
|
113
|
+
'digipin': digipin_code or '',
|
|
114
|
+
'errors': ['DigiPin is required'],
|
|
115
|
+
'source': 'offline'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
clean_digipin = digipin_code.strip()
|
|
119
|
+
errors = []
|
|
120
|
+
|
|
121
|
+
# Basic format validation
|
|
122
|
+
if len(clean_digipin) < 6 or len(clean_digipin) > 20:
|
|
123
|
+
errors.append('DigiPin must be between 6 and 20 characters long')
|
|
124
|
+
|
|
125
|
+
# Check for valid characters
|
|
126
|
+
if not all(c.isalnum() or c in '-_' for c in clean_digipin):
|
|
127
|
+
errors.append('DigiPin can only contain alphanumeric characters, hyphens, and underscores')
|
|
128
|
+
|
|
129
|
+
# Try to validate with DigiPin library
|
|
130
|
+
is_valid = len(errors) == 0
|
|
131
|
+
if is_valid:
|
|
132
|
+
try:
|
|
133
|
+
result = digipin.getLatLonFromDIGIPIN(clean_digipin)
|
|
134
|
+
if result == "Invalid DIGIPIN":
|
|
135
|
+
is_valid = False
|
|
136
|
+
errors.append('DigiPin does not correspond to a valid location')
|
|
137
|
+
except:
|
|
138
|
+
is_valid = False
|
|
139
|
+
errors.append('DigiPin does not correspond to a valid location')
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
'isValid': is_valid,
|
|
143
|
+
'digipin': clean_digipin,
|
|
144
|
+
'errors': errors if errors else None,
|
|
145
|
+
'source': 'offline'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
def calculate_distance(
|
|
149
|
+
self,
|
|
150
|
+
lat1: float, lon1: float,
|
|
151
|
+
lat2: float, lon2: float,
|
|
152
|
+
unit: str = 'km'
|
|
153
|
+
) -> float:
|
|
154
|
+
"""
|
|
155
|
+
Calculate distance between two coordinates using Haversine formula
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
lat1, lon1: First coordinate pair
|
|
159
|
+
lat2, lon2: Second coordinate pair
|
|
160
|
+
unit: Distance unit ('km' or 'miles')
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
Distance in specified unit
|
|
164
|
+
"""
|
|
165
|
+
# Convert to radians
|
|
166
|
+
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])
|
|
167
|
+
|
|
168
|
+
# Haversine formula
|
|
169
|
+
dlat = lat2 - lat1
|
|
170
|
+
dlon = lon2 - lon1
|
|
171
|
+
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
|
|
172
|
+
c = 2 * math.asin(math.sqrt(a))
|
|
173
|
+
|
|
174
|
+
# Earth's radius
|
|
175
|
+
r = 6371 if unit == 'km' else 3956 # km or miles
|
|
176
|
+
|
|
177
|
+
return c * r
|
|
178
|
+
|
|
179
|
+
def get_grid_info(self, digipin_code: str) -> Dict:
|
|
180
|
+
"""
|
|
181
|
+
Get information about the DigiPin grid
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
digipin_code: The DigiPin code
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Dict containing grid information
|
|
188
|
+
"""
|
|
189
|
+
try:
|
|
190
|
+
coords = self.digipin_to_coordinates(digipin_code)
|
|
191
|
+
lat = coords['coordinates']['latitude']
|
|
192
|
+
lon = coords['coordinates']['longitude']
|
|
193
|
+
|
|
194
|
+
# Each DigiPin represents a 4x4 meter grid
|
|
195
|
+
grid_size_meters = 4
|
|
196
|
+
|
|
197
|
+
# Calculate approximate grid bounds
|
|
198
|
+
# 1 degree latitude ≈ 111,320 meters
|
|
199
|
+
# 1 degree longitude ≈ 111,320 * cos(latitude) meters
|
|
200
|
+
lat_offset = grid_size_meters / 111320
|
|
201
|
+
lon_offset = grid_size_meters / (111320 * math.cos(math.radians(lat)))
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
'digipin': digipin_code,
|
|
205
|
+
'center': {
|
|
206
|
+
'latitude': lat,
|
|
207
|
+
'longitude': lon
|
|
208
|
+
},
|
|
209
|
+
'bounds': {
|
|
210
|
+
'north': lat + lat_offset/2,
|
|
211
|
+
'south': lat - lat_offset/2,
|
|
212
|
+
'east': lon + lon_offset/2,
|
|
213
|
+
'west': lon - lon_offset/2
|
|
214
|
+
},
|
|
215
|
+
'grid_size_meters': grid_size_meters,
|
|
216
|
+
'area_square_meters': grid_size_meters * grid_size_meters,
|
|
217
|
+
'source': 'offline'
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
except Exception as e:
|
|
221
|
+
raise OfflineProcessingError(f"Failed to get grid info: {str(e)}")
|
|
222
|
+
|
|
223
|
+
def find_nearby_grids(
|
|
224
|
+
self,
|
|
225
|
+
latitude: float,
|
|
226
|
+
longitude: float,
|
|
227
|
+
radius_meters: int = 100
|
|
228
|
+
) -> List[Dict]:
|
|
229
|
+
"""
|
|
230
|
+
Find nearby DigiPin grids within a radius
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
latitude: Center latitude
|
|
234
|
+
longitude: Center longitude
|
|
235
|
+
radius_meters: Search radius in meters
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
List of nearby DigiPin codes with distances
|
|
239
|
+
"""
|
|
240
|
+
if radius_meters > 1000: # Limit to 1km for performance
|
|
241
|
+
raise ValidationError("Radius cannot exceed 1000 meters")
|
|
242
|
+
|
|
243
|
+
# Calculate grid step size (4 meters per grid)
|
|
244
|
+
grid_size = 4
|
|
245
|
+
steps = math.ceil(radius_meters / grid_size)
|
|
246
|
+
|
|
247
|
+
# 1 degree latitude ≈ 111,320 meters
|
|
248
|
+
lat_step = grid_size / 111320
|
|
249
|
+
lon_step = grid_size / (111320 * math.cos(math.radians(latitude)))
|
|
250
|
+
|
|
251
|
+
nearby_grids = []
|
|
252
|
+
|
|
253
|
+
for i in range(-steps, steps + 1):
|
|
254
|
+
for j in range(-steps, steps + 1):
|
|
255
|
+
test_lat = latitude + (i * lat_step)
|
|
256
|
+
test_lon = longitude + (j * lon_step)
|
|
257
|
+
|
|
258
|
+
# Calculate actual distance
|
|
259
|
+
distance = self.calculate_distance(latitude, longitude, test_lat, test_lon) * 1000 # Convert to meters
|
|
260
|
+
|
|
261
|
+
if distance <= radius_meters:
|
|
262
|
+
try:
|
|
263
|
+
result = self.coordinates_to_digipin(test_lat, test_lon)
|
|
264
|
+
nearby_grids.append({
|
|
265
|
+
'digipin': result['digipin'],
|
|
266
|
+
'coordinates': result['coordinates'],
|
|
267
|
+
'distance_meters': round(distance, 2)
|
|
268
|
+
})
|
|
269
|
+
except:
|
|
270
|
+
continue # Skip invalid coordinates
|
|
271
|
+
|
|
272
|
+
# Sort by distance and remove duplicates
|
|
273
|
+
seen = set()
|
|
274
|
+
unique_grids = []
|
|
275
|
+
for grid in sorted(nearby_grids, key=lambda x: x['distance_meters']):
|
|
276
|
+
if grid['digipin'] not in seen:
|
|
277
|
+
seen.add(grid['digipin'])
|
|
278
|
+
unique_grids.append(grid)
|
|
279
|
+
|
|
280
|
+
return unique_grids
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quantaroute-geocoding
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python SDK for QuantaRoute Geocoding API with offline DigiPin processing
|
|
5
|
+
Home-page: https://github.com/quantaroute/quantaroute-geocoding-python
|
|
6
|
+
Author: QuantaRoute
|
|
7
|
+
Author-email: QuantaRoute <support@quantaroute.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://quantaroute.com
|
|
10
|
+
Project-URL: Documentation, https://api.quantaroute.com/v1/digipin/docs
|
|
11
|
+
Project-URL: Repository, https://github.com/quantaroute/quantaroute-geocoding-python
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/quantaroute/quantaroute-geocoding-python/issues
|
|
13
|
+
Keywords: geocoding,digipin,gis,location,india,address,coordinates
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Requires-Python: >=3.7
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: requests>=2.25.0
|
|
30
|
+
Requires-Dist: pandas>=1.3.0
|
|
31
|
+
Requires-Dist: digipin>=1.0.0
|
|
32
|
+
Requires-Dist: tqdm>=4.60.0
|
|
33
|
+
Requires-Dist: click>=8.0.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
38
|
+
Requires-Dist: flake8>=3.8; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=0.910; extra == "dev"
|
|
40
|
+
Dynamic: author
|
|
41
|
+
Dynamic: home-page
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
Dynamic: requires-python
|
|
44
|
+
|
|
45
|
+
# QuantaRoute Geocoding Python SDK
|
|
46
|
+
|
|
47
|
+
A comprehensive Python library for geocoding addresses to DigiPin codes with both online API and offline processing capabilities.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- 🌐 **Online API Integration**: Full access to QuantaRoute Geocoding API
|
|
52
|
+
- 🔌 **Offline Processing**: Process coordinates ↔ DigiPin without internet
|
|
53
|
+
- 📊 **CSV Bulk Processing**: Handle large datasets efficiently
|
|
54
|
+
- 🚀 **CLI Tools**: Command-line interface for quick operations
|
|
55
|
+
- 📈 **Progress Tracking**: Real-time progress bars for bulk operations
|
|
56
|
+
- 🔄 **Retry Logic**: Automatic retry with exponential backoff
|
|
57
|
+
- 🎯 **Rate Limit Handling**: Intelligent rate limit management
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install quantaroute-geocoding
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For offline DigiPin processing, also install the official DigiPin library:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install digipin
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick Start
|
|
72
|
+
|
|
73
|
+
### Online API Usage
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from quantaroute_geocoding import QuantaRouteClient
|
|
77
|
+
|
|
78
|
+
# Initialize client
|
|
79
|
+
client = QuantaRouteClient(api_key="your-api-key")
|
|
80
|
+
|
|
81
|
+
# Geocode an address
|
|
82
|
+
result = client.geocode("India Gate, New Delhi, India")
|
|
83
|
+
print(f"DigiPin: {result['digipin']}")
|
|
84
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
85
|
+
|
|
86
|
+
# Convert coordinates to DigiPin
|
|
87
|
+
result = client.coordinates_to_digipin(28.6139, 77.2090)
|
|
88
|
+
print(f"DigiPin: {result['digipin']}")
|
|
89
|
+
|
|
90
|
+
# Reverse geocode DigiPin
|
|
91
|
+
result = client.reverse_geocode("39J-438-TJC7")
|
|
92
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Offline Processing
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from quantaroute_geocoding import OfflineProcessor
|
|
99
|
+
|
|
100
|
+
# Initialize offline processor
|
|
101
|
+
processor = OfflineProcessor()
|
|
102
|
+
|
|
103
|
+
# Convert coordinates to DigiPin (offline)
|
|
104
|
+
result = processor.coordinates_to_digipin(28.6139, 77.2090)
|
|
105
|
+
print(f"DigiPin: {result['digipin']}")
|
|
106
|
+
|
|
107
|
+
# Convert DigiPin to coordinates (offline)
|
|
108
|
+
result = processor.digipin_to_coordinates("39J-438-TJC7")
|
|
109
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
110
|
+
|
|
111
|
+
# Validate DigiPin format
|
|
112
|
+
result = processor.validate_digipin("39J-438-TJC7")
|
|
113
|
+
print(f"Valid: {result['isValid']}")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### CSV Bulk Processing
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from quantaroute_geocoding import CSVProcessor
|
|
120
|
+
|
|
121
|
+
# Initialize processor
|
|
122
|
+
processor = CSVProcessor(api_key="your-api-key")
|
|
123
|
+
|
|
124
|
+
# Process addresses to DigiPin
|
|
125
|
+
result = processor.process_geocoding_csv(
|
|
126
|
+
input_file="addresses.csv",
|
|
127
|
+
output_file="results.csv",
|
|
128
|
+
address_column="address"
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
print(f"Processed {result['total_rows']} rows")
|
|
132
|
+
print(f"Success rate: {result['success_rate']:.1%}")
|
|
133
|
+
|
|
134
|
+
# Process coordinates to DigiPin (can use offline mode)
|
|
135
|
+
processor_offline = CSVProcessor(use_offline=True)
|
|
136
|
+
result = processor_offline.process_coordinates_to_digipin_csv(
|
|
137
|
+
input_file="coordinates.csv",
|
|
138
|
+
output_file="digipins.csv"
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Command Line Interface
|
|
143
|
+
|
|
144
|
+
The package includes a powerful CLI for batch processing:
|
|
145
|
+
|
|
146
|
+
### Geocode addresses from CSV
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Using API
|
|
150
|
+
quantaroute-geocode geocode addresses.csv results.csv --api-key your-key
|
|
151
|
+
|
|
152
|
+
# With custom columns
|
|
153
|
+
quantaroute-geocode geocode data.csv output.csv \
|
|
154
|
+
--address-column street_address \
|
|
155
|
+
--city-column city_name \
|
|
156
|
+
--state-column state_name
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Convert coordinates to DigiPin
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Online processing
|
|
163
|
+
quantaroute-geocode coords-to-digipin coordinates.csv digipins.csv --api-key your-key
|
|
164
|
+
|
|
165
|
+
# Offline processing (no API key needed)
|
|
166
|
+
quantaroute-geocode coords-to-digipin coordinates.csv digipins.csv --offline
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Convert DigiPin to coordinates
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Online processing
|
|
173
|
+
quantaroute-geocode digipin-to-coords digipins.csv coordinates.csv --api-key your-key
|
|
174
|
+
|
|
175
|
+
# Offline processing
|
|
176
|
+
quantaroute-geocode digipin-to-coords digipins.csv coordinates.csv --offline
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Single operations
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Convert single coordinate to DigiPin
|
|
183
|
+
quantaroute-geocode single-coord-to-digipin 28.6139 77.2090 --offline
|
|
184
|
+
|
|
185
|
+
# Convert single DigiPin to coordinates
|
|
186
|
+
quantaroute-geocode single-digipin-to-coords "39J-438-TJC7" --offline
|
|
187
|
+
|
|
188
|
+
# Check API usage
|
|
189
|
+
quantaroute-geocode usage --api-key your-key
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## CSV File Formats
|
|
193
|
+
|
|
194
|
+
### Input CSV for Address Geocoding
|
|
195
|
+
|
|
196
|
+
```csv
|
|
197
|
+
address,city,state,pincode,country
|
|
198
|
+
"123 Main Street","New Delhi","Delhi","110001","India"
|
|
199
|
+
"456 Park Avenue","Mumbai","Maharashtra","400001","India"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Input CSV for Coordinates to DigiPin
|
|
203
|
+
|
|
204
|
+
```csv
|
|
205
|
+
latitude,longitude
|
|
206
|
+
28.6139,77.2090
|
|
207
|
+
19.0760,72.8777
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Input CSV for DigiPin to Coordinates
|
|
211
|
+
|
|
212
|
+
```csv
|
|
213
|
+
digipin
|
|
214
|
+
39J-438-TJC7
|
|
215
|
+
39J-49J-4867
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Advanced Features
|
|
219
|
+
|
|
220
|
+
### Webhook Management
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
# Register webhook
|
|
224
|
+
webhook = client.register_webhook(
|
|
225
|
+
url="https://your-app.com/webhook",
|
|
226
|
+
events=["bulk_processing.completed", "geocoding.completed"]
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
# List webhooks
|
|
230
|
+
webhooks = client.list_webhooks()
|
|
231
|
+
|
|
232
|
+
# Delete webhook
|
|
233
|
+
client.delete_webhook(webhook['id'])
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Batch Processing with Progress Callback
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
def progress_callback(processed, total, success, errors):
|
|
240
|
+
print(f"Progress: {processed}/{total} - Success: {success}, Errors: {errors}")
|
|
241
|
+
|
|
242
|
+
processor = CSVProcessor(api_key="your-key")
|
|
243
|
+
result = processor.process_geocoding_csv(
|
|
244
|
+
input_file="large_dataset.csv",
|
|
245
|
+
output_file="results.csv",
|
|
246
|
+
progress_callback=progress_callback
|
|
247
|
+
)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Offline Grid Operations
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
processor = OfflineProcessor()
|
|
254
|
+
|
|
255
|
+
# Get grid information
|
|
256
|
+
grid_info = processor.get_grid_info("39J-438-TJC7")
|
|
257
|
+
print(f"Grid center: {grid_info['center']}")
|
|
258
|
+
print(f"Grid bounds: {grid_info['bounds']}")
|
|
259
|
+
|
|
260
|
+
# Find nearby grids
|
|
261
|
+
nearby = processor.find_nearby_grids(28.6139, 77.2090, radius_meters=100)
|
|
262
|
+
for grid in nearby:
|
|
263
|
+
print(f"DigiPin: {grid['digipin']}, Distance: {grid['distance_meters']}m")
|
|
264
|
+
|
|
265
|
+
# Calculate distance between coordinates
|
|
266
|
+
distance = processor.calculate_distance(28.6139, 77.2090, 28.6150, 77.2100)
|
|
267
|
+
print(f"Distance: {distance:.2f} km")
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Configuration
|
|
271
|
+
|
|
272
|
+
### Environment Variables
|
|
273
|
+
|
|
274
|
+
Set your API key as an environment variable:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
export QUANTAROUTE_API_KEY="your-api-key"
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### API Configuration
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
client = QuantaRouteClient(
|
|
284
|
+
api_key="your-key",
|
|
285
|
+
base_url="https://api.quantaroute.com", # Custom base URL
|
|
286
|
+
timeout=30, # Request timeout in seconds
|
|
287
|
+
max_retries=3 # Maximum retry attempts
|
|
288
|
+
)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### CSV Processor Configuration
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
processor = CSVProcessor(
|
|
295
|
+
api_key="your-key",
|
|
296
|
+
use_offline=False, # Use offline processing when possible
|
|
297
|
+
batch_size=50, # Records per API batch
|
|
298
|
+
delay_between_batches=1.0 # Delay in seconds between batches
|
|
299
|
+
)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Error Handling
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from quantaroute_geocoding import (
|
|
306
|
+
QuantaRouteError,
|
|
307
|
+
APIError,
|
|
308
|
+
RateLimitError,
|
|
309
|
+
AuthenticationError,
|
|
310
|
+
ValidationError
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
try:
|
|
314
|
+
result = client.geocode("Invalid address")
|
|
315
|
+
except RateLimitError as e:
|
|
316
|
+
print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
|
|
317
|
+
except AuthenticationError:
|
|
318
|
+
print("Invalid API key")
|
|
319
|
+
except ValidationError as e:
|
|
320
|
+
print(f"Validation error: {e}")
|
|
321
|
+
except APIError as e:
|
|
322
|
+
print(f"API error: {e} (Status: {e.status_code})")
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Performance Tips
|
|
326
|
+
|
|
327
|
+
1. **Use Batch Processing**: Process multiple addresses in batches for better performance
|
|
328
|
+
2. **Offline Mode**: Use offline processing for coordinate ↔ DigiPin conversions
|
|
329
|
+
3. **Caching**: The API includes intelligent caching - repeated requests are faster
|
|
330
|
+
4. **Rate Limits**: The SDK handles rate limits automatically with retry logic
|
|
331
|
+
5. **CSV Processing**: Use the CSV processor for large datasets instead of individual API calls
|
|
332
|
+
|
|
333
|
+
## API Limits
|
|
334
|
+
|
|
335
|
+
| Tier | Requests/Minute | Monthly Limit | Batch Size |
|
|
336
|
+
|------|----------------|---------------|------------|
|
|
337
|
+
| Free | 10 | 1,000 | 50 |
|
|
338
|
+
| Paid | 100 | 10,000 | 100 |
|
|
339
|
+
| Enterprise | 1,000 | Unlimited | 100 |
|
|
340
|
+
|
|
341
|
+
## Support
|
|
342
|
+
|
|
343
|
+
- 📧 Email: support@quantaroute.com
|
|
344
|
+
- 🌐 Website: https://quantaroute.com
|
|
345
|
+
- 📖 API Documentation: https://api.quantaroute.com/v1/digipin/docs
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT License - see LICENSE file for details.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
quantaroute_geocoding/__init__.py,sha256=22lbjbaAk75zdndnWvU2lCyjlPnx2HPKrUuoYWkEnV0,688
|
|
2
|
+
quantaroute_geocoding/cli.py,sha256=kfVoKtBNC_jeAeqMeKRN5kxpwNEcPhnekTyLwZJFRw0,10626
|
|
3
|
+
quantaroute_geocoding/client.py,sha256=y6aAr5Ka1nlu2epw6rXxiJ8WQpOTAO7O-ef2Ww6EYtY,10644
|
|
4
|
+
quantaroute_geocoding/csv_processor.py,sha256=tmbtE1bQzi2TnKgxOGIQ-H6MWirh-cuG4RRErcCdfco,16096
|
|
5
|
+
quantaroute_geocoding/exceptions.py,sha256=rAkj8K5-AUf31kV8UlmNxQ5IN0m4CIL2qnI6ALas5Ys,1173
|
|
6
|
+
quantaroute_geocoding/offline.py,sha256=oY_sCFWKDes-yC7IQrgWcYxII8teUACBndEDjOXLZYw,9766
|
|
7
|
+
quantaroute_geocoding-1.0.0.dist-info/licenses/LICENSE,sha256=QY7Uoe-MPRTjfyyDM3HOnqtuSqbzyPLATiriEaQ9u90,1068
|
|
8
|
+
quantaroute_geocoding-1.0.0.dist-info/METADATA,sha256=3GgV9uz4RP7xH0hS1EErhokVMxJJwCNByd2JxoplerM,9545
|
|
9
|
+
quantaroute_geocoding-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
quantaroute_geocoding-1.0.0.dist-info/entry_points.txt,sha256=cniijgPLz_Pb6Fiti6aOxaJp1BB_bv60ZOL_oitGCx8,71
|
|
11
|
+
quantaroute_geocoding-1.0.0.dist-info/top_level.txt,sha256=_cyyFLwSH1wYB1HNs_LcZIDQRo1CnvoEsdnKz-cBCr4,22
|
|
12
|
+
quantaroute_geocoding-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 QuantaRoute
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
quantaroute_geocoding
|