Upgrade to Pro — share decks privately, control downloads, hide ads and more …

検証!会津は本当に地盤が硬いのか?

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for noharu36 noharu36
December 01, 2025

 検証!会津は本当に地盤が硬いのか?

Avatar for noharu36

noharu36

December 01, 2025
Tweet

More Decks by noharu36

Other Decks in Programming

Transcript

  1. 自己紹介 { name: 能島明希 handle: harukun origin: 広島->岡山->大阪->東京->会津 tech: {

    front-end: React+TS backend: Rust, Go etc: Rust, Haskell Rust: Rust } favorites: Game, Tobacco, BoyScout, Rust, Neovim Twitter(x): https://twitter.com/pieceofharuki Blog: https://zenn.dev/haru_blog }
  2. [dependencies] reqwest = { version = "0.12.9", features = ["json"]

    } tokio = { version = "1.41.1", features = ["full"] } serde = { version = "1.0.215", features = ["derive"] } serde_json = "1.0.133" chrono = {version = "0.4.38", features = ["serde"] } scraper = "0.21.0" plotters = "0.3.7" geojson = "0.24.1" geo-types = "0.7.14" 使用した外部クレート
  3. 説明 • requwest: HTTPリクエストを送信するためのライブラリ • tokio: 非同期処理をするためのライブラリ • serde, serde_json:

    シリアライズ、デシリアライズを行うためのライブラリ • chrono: 時刻を扱うライブラリ • scraper: スクレイピングをするためのライブラリ • plotters:いわゆる描画ライブラリ。いろんな形式をサポートしている • geojson: GeoJsonを読み込むためのライブラリ • geo-types: Rustで地理空間情報を扱うための基本的なデータ型と構造体を提供するライブラリ
  4. 気象庁の地震速報 参考: https://www.p2pquake.net/develop/json_api_v2 async fn main() -> Result<(), Box<dyn std::error::Error>>

    { create_point_list().await?; let url = "https://api.p2pquake.net/v2/jma/quake"; let params = [ ("limit", "100"), ("order", "-1"), ("quake_type", "ScalePrompt"), ("min_scale", "20"), ]; let client = reqwest::Client::new(); let response = client .get(url) .query(&params) .header("accept", "application/json") .send() .await?; let json: serde_json::Value = response.json().await?; let quakes = parse_json(json)?; Ok(()) } apiを叩いて、とってきたJsonをstructに変換する
  5. { "quakes": [ "Quake": { "time": "2024-12-09T21:00:00", "points": [ {

    "location": { "addr": "九戸郡洋野町種市第23地割27(洋野町役場種市庁舎)", "latitude": 40.40833333333333, "longitude": 141.71833333333333 }, "scale": 30 }, { "location": { "addr": "八幡平市大更第35地割62(旧八幡平市役所西根総合支所)", "latitude": 39.92666666666667, "longitude": 141.095 }, "scale": 30 } ] } ] } #[derive(Deserialize, Debug)] pub struct Quake { #[serde(deserialize_with = "deserialize_naive_date_time_from_str")] pub time: NaiveDateTime, #[serde(deserialize_with = "create_point")] pub points: Vec<Point>, } #[derive(Deserialize, Debug)] pub struct Point { pub location: Addr, pub scale: usize, } 取得したデータの例→
  6. なんとか解決しようと試みるも ... なんだか小島のあたりで縦線が沢山生じているので描画方法を変えてみた → うまく行きそうなので小島かどうかの判別(描画方法の決定) をする関数を書いた fn decide_area_or_line(v: &Vec<(f64, f64)>)

    -> bool { let (min_x, max_x, min_y, max_y) = v.iter().fold( (f64::INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::NEG_INFINITY), |(acc_min_x, acc_max_x, acc_min_y, acc_max_y), &(x, y)| { ( acc_min_x.min(x), acc_max_x.max(x), acc_min_y.min(y), acc_max_y.max(y), ) }, ); let diff_x = max_x - min_x; let diff_y = max_y - min_y; if diff_x >= 1.0 || diff_y >= 1.0 { return true } false }