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>

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 \
--address_clean true \
--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 \
--address_clean true \
--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.1.tar.gz (11.9 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.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for async_map_mongo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c132467a24c03b63132cd838438ff5bd1c87b198c54315062354560fcd9e1d19
MD5 536e320e2031e37e4d5d67ecb383dfc2
BLAKE2b-256 1f84ecab7cf2bcf347a2e1b706f21ee3729d35cba8cea0393ec6b3940ec9b68c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for async_map_mongo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 250dbab7fd401925e53a39012977dd0cbac8552d277b62c3fc6a5e8f86fd9ed2
MD5 803c2b3ab7a6f57b7f6b8bdd87d53424
BLAKE2b-256 3550fc0b679d2edd50a97a5d587b6a489a03e5078722d81638bd8841b5968e33

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