0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Mapbox Studio のデータアップロード方法、Datasets API もあるよ!

0
Last updated at Posted at 2023-12-15

データのアップロード方法

Mapbox に GeoJSON などのデータをアップロードする方法はいくつかあります。
過去の記事では、Web UI(Mapbox Studio)からアップロードする手順を紹介しました。

🔗 過去記事:MapboxにGeoJSONをアップロードする方法(Qiita)


Datasets API を使ったアップロード方法

今回は、Mapbox Datasets API を使ってプログラムからデータをアップロードする方法を紹介します。
自動化したい場合や、定期的にデータを更新したい場合に便利です。

📘 Mapbox Datasets API ドキュメント

以下は Python を使ったサンプルコードです。

upload.py
import mapbox
from mapbox import Uploader

# 1. Mapboxアクセストークンを設定
access_token = 'YOUR_MAPBOX_ACCESS_TOKEN'
mapbox.config.update(access_token=access_token)

# 2. アップロードするファイルのパス
file_path = 'path/to/your/file.geojson'

# 3. Uploader インスタンスを作成
uploader = Uploader()

# 4. アップロード先タイルセットのID(username.tileset_id 形式)
tileset = 'your_mapbox_username.tileset_id'

# 5. ファイルを開いてアップロード実行
with open(file_path, 'rb') as src:
    upload_resp = uploader.upload(src, tileset)

# 6. レスポンスを確認
print(upload_resp.status_code)
print(upload_resp.json())

アップロードが成功すると、status_code201 を返し、タイルセットIDやジョブステータスなどが JSON で表示されます。
このタイルセットは Mapbox Studio の「Tilesets」からも確認できます。


🧩 補足:

  • GeoJSON 以外に .csv.tif なども対応しています。
  • 定期更新する場合は、スクリプトを定期実行(例:AWS Lambda や GitHub Actions)に組み込むのがおすすめです。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?