コンテンツにスキップ

GeoRectBounds(矩形範囲)

GeoRectBounds は、南西と北東の角の点で定義される矩形の地理的エリアを表します。地図領域の定義、グラウンドイメージの境界、ビューポート計算に使用されます。

class GeoRectBounds(
southWest: GeoPoint? = null,
northEast: GeoPoint? = null
)
  • southWest: GeoPoint?: 矩形の南西角(左下)
  • northEast: GeoPoint?: 矩形の北東角(右上)
  • isEmpty: Boolean: 境界が定義されていない場合は true を返します
  • center: GeoPoint?: 境界の中心点
  • toSpan(): GeoPoint?: GeoPointInterface として範囲(幅/高さ)を返します
// 矩形エリアを定義
val bounds = GeoRectBounds(
southWest = GeoPoint.fromLatLong(37.7649, -122.4294),
northeast = GeoPoint.fromLatLong(37.7849, -122.4094)
)
// 空の境界(後で拡張)
val bounds = GeoRectBounds()

境界は新しい点を含むように動的に拡張できます:

fun extend(point: GeoPointInterface)
// 使用例
val bounds = GeoRectBounds() // 空からスタート
val points = listOf(
GeoPoint.fromLatLong(37.7749, -122.4194),
GeoPoint.fromLatLong(37.7849, -122.4094),
GeoPoint.fromLatLong(37.7649, -122.4294)
)
points.forEach { point ->
bounds.extend(point) // 各点を含むように境界が拡大
}
println("最終境界: $bounds")
val bounds1 = GeoRectBounds(
southWest = GeoPoint.fromLatLong(37.7649, -122.4294),
northEast = GeoPoint.fromLatLong(37.7749, -122.4194)
)
val bounds2 = GeoRectBounds(
southWest = GeoPoint.fromLatLong(37.7749, -122.4194),
northEast = GeoPoint.fromLatLong(37.7849, -122.4094)
)
val combinedBounds = bounds1.union(bounds2) // 両方のエリアを含む
fun contains(point: GeoPointInterface): Boolean
// Usage
val bounds = GeoRectBounds(
southWest = GeoPoint.fromLatLong(37.7649, -122.4294),
northEast = GeoPoint.fromLatLong(37.7849, -122.4094)
)
val testPoint = GeoPoint.fromLatLong(37.7749, -122.4194)
val isInside = bounds.contains(testPoint)
println("Point is inside bounds: $isInside")
fun intersects(other: GeoRectBounds): Boolean
// Usage
val bounds1 = GeoRectBounds(/* ... */)
val bounds2 = GeoRectBounds(/* ... */)
val doIntersect = bounds1.intersects(bounds2)
println("Bounds intersect: $doIntersect")

GeoRectBounds は国際日付変更線(経度 ±180°)をまたぐ矩形を処理します:

// Bounds crossing the date line
val pacificBounds = GeoRectBounds(
southWest = GeoPoint.fromLatLong(20, 170), // West of date line
northEast = GeoPoint.fromLatLong(40, -170) // East of date line
)
val pointInPacific = GeoPoint.fromLatLong(30, 175)
val containsPoint = pacificBounds.contains(pointInPacific) // true
val emptyBounds = GeoRectBounds()
println(emptyBounds.isEmpty) // true
println(emptyBounds.center) // null
println(emptyBounds.toSpan()) // null
// Extending empty bounds
emptyBounds.extend(GeoPoint.fromLatLong(37.7749, -122.4194))
println(emptyBounds.isEmpty) // false
// For debugging
val bounds = GeoRectBounds(
southWest = GeoPoint.fromLatLong(37.7649, -122.4294),
northEast = GeoPoint.fromLatLong(37.7849, -122.4094)
)
println(bounds.toString())
// Output: ((37.7649, -122.4294), (37.7849, -122.4094))
fun toUrlValue(precision: Int = 6): String
// Usage for API calls
val urlString = bounds.toUrlValue() // "37.764900,-122.429400,37.784900,-122.409400"
val preciseString = bounds.toUrlValue(precision = 8)
fun equalsTo(other: GeoRectBounds): Boolean
// 使用例
val bounds1 = GeoRectBounds(/* ... */)
val bounds2 = GeoRectBounds(/* ... */)
val areEqual = bounds1.equalsTo(bounds2)