以下のクエリは、潜在的な各場所を調べ、H3 ヘキサゴン で定義され、H3 Hex ID で識別される周辺地域の平均アクティビティインデックスを決定します。都市は地理的に複雑な分析領域であり、ヘキサゴンを使用すると、選択とフィルタリングのための一貫した識別子を保持しながら、同等のサイズと形状でこれらの領域を調べることができます。 まず、レストランのランチタイムのピークである正午の平日を見てみましょう。調べる曜日と時刻は、ON ステートメントで指定します。
select AVG(movement.activity_index_total) as avgMovement,bqcarto.h3.ST_ASH3(ST_GEOGPOINT(restLocs.lng,restLocs.lat), 9) as hexid,restLocs.address_name FROM `movement-307122.mapBoxSampleData.portlandMovementHourly` as movement join `movement-307122.mapBoxSampleData.restaurantLocations` as restLocson ST_WITHIN( ``` --this will select all the movement points that are within the HEX boundary ``` ST_GEOGPOINT(movement.xlon,movement.xlat),``` --ST_GEOPOINT turns the lat/long into point for use in the ST_WITHIN ``` bqcarto.h3.ST_BOUNDARY(bqcarto.h3.ST_ASH3(ST_GEOGPOINT(restLocs.lng,restLocs.lat), 9))) ``` -- get the geometry for the HEX. 9 is the H3 cell resolution``` where movement.agg_day_period = 0 and movement.agg_time_period = 12 ```-- 0 for agg day period is weekday, 12 for agg time period is 12:00 ``` group by hexid, restLocs.address_name order by avgMovement
select AVG(movement.activity_index_total) as avgMovement,bqcarto.h3.ST_ASH3(ST_GEOGPOINT(restLocs.lng,restLocs.lat), 9) as hexid,restLocs.address_name FROM `movement-307122.mapBoxSampleData.portlandMovementHourly` as movement join `movement-307122.mapBoxSampleData.restaurantLocations` as restLocson ST_WITHIN( ``` --this will select all the movement points that are within the HEX boundary ``` ST_GEOGPOINT(movement.xlon,movement.xlat),``` --ST_GEOPOINT turns the lat/long into point for use in the ST_WITHIN ``` bqcarto.h3.ST_BOUNDARY(bqcarto.h3.ST_ASH3(ST_GEOGPOINT(restLocs.lng,restLocs.lat), 9))) ``` -- get the geometry for the HEX. 9 is the H3 cell resolution``` where movement.agg_day_period = 0 and movement.agg_time_period = 18 ```-- 0 for agg day period is weekday, 18 for agg time period is 18:00 ``` group by hexid, restLocs.address_name order by avgMovement
そして、こちらが結果です。9225 SW Allen Rdの周辺が夕食時に最も混雑することがわかります。
BigQueryのMapbox Movementからの洞察を使用して、新しいレストランに最適な場所として9225 SW Allen Rdを特定しました。この場所は、ディナーサービスの平均アクティビティが最も高く、ランチサービスでも上位3位に入っています。 BigQueryの初心者の方は、基本についてクイックスタートガイドをご覧ください。この投稿からのサンプルデータは、パブリックGoogle Cloud Bucketで入手できるようにしました。これにより、開発者はテーブルを作成し、これらのクエリを以下に示すように正確に実行できます: