Skip to main content

Asynchronously calls Amap's API to obtain corresponding latitude and longitude coordinates, with API call results stored in a MongoDB database. Provides functionality to query latitude and longitude from MongoDB and export to Excel.

Project description

简体中文

async-map-mongo

Asynchronously calls Amap's API to obtain corresponding latitude and longitude coordinates, with API call results stored in a MongoDB database. Provides functionality to query latitude and longitude from MongoDB and export to Excel.

Open Source Code Address: https://github.com/JieShenAI/async-map-mongo

Introduction

This package enables asynchronous calls to geocoding APIs (default: Amap API; extensible to Baidu Maps and more) to fetch latitude and longitude for addresses. It automates persists geocoding results (e.g., formatted address, country, province, city, coordinates) in MongoDB for efficient data retrieval.

Amap API call interface: https://restapi.amap.com/v3/geocode/geo?address=北京市朝阳区阜通东大街6号&output=XML&key=<user's key>

install

pip install async-map-mongo

Usage

The Amap API key can be stored in a .env file:

api_key=Amap API Key

Call the Amap API and save latitude and longitude information to MongoDB:

amap_insert \
--db_name map \
--collection_name amap \
--limiter_ratio 2.8 \
--address_min_length 5 \
--filename data/excel_name.xlsx \
--address_col_name address \
--max_addresses_num 1000 \

Collects all addresses from the "address" column, filters out addresses that do not exist in the database, and then calls Amap for the remaining addresses to obtain latitude and longitude.

  • filename: Excel or CSV file;
  • address_col_name: the attribute name corresponding to the address;
  • limiter_ratio: API call rate limit per second;
  • max_addresses_num: maximum of 1000 Amap API calls;
  • address_min_length: minimum length of a valid address; addresses with a string length less than address_min_length will not call the API;

Data format stored in the database:

Query latitude and longitude from MongoDB based on the provided table and export to Excel:

amap_export \
--db_name map \
--collection_name amap \
--address_min_length 5 \
--filename data/excel_name.xlsx \
--address_col_name address \
--output_type csv \
--output_dir output
  • address_clean: whether to remove text enclosed in Chinese parentheses in the address; true means remove, false means do not remove;
  • output_type: The format of the exported file, which defaults to csv. Only file extensions of csv and xlsx are supported.

API Call Extensibility

Although it supports Amap API for latitude and longitude calls by default, Baidu Maps can be used by changing the base_url parameter. For calls to other API interfaces and corresponding processing, please modify the code of AsyncMapCall.__call_api.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_map_mongo-0.0.4.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_map_mongo-0.0.4-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file async_map_mongo-0.0.4.tar.gz.

File metadata

  • Download URL: async_map_mongo-0.0.4.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for async_map_mongo-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c25795e8fa7d0cff8c085c51465c05d71fadef856ef021b902427a7a8422ed15
MD5 91d53d6f0571259bf19798a91ec56b03
BLAKE2b-256 a0df44dbb9bd4e10eea3332aeaace861a99364a953f27c7d67e8cd7c8ae00807

See more details on using hashes here.

File details

Details for the file async_map_mongo-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for async_map_mongo-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb8e9b85c41eeebf23438b57c6e6ab3227c79fa29e227cb15ec5ae8741bfeaa6
MD5 fb1de9109baf360c01733606f94bfbf2
BLAKE2b-256 2bd1ffba6f5f22a4b7c994fda6ce5486853710321633e1c253030a366a85fdb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page