quantaroute-geocoding 1.0.0__tar.gz
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-1.0.0/LICENSE +21 -0
- quantaroute_geocoding-1.0.0/MANIFEST.in +5 -0
- quantaroute_geocoding-1.0.0/PKG-INFO +349 -0
- quantaroute_geocoding-1.0.0/README.md +305 -0
- quantaroute_geocoding-1.0.0/pyproject.toml +59 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/__init__.py +32 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/cli.py +281 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/client.py +312 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/csv_processor.py +415 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/exceptions.py +42 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding/offline.py +280 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/PKG-INFO +349 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/SOURCES.txt +17 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/dependency_links.txt +1 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/entry_points.txt +2 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/requires.txt +12 -0
- quantaroute_geocoding-1.0.0/quantaroute_geocoding.egg-info/top_level.txt +1 -0
- quantaroute_geocoding-1.0.0/setup.cfg +4 -0
- quantaroute_geocoding-1.0.0/setup.py +56 -0
|
@@ -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,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,305 @@
|
|
|
1
|
+
# QuantaRoute Geocoding Python SDK
|
|
2
|
+
|
|
3
|
+
A comprehensive Python library for geocoding addresses to DigiPin codes with both online API and offline processing capabilities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌐 **Online API Integration**: Full access to QuantaRoute Geocoding API
|
|
8
|
+
- 🔌 **Offline Processing**: Process coordinates ↔ DigiPin without internet
|
|
9
|
+
- 📊 **CSV Bulk Processing**: Handle large datasets efficiently
|
|
10
|
+
- 🚀 **CLI Tools**: Command-line interface for quick operations
|
|
11
|
+
- 📈 **Progress Tracking**: Real-time progress bars for bulk operations
|
|
12
|
+
- 🔄 **Retry Logic**: Automatic retry with exponential backoff
|
|
13
|
+
- 🎯 **Rate Limit Handling**: Intelligent rate limit management
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install quantaroute-geocoding
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For offline DigiPin processing, also install the official DigiPin library:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install digipin
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Online API Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from quantaroute_geocoding import QuantaRouteClient
|
|
33
|
+
|
|
34
|
+
# Initialize client
|
|
35
|
+
client = QuantaRouteClient(api_key="your-api-key")
|
|
36
|
+
|
|
37
|
+
# Geocode an address
|
|
38
|
+
result = client.geocode("India Gate, New Delhi, India")
|
|
39
|
+
print(f"DigiPin: {result['digipin']}")
|
|
40
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
41
|
+
|
|
42
|
+
# Convert coordinates to DigiPin
|
|
43
|
+
result = client.coordinates_to_digipin(28.6139, 77.2090)
|
|
44
|
+
print(f"DigiPin: {result['digipin']}")
|
|
45
|
+
|
|
46
|
+
# Reverse geocode DigiPin
|
|
47
|
+
result = client.reverse_geocode("39J-438-TJC7")
|
|
48
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Offline Processing
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from quantaroute_geocoding import OfflineProcessor
|
|
55
|
+
|
|
56
|
+
# Initialize offline processor
|
|
57
|
+
processor = OfflineProcessor()
|
|
58
|
+
|
|
59
|
+
# Convert coordinates to DigiPin (offline)
|
|
60
|
+
result = processor.coordinates_to_digipin(28.6139, 77.2090)
|
|
61
|
+
print(f"DigiPin: {result['digipin']}")
|
|
62
|
+
|
|
63
|
+
# Convert DigiPin to coordinates (offline)
|
|
64
|
+
result = processor.digipin_to_coordinates("39J-438-TJC7")
|
|
65
|
+
print(f"Coordinates: {result['coordinates']}")
|
|
66
|
+
|
|
67
|
+
# Validate DigiPin format
|
|
68
|
+
result = processor.validate_digipin("39J-438-TJC7")
|
|
69
|
+
print(f"Valid: {result['isValid']}")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### CSV Bulk Processing
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from quantaroute_geocoding import CSVProcessor
|
|
76
|
+
|
|
77
|
+
# Initialize processor
|
|
78
|
+
processor = CSVProcessor(api_key="your-api-key")
|
|
79
|
+
|
|
80
|
+
# Process addresses to DigiPin
|
|
81
|
+
result = processor.process_geocoding_csv(
|
|
82
|
+
input_file="addresses.csv",
|
|
83
|
+
output_file="results.csv",
|
|
84
|
+
address_column="address"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
print(f"Processed {result['total_rows']} rows")
|
|
88
|
+
print(f"Success rate: {result['success_rate']:.1%}")
|
|
89
|
+
|
|
90
|
+
# Process coordinates to DigiPin (can use offline mode)
|
|
91
|
+
processor_offline = CSVProcessor(use_offline=True)
|
|
92
|
+
result = processor_offline.process_coordinates_to_digipin_csv(
|
|
93
|
+
input_file="coordinates.csv",
|
|
94
|
+
output_file="digipins.csv"
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Command Line Interface
|
|
99
|
+
|
|
100
|
+
The package includes a powerful CLI for batch processing:
|
|
101
|
+
|
|
102
|
+
### Geocode addresses from CSV
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Using API
|
|
106
|
+
quantaroute-geocode geocode addresses.csv results.csv --api-key your-key
|
|
107
|
+
|
|
108
|
+
# With custom columns
|
|
109
|
+
quantaroute-geocode geocode data.csv output.csv \
|
|
110
|
+
--address-column street_address \
|
|
111
|
+
--city-column city_name \
|
|
112
|
+
--state-column state_name
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Convert coordinates to DigiPin
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Online processing
|
|
119
|
+
quantaroute-geocode coords-to-digipin coordinates.csv digipins.csv --api-key your-key
|
|
120
|
+
|
|
121
|
+
# Offline processing (no API key needed)
|
|
122
|
+
quantaroute-geocode coords-to-digipin coordinates.csv digipins.csv --offline
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Convert DigiPin to coordinates
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Online processing
|
|
129
|
+
quantaroute-geocode digipin-to-coords digipins.csv coordinates.csv --api-key your-key
|
|
130
|
+
|
|
131
|
+
# Offline processing
|
|
132
|
+
quantaroute-geocode digipin-to-coords digipins.csv coordinates.csv --offline
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Single operations
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Convert single coordinate to DigiPin
|
|
139
|
+
quantaroute-geocode single-coord-to-digipin 28.6139 77.2090 --offline
|
|
140
|
+
|
|
141
|
+
# Convert single DigiPin to coordinates
|
|
142
|
+
quantaroute-geocode single-digipin-to-coords "39J-438-TJC7" --offline
|
|
143
|
+
|
|
144
|
+
# Check API usage
|
|
145
|
+
quantaroute-geocode usage --api-key your-key
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## CSV File Formats
|
|
149
|
+
|
|
150
|
+
### Input CSV for Address Geocoding
|
|
151
|
+
|
|
152
|
+
```csv
|
|
153
|
+
address,city,state,pincode,country
|
|
154
|
+
"123 Main Street","New Delhi","Delhi","110001","India"
|
|
155
|
+
"456 Park Avenue","Mumbai","Maharashtra","400001","India"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Input CSV for Coordinates to DigiPin
|
|
159
|
+
|
|
160
|
+
```csv
|
|
161
|
+
latitude,longitude
|
|
162
|
+
28.6139,77.2090
|
|
163
|
+
19.0760,72.8777
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Input CSV for DigiPin to Coordinates
|
|
167
|
+
|
|
168
|
+
```csv
|
|
169
|
+
digipin
|
|
170
|
+
39J-438-TJC7
|
|
171
|
+
39J-49J-4867
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Advanced Features
|
|
175
|
+
|
|
176
|
+
### Webhook Management
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
# Register webhook
|
|
180
|
+
webhook = client.register_webhook(
|
|
181
|
+
url="https://your-app.com/webhook",
|
|
182
|
+
events=["bulk_processing.completed", "geocoding.completed"]
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# List webhooks
|
|
186
|
+
webhooks = client.list_webhooks()
|
|
187
|
+
|
|
188
|
+
# Delete webhook
|
|
189
|
+
client.delete_webhook(webhook['id'])
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Batch Processing with Progress Callback
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
def progress_callback(processed, total, success, errors):
|
|
196
|
+
print(f"Progress: {processed}/{total} - Success: {success}, Errors: {errors}")
|
|
197
|
+
|
|
198
|
+
processor = CSVProcessor(api_key="your-key")
|
|
199
|
+
result = processor.process_geocoding_csv(
|
|
200
|
+
input_file="large_dataset.csv",
|
|
201
|
+
output_file="results.csv",
|
|
202
|
+
progress_callback=progress_callback
|
|
203
|
+
)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Offline Grid Operations
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
processor = OfflineProcessor()
|
|
210
|
+
|
|
211
|
+
# Get grid information
|
|
212
|
+
grid_info = processor.get_grid_info("39J-438-TJC7")
|
|
213
|
+
print(f"Grid center: {grid_info['center']}")
|
|
214
|
+
print(f"Grid bounds: {grid_info['bounds']}")
|
|
215
|
+
|
|
216
|
+
# Find nearby grids
|
|
217
|
+
nearby = processor.find_nearby_grids(28.6139, 77.2090, radius_meters=100)
|
|
218
|
+
for grid in nearby:
|
|
219
|
+
print(f"DigiPin: {grid['digipin']}, Distance: {grid['distance_meters']}m")
|
|
220
|
+
|
|
221
|
+
# Calculate distance between coordinates
|
|
222
|
+
distance = processor.calculate_distance(28.6139, 77.2090, 28.6150, 77.2100)
|
|
223
|
+
print(f"Distance: {distance:.2f} km")
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Configuration
|
|
227
|
+
|
|
228
|
+
### Environment Variables
|
|
229
|
+
|
|
230
|
+
Set your API key as an environment variable:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
export QUANTAROUTE_API_KEY="your-api-key"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### API Configuration
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
client = QuantaRouteClient(
|
|
240
|
+
api_key="your-key",
|
|
241
|
+
base_url="https://api.quantaroute.com", # Custom base URL
|
|
242
|
+
timeout=30, # Request timeout in seconds
|
|
243
|
+
max_retries=3 # Maximum retry attempts
|
|
244
|
+
)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### CSV Processor Configuration
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
processor = CSVProcessor(
|
|
251
|
+
api_key="your-key",
|
|
252
|
+
use_offline=False, # Use offline processing when possible
|
|
253
|
+
batch_size=50, # Records per API batch
|
|
254
|
+
delay_between_batches=1.0 # Delay in seconds between batches
|
|
255
|
+
)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Error Handling
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
from quantaroute_geocoding import (
|
|
262
|
+
QuantaRouteError,
|
|
263
|
+
APIError,
|
|
264
|
+
RateLimitError,
|
|
265
|
+
AuthenticationError,
|
|
266
|
+
ValidationError
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
result = client.geocode("Invalid address")
|
|
271
|
+
except RateLimitError as e:
|
|
272
|
+
print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
|
|
273
|
+
except AuthenticationError:
|
|
274
|
+
print("Invalid API key")
|
|
275
|
+
except ValidationError as e:
|
|
276
|
+
print(f"Validation error: {e}")
|
|
277
|
+
except APIError as e:
|
|
278
|
+
print(f"API error: {e} (Status: {e.status_code})")
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Performance Tips
|
|
282
|
+
|
|
283
|
+
1. **Use Batch Processing**: Process multiple addresses in batches for better performance
|
|
284
|
+
2. **Offline Mode**: Use offline processing for coordinate ↔ DigiPin conversions
|
|
285
|
+
3. **Caching**: The API includes intelligent caching - repeated requests are faster
|
|
286
|
+
4. **Rate Limits**: The SDK handles rate limits automatically with retry logic
|
|
287
|
+
5. **CSV Processing**: Use the CSV processor for large datasets instead of individual API calls
|
|
288
|
+
|
|
289
|
+
## API Limits
|
|
290
|
+
|
|
291
|
+
| Tier | Requests/Minute | Monthly Limit | Batch Size |
|
|
292
|
+
|------|----------------|---------------|------------|
|
|
293
|
+
| Free | 10 | 1,000 | 50 |
|
|
294
|
+
| Paid | 100 | 10,000 | 100 |
|
|
295
|
+
| Enterprise | 1,000 | Unlimited | 100 |
|
|
296
|
+
|
|
297
|
+
## Support
|
|
298
|
+
|
|
299
|
+
- 📧 Email: support@quantaroute.com
|
|
300
|
+
- 🌐 Website: https://quantaroute.com
|
|
301
|
+
- 📖 API Documentation: https://api.quantaroute.com/v1/digipin/docs
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT License - see LICENSE file for details.
|