現時点が、これがベースとなる座標 (2024/07/07)
var polygon = [][]float64{
{35.36394967, 139.61846500},
{35.3618532453048, 139.61890414751684}, // 変更 35.3618532453048, 139.61890414751684
{35.36170465505306, 139.6220415552594},
{35.36163108058289, 139.62334070015595},
{35.363117271878345, 139.62314221968566},
{35.36335187635167, 139.62481739887647},
{35.36310056060587, 139.62485183402688},
{35.36376860001917, 139.6288186562702},
{35.36420166714637, 139.6297897196359},
{35.36754482323006, 139.6296024603071},
{35.37126945661188, 139.62886244945108},
{35.37375189636854, 139.62615207124352},
{35.37464657021711, 139.623189740366},
{35.37574882601201, 139.6213765671167},
{35.37527643251494, 139.6210117866997},
{35.37306314467156, 139.6217413475337},
{35.37268696718477, 139.62013202216457},
{35.37018828750506, 139.61840497406456},
{35.370782160278, 139.61705458898427},
{35.36947068533102, 139.61641732865053},
{35.370596575495014, 139.61476348635583},
{35.37078029225879, 139.61403393574466},
{35.36864433631068, 139.61438212951467},
{35.36653571408147, 139.61453772192408},
{35.3633959839821, 139.61469428997398}, // 追加
{35.36351410, 139.61626070},
{35.36394967, 139.61846500},
}
(図面)F:\しゅらばしゅう\有吉先生データ\富岡エリア_座標.pptx
(コード) C:\Users\ebata\tomioka_school\src\trip_school\main.go
Polygon使う時の注意点(赤丸に注意: db.Query()で簡単にエラーにされる
// C:\Users\ebata\tomioka3B\src\others\main35.go
/*
実験用の座標を作る
修正後 (富岡西5丁目を削除し、富岡6丁目の下1/4を削除)
*/
package main
import (
"database/sql"
"fmt"
"log"
"regexp"
"strconv"
_ "github.com/lib/pq"
)
func main() {
// 取り扱うDBによってノード番号が代わるので注意すること
// 例えばtomioka_db_c とtomioka_dbは全く異なる
db, err := sql.Open("postgres",
"user=postgres password=password host=192.168.0.23 port=15432 dbname=tomioka_db sslmode=disable")
if err != nil {
log.Fatal("OpenError: ", err)
}
defer db.Close()
// 修正後のターゲットの富岡地区 (富岡西5丁目を削除し、富岡6丁目の下1/4を削除)
query := `
SELECT st_asText(
ST_GeneratePoints(
ST_GeomFromText(
'POLYGON((
35.36394967 139.61846500,
35.36216810 139.61890850,
35.36170465505306 139.6220415552594,
35.36163108058289 139.62334070015595,
35.363117271878345 139.62314221968566,
35.36335187635167 139.62481739887647,
35.36310056060587 139.62485183402688,
35.36376860001917 139.6288186562702,
35.36420166714637 139.6297897196359,
35.36754482323006 139.6296024603071,
35.37126945661188 139.62886244945108,
35.37375189636854 139.62615207124352,
35.37464657021711 139.623189740366,
35.37574882601201 139.6213765671167,
35.37527643251494 139.6210117866997,
35.37306314467156 139.6217413475337,
35.37268696718477 139.62013202216457,
35.37018828750506 139.61840497406456,
35.370782160278 139.61705458898427,
35.36947068533102 139.61641732865053,
35.370596575495014 139.61476348635583,
35.37078029225879 139.61403393574466,
35.36864433631068 139.61438212951467,
35.36653571408147 139.61453772192408,
35.36394967 139.61846500
))'
),
25)
)
`
rows, err := db.Query(query) // この25が生成する乱数座標
if err != nil {
log.Fatal(err)
}
defer rows.Close()
var msg string
for rows.Next() {
if err := rows.Scan(&msg); err != nil {
fmt.Println(err)
}
// まずはMULTIPOINTをバラバラに分解する
arr1 := regexp.MustCompile("[() ,]").Split(msg, -1) // '('か、')'か、' 'か、","で分割する → "[中身]" という構造でまぎらわしい
// 2つの値を一度に取得する (最初の値" MULTIPOIN"をスキップする為に、i:=1から始める)
for i := 1; i < len(arr1); i += 2 {
// arr1[i]とarr1[i+1]は2つの値を表します
if i+1 < len(arr1) {
value1, _ := strconv.ParseFloat(arr1[i], 64) // 乱数の緯度
value2, _ := strconv.ParseFloat(arr1[i+1], 64) // 乱数の経度
fmt.Println(value1, value2)
}
}
}
}