2023,江端さんの技術メモ

https://josm.openstreetmap.de/wiki/Help/Action/JumpToPosition

ショートカットキー: Ctrl+J

または、ここをクリックすると、

このダイアログが出てくので、ここに名称または座標を入れる。

2023,江端さんの技術メモ

まだ試してないけど、バス停の追加は多分、これで可能となるはず

osm2pgrouting -f tsuzuki.osm -c mapconfig_for_cars_rail_busstop.xml -d tsuzuki_rail -U postgres -h 192.168.0.23 -p 15432 -W password

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <tag_name name="highway" id="1">
    <tag_value name="bus_stop"/>
    <tag_value name="motorway"          id="101" priority="1.0" maxspeed="130" />
    <tag_value name="motorway_link"     id="102" priority="1.0" maxspeed="130" />
    <tag_value name="motorway_junction" id="103" priority="1.0" maxspeed="130" />
    <tag_value name="trunk"             id="104" priority="1.05" maxspeed="110" />
    <tag_value name="trunk_link"        id="105" priority="1.05" maxspeed="110" />    
    <tag_value name="primary"           id="106" priority="1.15" maxspeed="90" />
    <tag_value name="primary_link"      id="107" priority="1.15" maxspeed="90" />    
    <tag_value name="secondary"         id="108" priority="1.5" maxspeed="90" />
    <tag_value name="secondary_link"    id="109" priority="1.5" maxspeed="90"/>  
    <tag_value name="tertiary"          id="110" priority="1.75" maxspeed="90" />
    <tag_value name="tertiary_link"     id="111" priority="1.75" maxspeed="90" />  
    <tag_value name="residential"       id="112" priority="2.5" maxspeed="50" />
    <tag_value name="living_street"     id="113" priority="3" maxspeed="20" />
    <tag_value name="service"           id="114" priority="2.5" maxspeed="50" />
    <tag_value name="unclassified"      id="117" priority="3" maxspeed="90"/>
    <tag_value name="road"              id="100" priority="5" maxspeed="50" />
  </tag_name> 
  <tag_name name="railway" id="1">
    <tag_value name="subway"              id="101" priority="1.0" maxspeed="40" />
    <tag_value name="rail"              id="101" priority="1.0" maxspeed="40" />
  </tag_name> 
</configuration>

明日がんばれ > 自分

2023,未分類,江端さんの技術メモ

>osm2pgrouting -f tsuzuki.osm -c mapconfig_for_cars_rail.xml -d tsuzuki_rail -U postgres -h 192.168.0.23 -p 15432 -W password

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <tag_name name="highway" id="1">
    <tag_value name="motorway"          id="101" priority="1.0" maxspeed="130" />
    <tag_value name="motorway_link"     id="102" priority="1.0" maxspeed="130" />
    <tag_value name="motorway_junction" id="103" priority="1.0" maxspeed="130" />
    <tag_value name="trunk"             id="104" priority="1.05" maxspeed="110" />
    <tag_value name="trunk_link"        id="105" priority="1.05" maxspeed="110" />    
    <tag_value name="primary"           id="106" priority="1.15" maxspeed="90" />
    <tag_value name="primary_link"      id="107" priority="1.15" maxspeed="90" />    
    <tag_value name="secondary"         id="108" priority="1.5" maxspeed="90" />
    <tag_value name="secondary_link"    id="109" priority="1.5" maxspeed="90"/>  
    <tag_value name="tertiary"          id="110" priority="1.75" maxspeed="90" />
    <tag_value name="tertiary_link"     id="111" priority="1.75" maxspeed="90" />  
    <tag_value name="residential"       id="112" priority="2.5" maxspeed="50" />
    <tag_value name="living_street"     id="113" priority="3" maxspeed="20" />
    <tag_value name="service"           id="114" priority="2.5" maxspeed="50" />
    <tag_value name="unclassified"      id="117" priority="3" maxspeed="90"/>
    <tag_value name="road"              id="100" priority="5" maxspeed="50" />
  </tag_name> 
  <tag_name name="railway" id="1">
    <tag_value name="subway"              id="101" priority="1.0" maxspeed="40" />
    <tag_value name="rail"              id="101" priority="1.0" maxspeed="40" />
  </tag_name> 
</configuration>

とりあえず、ちゃんと、JRと市営地下鉄が加えられている。

この後は、osmファイルを手作業で加工

街の中に道路を作って、ダイクストラ計算ができるか試してみた件 ―― JOSMを使った道路追加の方法を試す

がんばれ > 自分

 

2023,江端さんの技術メモ

JOSMで地下鉄の情報だけをosm形式で取り出したい時(未完成)

JOSMでバス停が取り出せる。これを使って、バス路線を自力で作れそう。

拡大すると、こんな感じ

バス停専用の高架を作って、一般道に繋ぐイメージにすることで、バスを専用路線扱いできる。コスト値を変えて、ダイクストラを実施すれば、バスが選ばたり、逆に忌避させたりすることもできるはず。

以上

2023,江端さんの技術メモ

JOSM (Java OpenStreetMap Editor) を用いて複数 OSM ファイルのマージ

Step 1. マージするOSMを選択

Step 2.  JOSMにドラッグ

Step 3. ファイルをマージ

Step 4. 「レイヤを結合する」を選択する(この段階ではセーブされないので、どのレイヤでもいい)

Step 5. 路線を結合したい点を、同じ番号にするなどの加工を行う

以上

2023,江端さんの技術メモ

神奈川県のバスルートのsharpファイルをpostGISにインポートする

をやってから、試しに、1つのバスルートのみを、ここから取り出して、

select文の出力をローカルのテキストで保存する方法

とした後、このプログラムで、なんちゃってosmファイルを作成する。

/* 


前処理
bus_route=# \o output.txt
bus_route=# select ST_AsText(geom) from bus_route where gid = 1488;
bus_route=# \o

f:/しゅらばしゅう/有吉先生データ/Transfer(2018)/N07-11_14_GML/
sharp2osm.go

>go run sharp2osm.go ichi-61.txt 20000 > ichi-61.osm

ichi-61.txtの形式は、以下の感じ

MultiLineStringM ((139.53708861000001207 35.55222889000000208 0, 139.5370455599999957 35.55227666999999769 0, 139.53649416999999744 35.55299193999999829 0, 139.53643777999999998 35.55307056000000188 0, 139.53636917000000039 35.55315000000000225 0, 139.53559056000000282 35.55415305999999731 0, 139.53552528000000166 35.5542358300000032 0, 139.53547499999999104 35.5543083299999978 0, 139.53475943999998776 35.55520943999999872 0, 139.53468250000000239 35.55528333000000174 0, 139.53507944000000407 35.55541443999999984 0, 139.53518278000001374 35.55545389000000256 0, 139.53539638999998829 35.55552139000000267 0, 139.53575471999999991 35.55565666999999763 0, 139.5360763600000098 35.55570185999999921 0))

*/

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)

func main() {

	// ファイルを開く
	filePath := "output.txt" // 実際のファイルパスに置き換えてください
	file, err := os.Open(filePath)
	if err != nil {
		fmt.Println("ファイルを開けませんでした:", err)
		return
	}
	defer file.Close()


	fmt.Println("<?xml version='1.0' encoding='UTF-8'?>")
	fmt.Println("<osm version='0.6' generator='JOSM'>")

	node_id := 20000

	// ファイルを行ごとに読み込み、カンマとスペースでパースする
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line_org := scanner.Text()
		prefix := " MULTILINESTRING M ((" // 切り捨てる最初の文字列
		line := strings.TrimPrefix(line_org, prefix)

		fields := strings.FieldsFunc(line, func(r rune) bool {
			return r == ',' || r == ' ' 
		})



		var lon,lat float64


		// 取得したフィールドを表示
		for i, field := range fields {

			num, _ := strconv.ParseFloat(field, 64)
			// fmt.Println(i, i%3, num)
			
			if i % 3 == 0 {
			   lon = num
			}else if i % 3 == 1{
			   lat = num
			} else if i % 3 == 2{
			   fmt.Printf("  <node id='%d' visible='true'  version='5' lat='%f' lon='%f' />\n", node_id, lat, lon) 
			   node_id++
			   //fmt.Println(lat,",",lon)
			}	

		}
	}

	fmt.Println("  <way id='180000' visible='true' version='5'>")	

	for i:=20000; i<node_id; i++{
		fmt.Printf("    <nd ref='%d' />\n",i) 
	}
	fmt.Printf("        <tag k='highway' v='residential' />")
		
	fmt.Println("  </way>")	
	fmt.Println("</osm>")	



	if err := scanner.Err(); err != nil {
		fmt.Println("ファイル読み込みエラー:", err)
	}
}

で、以下のようなファイルができる。

<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='JOSM'>
<node id='20000' visible='true' version='5' lat='35.560912' lon='139.606144' />
<node id='20001' visible='true' version='5' lat='35.561252' lon='139.606062' />
<node id='20002' visible='true' version='5' lat='35.561646' lon='139.605835' />
<node id='20003' visible='true' version='5' lat='35.561736' lon='139.60575' />
(中略)
<way id='180000' visible='true' version='5'>
<nd ref='20000' />
<nd ref='20001' />
<nd ref='20002' />
<nd ref='20003' />
(中略)
<nd ref='20189' />
<tag k='highway' v='residential' />
</way>
</osm>

JOSMでの表示

QGISでの表示

とりあえず、忘れないうちにメモを作成しました。

以上

2023,江端さんの技術メモ

bus_route=# \o output.txt
bus_route=# select * from bus_route where gid = 1488;
bus_route=# \o

psqlを立ち上げたディレクトリにできている

 

2023,江端さんの技術メモ

https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N07.html

アンケートに答える

ダウンロードしたものを解凍すると、以下のファイルが出てくる

で、shp2pgsqlを使って、sqlファイルを作る

F:\N07-11_14_GML>shp2pgsql -W cp932 -D -I -s 4612 F:\N07-11_14_GML\N07-11_14.shp bus_route > F:\N07-11_14_GML\bus_route.sql

bus_route.sqlの内容はこんな感じ

最初に、データベースを作っておく。

C:\Users\ebata>psql -U postgres -h 192.168.0.23 -p 15432
Password for user postgres:
psql (13.4, server 13.3 (Debian 13.3-1.pgdg100+1))
Type "help" for help.

tsuzuki_db=# create database bus_route;
CREATE DATABASE
tsuzuki_db=# \c bus_route
psql (13.4, server 13.3 (Debian 13.3-1.pgdg100+1))
You are now connected to database "bus_route" as user "postgres".
bus_route=# create extension postgis;
CREATE EXTENSION
bus_route=# create extension pgrouting;
CREATE EXTENSION

bus_route=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+----------
public | spatial_ref_sys | table | postgres
(1 row)

と、この状態で、

psql -U postgres -h 192.168.0.23 -p 15432 -d bus_route -f "bus_route.sql"

でインポートを実施。

bus_route=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------+-------+----------
public | bus_route | table | postgres
public | spatial_ref_sys | table | postgres
(2 rows)

テーブルbus_routeが追加されている。

QGIS3で見るとこんな感じに見える。

データベースへのアクセス方法は、図中参考のこと。

以上

 

2023,江端さんの技術メモ

https://github.com/BtbN/FFmpeg-Builds/releases から、

をダウンロードして、解凍して、binにパスを通して、

カメラ繋げて、以下のコマンドを投入する。

C:\Users\ebata>ffplay -i rtsp://192.168.0.2/ONVIF/Streaming/channels/3

と、こんな感じで、動画が出てくる。

C:\Users\ebata>ffprobe -v error -show_entries stream=codec_type,width,height -i rtsp://192.168.0.2/ONVIF/Streaming/channels/3
[STREAM]
codec_type=video
width=640
height=360
[/STREAM]
[STREAM]
codec_type=audio
[/STREAM]
[STREAM]
codec_type=data
[/STREAM]

C:\Users\ebata>ffprobe -v error -show_entries stream=codec_type,width,height -i rtsp://192.168.0.2/ONVIF/Streaming/channels/0
[h264 @ 00000168d79bc9c0] left block unavailable for requested intra4x4 mode -1
[h264 @ 00000168d79bc9c0] error while decoding MB 0 27, bytestream 59839
[STREAM]
codec_type=video
width=1920
height=1080
[/STREAM]
[STREAM]
codec_type=audio
[/STREAM]
[STREAM]
codec_type=data
[/STREAM]

 

C:\Users\ebata>ffprobe -v error -show_format -show_streams -i rtsp://192.168.0.2/ONVIF/Streaming/channels/3
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=640
height=360
coded_width=640
coded_height=360
closed_captions=0
film_grain=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=31
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=progressive
refs=1
is_avc=false
nal_length_size=0
id=N/A
r_frame_rate=5/1
avg_frame_rate=5/1
time_base=1/90000
start_pts=17635
start_time=0.195944
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=58
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[STREAM]
index=1
codec_name=pcm_mulaw
codec_long_name=PCM mu-law / G.711 mu-law
profile=unknown
codec_type=audio
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16
sample_rate=8000
channels=1
channel_layout=unknown
bits_per_sample=8
initial_padding=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/8000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=64000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[STREAM]
index=2
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=data
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/90000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[FORMAT]
filename=rtsp://192.168.0.2/ONVIF/Streaming/channels/3
nb_streams=3
nb_programs=0
format_name=rtsp
format_long_name=RTSP input
start_time=0.000000
duration=N/A
size=N/A
bit_rate=N/A
probe_score=100
TAG:title=RTSP/RTP stream from HDIPCam
[/FORMAT]

C:\Users\ebata>ffprobe -v error -show_format -show_streams -i rtsp://192.168.0.2/ONVIF/Streaming/channels/0
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1080
coded_width=1920
coded_height=1080
closed_captions=0
film_grain=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=40
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=progressive
refs=1
is_avc=false
nal_length_size=0
id=N/A
r_frame_rate=30/1
avg_frame_rate=30/1
time_base=1/90000
start_pts=4354
start_time=0.048378
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=61
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[STREAM]
index=1
codec_name=pcm_mulaw
codec_long_name=PCM mu-law / G.711 mu-law
profile=unknown
codec_type=audio
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16
sample_rate=8000
channels=1
channel_layout=unknown
bits_per_sample=8
initial_padding=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/8000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=64000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[STREAM]
index=2
codec_name=unknown
codec_long_name=unknown
profile=unknown
codec_type=data
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/90000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
[/STREAM]
[FORMAT]
filename=rtsp://192.168.0.2/ONVIF/Streaming/channels/0
nb_streams=3
nb_programs=0
format_name=rtsp
format_long_name=RTSP input
start_time=0.000000
duration=N/A
size=N/A
bit_rate=N/A
probe_score=100
TAG:title=RTSP/RTP stream from HDIPCam
[/FORMAT]

ffplayは、これでかなり描画が早くなる。(VLCと同程度になった→ ということは、VLCもフレーム落しをしているんだな、多分)

ffplay -fflags nobuffer -flags low_delay -framedrop -i srt://192.168.1.15:12345

■ffmpegでSRTストリームを10秒間録画する方法

ffmpeg -i "srt://192.168.1.15:12345" -t 10 output.mp4

#3 30/1 max=30 3543KB
#3 10/1 max=10 4529KB
#3 5/1 max=5