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.3.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.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_map_mongo-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c003ca06785a777aa33d8a2d7c570e8c4cf519b3f7d80255df99b03ca2db4d9a
MD5 dbae9e26e3fac3c6f75fdc084a30990e
BLAKE2b-256 d84b08f93ca49d733b74493903036cf50c6c2134afc0601865be3081cce6592a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for async_map_mongo-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 51f0d3ebbc903af26078a16d9d18d04026d5948ba5dbf24a7a24294d1689452b
MD5 122f128635b248be99590b25f55522ac
BLAKE2b-256 89387446aea4a4569aa88321e1d8f58da476a0c1b5a013df9ef8e018801b4732

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