2023,江端さんの技術メモ

A社 CSVファイルパース用テストコード (用事が終わったら消すこと)

package main

import (
	"encoding/csv"
	"fmt"
	"log"
	"os"
	"regexp"
	"strings"
)

func main() {

	file, err := os.Open("tracking_data.csv") 
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	r := csv.NewReader(file)
	rows, err := r.ReadAll() // csvを一度に全て読み込む
	if err != nil {
		log.Fatal(err)
	}

	lat := [10000]string{}
	lng := [10000]string{}
	speed := [10000]string{}

	// [][]stringなのでループする
	for j, v := range rows {

		if j == 0 {
			continue // CSVのヘッダー行を無視
		}

		//fmt.Println(v[3])
		// v[3]をバラバラに分解する
		// v3 := regexp.MustCompile("[() ,]").Split(v[3], -1)
		v3 := regexp.MustCompile("}, {").Split(v[3], -1)

		for i, s := range v3 { // i: 数
			//fmt.Printf("%s\n", s)
			v31 := strings.Replace(s, "\"lat\": ", "", -1)
			v32 := strings.Replace(v31, "\"lng\": ", "", -1)
			v33 := strings.Replace(v32, "[{", "", -1)
			v34 := strings.Replace(v33, "}]", "", -1)

			v35 := regexp.MustCompile(",").Split(v34, -1)

			for k, s5 := range v35 {

				//f64, _ := strconv.ParseFloat(s5, 64)
				//fmt.Println("string", i, s5)
				if k == 0 {
					lat[i] = s5
				} else {
					lng[i] = s5
				}
			}

		}

		//fmt.Println(lat[0], lng[0], lat[19], lng[19])
		//fmt.Println()

		// v[4]をバラバラに分解する
		v41 := strings.Replace(v[4], "[", "", -1)
		v42 := strings.Replace(v41, "]", "", -1)
		v43 := regexp.MustCompile(",").Split(v42, -1)

		for k4, s4 := range v43 {
			speed[k4] = s4

			fmt.Println(k4, ",", lat[k4], ",", lng[k4], ",", speed[k4])

		}

	}
}

2023,江端さんの忘備録

先日、家族で金沢旅行に行ってきました。

I recently took a trip to Kanazawa with my family.

もはや、めったなことでは家族全員での集合の機会はありません。

The whole family can no longer gather together on rare occasions.

今回の旅行がファイナルかもしれませんが、まあ、そういうものでしょう。

This trip may be the final one, but that's okay.

-----

もはや、全員が成人になっていますので、居酒屋でのネタにも制限はありません。

Since we are all adults now, there are no longer any restrictions on the stories we can tell in the pub.

マッチングアプリの活用方法などを含め、赤裸々な話を聞かされました。

I heard some naked stories about how to use matching apps.

まあ、私は、ノンアルコールビールを飲みながら、だまって聞き流していました(体調が悪く、ノドも潰していたので)。

Well, I just sat back and listened while drinking my non-alcoholic beer (I was sick and my throat was crushed).

-----

話題が『人生で、目もくらむほどの幸福感に浸ったことがあるか』というネタになった時です。

This is when the topic turned to a story about 'Have you ever been dazzlingly happy in your life?'

私は「大学院で自分の好きな研究を続けていたとき、ときどき幸せを感じていた」という話をしたのですが、

I told them that I sometimes felt happy when I was in graduate school continuing my own favorite research, however,

嫁さんと長女は、「恋愛一択」でした。

My wife and senior daughter chose "love affair" only and said,

―― 道行く人々の全てに声をかけて、この幸せを分けてやりたいと思うほどの幸せな気持ちになった

"They felt so happy that they wanted to call out to all the people on the street and share this happiness with them"

のだそうです。

二人で『そう!そうだよ!!』と盛り上がっていたので、客観的な事実であるようです。

They both said, 'Yes! Yes!!!' ' and they were so excited, so it seems to be an objective fact.

次女は、「よく分からん」といった風だったようですし、私に至っては、全く分かりませんでしたが。

My junior daughter seemed to be "I don't really understand," and I didn't understand at all either.

-----

で、ふと思い出したのが、これ、です。

And then I suddenly remembered this

『ええ、毎日、目が眩むほど幸せです。あなたは違うのですか?』と、気の毒そうな顔をして相手を見てやれば、大体、呆然として立ちすくんでいました。

カルト宗教が、『道行く人々の全てに声をかけて、この幸せを分けてやりたいと思うほどの幸せな気持ち』になれるものであるなら、その価値はあるのかもしれない ――

If a cult is something that makes them 'so happy that they want to call out to all the people on the street and share this happiness with them', then maybe it's worth it....

と、一瞬、思いかけましたが、直ぐに取り下げました。

For a moment, I almost thought that, but I immediately withdrew the idea.

嫁さんと長女の、大切な思い出を『汚された』ような気になったからです。

I felt like I was 'tarnishing' the precious memories of my wife and senior daughter.

-----

今度、街で『あなたは、今、幸せですか』と尋ねられたら、

The next time someone on the street asks me, 'Are you happy right now?'

―― 間髪入れずに、顔面パンチを食らわせてやろう

"I'll punch him/her in the face in no time"

という気持ちになっています。

I have come to think that.

2023,江端さんの忘備録

「サマータイムレンダ」も、「シュタインズゲート」も、ぶっちゃけ荒唐無稽な設定のSFです。

Both "Summertime Render" and "Steinsgate" are, to put it bluntly, science fiction with ridiculous settings.

それでもなお、私がこの2つの作品に魅了される理由は、

Still, I'm still fascinated by these two pieces for a reason.

―― 物語全体に課せられた厳しい時空間のルール

"Strict space-time rules imposed on the entire story"

の設定があるからですね。

That's because of its setting.

時空間を自由自在にコントロールできる存在に対して、3次元空間に拘束されている私たちは、必ず負ける運命にあるはずです。

Against beings who can control space-time at will, we, who are bound in three-dimensional space, must surely be doomed to defeat.

ところが、その厳しいルールの「裏をかく」「組み合わせる」ことで、思いもつかなかった『時空間世界のルールの抜け道』を探し続ける主人公たちの闘いに、私は胸を打たれるのです。

However, I am struck by the struggle of the protagonists who continue to search for "loopholes in the rules of the space-time world" that I had never thought of by "going behind" and "combining" those strict rules.

『そんなやり方があったか!』という驚きに浸れることは、本当に幸せです。

I'm so happy to be able to amaze with saying "I didn't know there was such a way to do that!"

-----

皆さんにお願いがあります。

I have a favor to ask of you all (Warning: jump to Youtube)

この網代慎平のノートの写し、手に入りませんか?(注意:Youtubeに飛びます)。

Can I get a copy of this Shinpei Ajiro's notes? (Warning: jump to Youtube).

コミックの方に記載があるなら、購入します。

If the comic is mentioned, I will buy it.

よろしくお願い致します。

Thank you for your cooperation.

2023,江端さんの忘備録

『数百からなるセンサデータと、その組み合わせからなるリアルタイムのチェックプログラムが、ロケットのリフトアップ前に、エンジン点火を自動停止させた』

"A real-time checking program consisting of hundreds of sensor data and their combination automatically shut down the engine ignition before the rocket lifted off"

これを、科学というプロセスをきちんと理解している人間であれば、

If one has a proper understanding of the scientific process, one would say,

「それは一般的に"失敗"とはいいません」

"That is not generally called a 'failure'"

私が勤務している会社で、これを"失敗"などと言ったら、ほぼ100%"ポカーン"とされる、と思う。

If I call this a "failure" at the company I work for, I will be almost 100% treated as "crank".

あるいは幹部から怒鳴られる気がする ―― 『そんな言葉を吐いている時間があれば、必要な作業と人材と時間の見積をとっとと出せ!!』と。

Or I feel like I'm going to get yelled at by executives -- "If you've got time for using the word, get me an estimate of the work, manpower, and time needed!

-----

現在、猛烈な勢いで、システム監視ログと、監視プログラムがチェックが行われているはずです。

Currently, the system monitoring logs and the monitoring program should be being checked at a furious pace.

これは、次回の打ち上げの安全性を1段階、あるいは、それ以上アップしてくれると期待できます。

This can be expected to increase the safety of the next launch by one or more steps.

-----

システムにたずさわっているエンジニアの一人として、今回のシステム直前停止は『まれに見る見事な成功例』に見えます。

As an engineer involved in a system, I can say that the last minute system shutdown looks like a "rare and spectacular success story.

『あの直前でよく中止を成しとげた』って、大絶賛したいくらいですが ―― 世間の(一部の)人には、そう見えないのでしょうか?

I would like to give them a big pat on the back with saying "How wonderful you could stop the system at the moment!". However, could all we not share the same emotion?

2023,江端さんの忘備録

今朝、呼び鈴が鳴って、「宅配かな」と思って、2Fのドアホンから対応に出たところ、変な第一声を聞いて、一気に警戒に入りました。

When the doorbell rang this morning, I thought it might be a delivery, so I answered the doorbell on the second floor to respond and heard a strange first voice that put me on alert at once.

「こんにちは。私は○○といいます」

"Hello. My name is XX."

(無言が5秒続く)

(Silence lasts 5 seconds)

「最近、少しずつ暖かくなって・・・」

"It's gotten a little warmer lately, and..."

と言った瞬間、

The moment I said that.

江端:「失礼します」

I said, "I'm sorry," and hung up the doorbell.

といって、そのままドアホンを切りました。

-----

セールスの電話でも、このメソッドは使えます。

This method can also be used for sales calls.

「江端さまのお電話でよろしかったでしょうか」

"Are you Mr. Ebata? May I interrupt you?"

江端:「はい」

"Yes"

相手:「今、お時間よろしいでしょうか?」

"Would you have a time to talk?"

江端:「死ぬほど忙しい」

"No. I am busy to death"

この対応で、2回目の電話がくることはありません。

With this response, I will not receive a second call.

-----

『話の内容を一切聞かないで、一方的に会話を打ち切る』ということは、重要です。

It is important to 'terminate the conversation unilaterally without listening anything'

一方的に自分の時間に介入された人は、そのような介入を無条件に打ち切る権利があります。

A person who is unilaterally intervened on his or her own time has the right to terminate such intervention unconditionally.

-----

そういえば、私、家の周りに、こんなの貼っています。

Come to think of it, I have these things posted around my house.

「見ているぞ!」 に「ポイ捨て禁止」を追加

これを見ても、なお、江端家のドアホンを押す勇気があることは、見上げたものだと思います。

To see this and still have the courage to press the doorbell of the Ebata family is something to look up to.

2023,江端さんの忘備録

以前、「めんつゆ」「コロッケ」「クロワッサン」の偉大さについて書いたことがあります。

I have previously written about the greatness of mentsuyu, croquettes, and croissants.

ですから、「ポテトサラダ」や「冷凍餃子」を使うことを「手抜き」であると批難した人は、まず私のところに来て下さい。

また、レトルト食品のアレンジ方法についても紹介しました。

Also I presented how to arrange retort foods.

まあ、それでも、レトルトカレーの域を出ることはないのですが ―― 結構、いけます。

最近、レトルトのパスタソースの味も、シャレにならないくらい美味しいです。

Lately, retort pasta sauces have tasted, no pun intended, delicious.

自分の好きな具材(ナス、ニンニク、ホウレンソウ、しめじ、鶏肉、その他)を適当に炒めておいて、このパスタソースを投入するだけで ――

Simply saute my favorite ingredients (eggplant, garlic, spinach, shimeji mushrooms, chicken, etc.) and add this pasta sauce.

間違いなく、その辺のイタリアンファミリーレストランには負けないくらいの、美味しいパスタになっていると思います。

Without a doubt, the pasta is as good as any Italian family restaurant in the area.

-----

―― とは言え、正直、よく分かりません。

-- However, I honestly don't know.

なぜなら、私は、まだ、その店に来店したことがないからです。

Because I have yet to visit the restaurant.

あるアニメの主人公(俺の青春ラブコメは・・・)が、この店を必要に推してくるので、今、私は、そのレストランに対する期待が、恐しい程に高まっているのです。

The main character in an anime (My Youth Love Comedy is...) makes a necessary push for this restaurant, and now my expectations for the restaurant have risen to a frightening degree.

『もしかしたら、ガッカリすることになるかもしれない』と思うと、どうしても、来店に二の足を踏んでしまうのです。

Tkinking 'Maybe I'll be disappointed,' I cannot help to hesitate to go to the restaurant.

2023,江端さんの忘備録

私は、『他人に自分の人生論を垂れる奴が大嫌い』ということを言い続けてきましたので、基本的に、そういうことはしません。

I have always said, 'I hate people who hang their life theories on others,' so basically, I don't do that.

仮に、自分の目の前に「これから失敗することが確実な人間」がいても、助言しません。

Even if there is a person in front of me who is certain to fail in the future, I would not advise him.

―― 笑顔を浮べながら、そいつが沈んでいくのを見続ける

"Keep smiling and watch that guy sink"

というのが、私のスタンスです。

That is my stance.

で、まあ、私自身、そういう風に、なんども"沈没"を続けてきましたが、それで良かったと思っています。

And, well, I have "sunk" many times in that way, and I am glad that I did.

私には『失敗する権利がある』と思っているからです。

Because I believe that I have the 'right to fail.

『"失敗"からしか学べないなら、学ぶためには"失敗"し続けなければならない』

自分の子どもであっても、同じスタンスです ―― もっとも、彼女らの生命と財産に関わることは、除きますが。

Even my own children, I take the same stance -- except when it comes to their lives and property.

-----

という訳で、大抵の場合、私は娘たちに語るかけることはしませんが、娘たちの方から相談されることはあります(主に長女)。

So, for the most part, I don't talk to my daughters about it, but they do ask me for advice (mainly my seior daughter).

彼女の相談の内容を纏めますと、

To summarize her consultation,

―― 多角的な視野をもって、上手く仕事を回したい

"I want to work well with multiple perspectives"

ということです。

江端:「大丈夫。年齢を重ねるだけで、ほっといても『多角的な視野』になるよ。なにしろ無駄に生きているんだから」

Ebata: "Don't worry. Just getting older will give you a 'multifaceted perspective' even if you leave it alone. After all, we all are living in vain.

長女:「今、すぐに、"そう"なりたい」

She: "Right now, I want to be 'so'."

江端:「それは、無理かなぁ。『若い』というのは、能力と関係なく『舐められる』運命にあるから」

Ebata: I don't know it is easy. Because 'young' is destined to be 'licked' regardless of ability.

長女:「能力は、評価されないの?」

She:"Isn't ability appreciated?"

江端:「能力って、評価が難しいんだよ ―― 例えば、私が20歳代にやってきた時『バカ、アホ』と言われたことを、今やると『流石は、江端さんですね。素晴しい』って言われるぞ」

Ebata: "Ability is difficult to evaluate. For example, when I was in my 20s, people said I was stupid or an idiot, but when I do it now, they say 'You are a brilliant person!"

長女:「・・・」

She:"..."

江端:「という訳で、『他人の評価は、受け流す』で、いいと思うぞ」

Ebata: "So, I think it's good that you should just 'let other people's evaluations slide".

-----

『人の意見を真に受けて、自分のやりたいことを止めてしまうことが、一番バカバカしい』

'The most ridiculous thing you can do is stop yourself from doing what you want to do because of the opinions of others.'

とは、多くの人も言っていますが、

Many people said that, however, I am afraid that they don't say

『それに気がつくのは、人生のラストイニングあたりである』

"You don't realize it until the last inning of your life"

ということは、あまり語られていないように思います。

2023,江端さんの忘備録

最近、映画「八甲田山」と「二百三高地」を見直したのですが、『もの凄い映画だなぁ』と感嘆しました。

I recently reviewed the movies "Hakkoudasan" and "Nihyaku san Kochi" and marveled at what a great movie they are.

アナログ実写の迫力もさることながら、おそらくはロケ地の劣悪な環境下での疲労困憊の役者やエキストラの血を吐くような演技が ―― ぶっちゃけ『怖い』。

The power of the analog live action, as well as the blood-curdling performances of the exhausted actors and extras, probably under the poor conditions of the location, are honestly 'scary'.

最近の映画が、今一つ面白くないのは、映像のデジタル化かのためかなぁ、と思うのですよね。

I wonder if the reason why movies these days are not as interesting as they used to be is because of the digitalization of images.

―― というのが、一つの仮説です。

-- is one hypothesis.

ところが、私には、もう一つの仮説があります。

However, I have another hypothesis.

それは、『単に、私が若い頃に慣れ親しんでいる映像に、私が洗脳されているだけ』というものです。

It is, 'I am simply brainwashed by the images I am familiar with from my youth.

-----

『ションコネリー以外の007はカスだ』といっていた著名人がいましたが、私は『ロジャームーアの007』の方が面白いと思っています。

There was a celebrity who said, "007 other than Shon Connery is scum," but I think "Roger Moore's 007" is more interesting.

また、私が実家に帰省した時に、父は、私に1950-60年代のハリッド映画を見せようとしていましたが、私には、その面白みが全く伝わってきませんでした。

Also, when I went back home, my father tried to show me halid films from the 1950s and 1960s, but I never found them interesting.

つまり、「その人間にとって、特に多感な時代に刷り込まれた(映画の)記憶が、その後の価値基準になる」、つまり『すりこみ』です。

"The memories (of films) imprinted on a person, especially during his or her impressionable years, become the standard of value thereafter", in other words, "slip-in".

『自分にとって最上と思っているモノやコトが、他の人にとっては論外である』ということは、普通にあると思います。

It is common for people to say, "What I consider to be the best thing for me is out of the question for others".

-----

20年後に、私の孫が存在するどうかは分かりませんが ―― その孫に『シュタインズ・ゲート』を見せたら、どういう感想を持つのだろうか、と考えると、ドキドキします。

I don't know if my grandchildren will exist 20 years from now -- but I get nervous thinking about what they will think of "Steins;Gate" when I show it to them.

もし、孫が『面白い』と言ったら、私は孫にお年玉を沢山渡すだろうと思います。

If my grandson says 'that's great' I will probably give him a lot of New Year's money.

2023,江端さんの忘備録

現在、私は3つのプロジェクトに属していますが、3つのプロジェクトリーダーの全員が女性です。

Currently I am part of three projects and all three project leaders are women.

―― ということに、今さらながら、気がつきました。

I realize that now.

当然ですが、全員が年下です ―― というか、単に私が"シニア"というだけのことですが。

Of course, they are all younger than me -- or rather, I am simply a "senior".

仕事に関して『問題がない』というか『問題を認識できない』です。

I don't have a problem with my work, or rather, I can't recognize a problem.

私が不当に忖度(そんたく)されているという可能性 ―― いや、それは、"ない"と思う。

The possibility that I am being unfairly given careful consideration -- no, I don't think so.

私には人事権などの裁量が全くないですから。

I have absolutely no discretionary authority over personnel matters.

-----

ちなみに、私は、私を気持ちよく働かせてくれるのであれば、リーダーの性別や年齢に興味はなく、機械(AI?)に指示されたって、一向に構いません。

By the way, I am not interested in the gender or age of the leader, as long as they make me feel good about working for them. I don't mind being directed by a machine (AI?).

2023,江端さんの技術メモ

ODデータ(csv):20220518weekday

領域データ(csv):yamaguchi_area

出力データ(csv):new_20220518weekday

その他: 年齢を乱数を使って適当に作成しているコードも入っている

// ~/yamaguchi/src_try1/others/main61.go

// Usage: go run main61.go 20220518weekday.csv new_20220518weekday.csv

package main

import (
	"database/sql"
	"encoding/csv"
	"fmt"
	"log"
	"math/rand"
	"os"
	"strconv"

	_ "github.com/lib/pq"
)

func main() {

	file, err := os.Open("yamaguchi_area.csv")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	r := csv.NewReader(file)
	rows, err := r.ReadAll() // csvを一度に全て読み込む
	if err != nil {
		log.Fatal(err)
	}

	str := "SELECT ST_Covers(st_geomfromtext('POLYGON(("

	// 行ごとに
	for i, row := range rows {
		if i == 0 {
			continue // CSVのヘッダー行を無視
		}

		str += row[1] + " " + row[2] + ", " // rowのままで取り出せば、文字列になっている

	}
	str1 := str[:len(str)-2] + "))'),st_geomfromtext('LINESTRING(" // 上記の最後の", "を削除して、文字列を追加

	dbMap, err := sql.Open("postgres",
		"user=postgres password=password host=192.168.0.23 port=15432 dbname=yama_db sslmode=disable")
	log.Println("------------------ map db open ------------------")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer dbMap.Close()

	///////////////////////////////////////

	//file2, err2 := os.Open("20220518weekday.csv")
	file2, err2 := os.Open(os.Args[1]) // 第1パラメータ
	if err2 != nil {
		log.Fatal(err2)
	}
	defer file2.Close()

	r2 := csv.NewReader(file2)
	rows2, err2 := r2.ReadAll() // csvを一度に全て読み込む
	if err != nil {
		log.Fatal(err2)
	}

	file3, err3 := os.Create(os.Args[2]) // 第2パラメータ
	if err3 != nil {
		panic(err)
	}

	w := csv.NewWriter(file3)

	var id int

	for _, row := range rows2 {
		//if i == 0 {
		//	continue // CSVのヘッダー行を無視
		//}

		str2 := str1 + row[0] + " " + row[1] + ", " + row[2] + " " + row[3]

		str2 += ")'))"

		fmt.Println(str2)

		rows1, err := dbMap.Query(str2)
		if err != nil {
			log.Fatal(err)
		}
		defer rows1.Close()

		//var dt string
		var dt bool

		for rows1.Next() {
			if err := rows1.Scan(&dt); err != nil {
				fmt.Println(err)
			}
			// fmt.Println(dt)
			if dt {

				//if err := rows.Scan(&id, &age, &type1, &departure_name, &departure_number, &departure_lat, &departure_lng, &arrival_name, &arrival_number, &arrival_lat, &arrival_lng); err != nil {
				//	fmt.Println(err)
				// 上記のSQLのフォームと同じ形でcsvファイルを作る

				var age int

				fmt.Println("row[4]:", row[4])

				// id_str := strconv.Itoa(id) // idを文字列に
				if row[4] == "10-15" {
					age = 10 + rand.Intn(5)
				} else if row[4] == "15-29" {
					age = 15 + rand.Intn(5)
				} else if row[4] == "20-24" {
					age = 20 + rand.Intn(5)
				} else if row[4] == "25-29" {
					age = 25 + rand.Intn(5)
				} else if row[4] == "30-34" {
					age = 30 + rand.Intn(5)
				} else if row[4] == "35-39" {
					age = 35 + rand.Intn(5)
				} else if row[4] == "40-44" {
					age = 40 + rand.Intn(5)
				} else if row[4] == "44-49" {		
					age = 45 + rand.Intn(5)
				} else if row[4] == "50-54" {
					age = 50 + rand.Intn(5)
				} else if row[4] == "55-59" {
					age = 55 + rand.Intn(5)
				} else if row[4] == "60-64" {
					age = 60 + rand.Intn(5)
				} else if row[4] == "65-69" {
					age = 65 + rand.Intn(5)
				} else if row[4] == "70-74" {
					age = 70 + rand.Intn(5)
				} else if row[4] == "75-80" {
					age = 75 + rand.Intn(5)
				} else if row[4] == "80-84" {
					age = 80 + rand.Intn(5)
				} else if row[4] == "85-89" {
					age = 85 + rand.Intn(5)
				} else if row[4] == "90-94" {
					age = 90 + rand.Intn(5)
				} else if row[4] == "95-99" {
					age = 95 + rand.Intn(5)
				} else {
					age = 15 + rand.Intn(65) // 15箸キ79までの乱数
				}

				type1 := "resident"
				departure_name := ""
				_row1, _ := strconv.ParseFloat(row[1], 64)
				_row0, _ := strconv.ParseFloat(row[0], 64)

				departure_number, departure_lng, departure_lat := fixPosition(dbMap, _row1, _row0) // row[1], row[0]の順番に注意

				arrival_name := ""
				_row3, _ := strconv.ParseFloat(row[3], 64)
				_row2, _ := strconv.ParseFloat(row[2], 64)
				arrival_number, arrival_lng, arrival_lat := fixPosition(dbMap, _row3, _row2) // row[3], row[2]の順番に注意

				output := []string{fmt.Sprint(id), fmt.Sprint(age), type1, departure_name, fmt.Sprint(departure_number), fmt.Sprint(departure_lat), fmt.Sprint(departure_lng), arrival_name, fmt.Sprint(arrival_number), fmt.Sprint(arrival_lat), fmt.Sprint(arrival_lng)}

				//output := []string{row[0], row[1], row[2], row[3], row[4]}
				fmt.Println("output:", output)

				if err = w.Write(output); err != nil {
					log.Fatal(err)
				}

				id++ // idの加算
			}
		}

		err = rows1.Err()
		if err != nil {
			panic(err)
		}

		defer w.Flush()

		if err := w.Error(); err != nil {
			log.Fatal(err)
		}

	}
}

// 指定した座標に近いDB上の座標を取得
func fixPosition(db *sql.DB, _x1, _y1 float64) (int, float64, float64) {

	// Scan用の仮変数
	var source int
	var longitude float64
	var latitude float64
	var dist float64

	upperLimitMeter := 1500.0 // 近傍ノードの上限を1500 mに設定
	str := fmt.Sprintf(
		// 修正前: ways (道) の中から最近傍を取得
		// "SELECT source, x1 AS longitude, y1 AS latitude, ST_Distance('SRID=4326;POINT(%v %v)'::GEOGRAPHY, the_geom) AS dist FROM ways WHERE ST_DWithin(the_geom, ST_GeographyFromText('SRID=4326;POINT(%v %v)'), %.1f) ORDER BY dist LIMIT 1",
		// 修正後: ways_vertices_pgr (点座標) の中から最近傍を取得
		"SELECT id AS source, lon AS longitude, lat AS latitude, ST_Distance('SRID=4326;POINT(%v %v)'::GEOGRAPHY, the_geom) AS dist FROM ways_vertices_pgr WHERE ST_DWithin(the_geom, ST_GeographyFromText('SRID=4326;POINT(%v %v)'), %.1f) ORDER BY dist LIMIT 1",
		_x1, _y1, _x1, _y1, upperLimitMeter,
	)
	//fmt.Println(str)

	rows, err := db.Query(str)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	foundGoodMapNode := false

	for rows.Next() {
		foundGoodMapNode = true
		if err := rows.Scan(&source, &longitude, &latitude, &dist); err != nil {
			fmt.Println(err)
		}
		//fmt.Println(source, longitude, latitude, dist)
	}

	if !foundGoodMapNode {
		log.Println("Warning: in func fixPosition: Good Map Node not found for query point (",
			_x1, ",", _y1, ")")
	}

	return source, longitude, latitude
}