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 \
--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.2.tar.gz (12.1 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.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for async_map_mongo-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6ff558530c1b5ae2909451a928117a085cc07b2e2bd8c3df5a4e24e66c73344d
MD5 c46a6610869e58f4c0fd3ec1ffa68961
BLAKE2b-256 b93d26c903a3f5079a8a032283a82e47071a1c47a95e49eb22e42457987a83fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for async_map_mongo-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54baba2411d5131e4e70e7b4368569d9f9b3462fbb3c13318b4525635f6f340c
MD5 c4934d3cd812f6998058ccbf7c677ed3
BLAKE2b-256 1cebeee1972354362b81d6ffe56849bcdda0dbab1a31c94bc0629025ccfb8b9a

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