二次メッシュの切り出し(その1)


20万分の1地図は、一次メッシュとして分割されている。それを、縦横8分割(合計64分割)すると二次メッシュができる。ここでは、国土地理院の20万分の1のデータから二次メッシュを切り出す作業の内、自動切り出し部分を紹介する。実際には、その後かなりの調整が必要に成る。


地図画像の収集

国土地理院発行20万分の1数値地図CD−ROMからTIF画像ファイル130個を取得。

画像データの収集

国土地理院発行20万分の1数値地図CD−ROM中の「KANRI.CSV」ファイルから、各地図の各種情報を取得。

PrimMeshData.xls ダウンロード)

自動切り出し処理

AppleScriptとPhotoFlashの組み合わせで、自動的に二次メッシュを切り出した。

切り出しの手続きは以下の順序である

  1. AllData.TXT の有効画像領域座標に基づいてオリジナル画像をトリミングする。
  2. 画像サイズを4000 x 3600 ピクセルに拡大・統一する。
  3. これを、縦8,横8に分割し64個の二次メッシュ画像(500 x 450 pixels) を切り出す。

自動切り出しのスクリプト
on run
	set MyDataText to choose file of type {"TEXT"}
	open MyDataText
end run
on open f
	set MySourceF to (choose folder with prompt "Source Image Folder:") as string
	set MyTargetF to (choose folder with prompt "Target Folder:") as string
	
	try
		set MyAccess to open for access f
		set MyEof to get eof MyAccess
		set MyLine to read MyAccess until return -- skip the 1st line as headder
		set AppleScript's text item delimiters to {tab}
		repeat
			set MyLine to read MyAccess until return
			set MyImageID to text item 1 of MyLine
			set MyPoly to {}
			repeat with i from 2 to 9
				set MyNum to (text item i of MyLine) as number
				set Ch04 to ASCII character (MyNum mod 256)
				set Ch03 to ASCII character (MyNum div 256)
				set Ch02 to ASCII character 0
				set Ch01 to ASCII character 0
				if ((i mod 2) = 0) then
					set ChCode to (Ch01 & Ch02 & Ch03 & Ch04) as string
				else
					set ChCode to ChCode & (Ch01 & Ch02 & Ch03 & Ch04) as string
					set MyPoly to MyPoly & (cast ChCode to "lpnt")
				end if
				
			end repeat
			repeat with i from 2 to 3
				set MyNum to (text item i of MyLine) as number
				set Ch04 to ASCII character (MyNum mod 256)
				set Ch03 to ASCII character (MyNum div 256)
				set Ch02 to ASCII character 0
				set Ch01 to ASCII character 0
				if (i mod 2) = 0 then
					set ChCode to (Ch01 & Ch02 & Ch03 & Ch04) as string
				else
					set ChCode to ChCode & (Ch01 & Ch02 & Ch03 & Ch04) as string
					set MyPoly to MyPoly & (cast ChCode to "lpnt")
				end if
			end repeat
			MyProc(MyPoly, MyImageID, MySourceF, MyTargetF)
		end repeat
		
	on error MyErrorStr
		close access MyAccess
		display dialog MyErrorStr
	end try
end open
on MyProc(MyPoly, MyImageID, MySourceF, MyTargetF)
	---Check Folder Name of MyImageID and Create it
	try
		set MyFdrName to (MyTargetF & MyImageID & ":") as string
		info for alias MyFdrName
	on error
		tell application "Finder"
			make folder at alias MyTargetF with properties {name:MyImageID}
		end tell
	end try
	tell application "PhotoFlash"
		activate
		open file ((MySourceF & MyImageID & ".TIF") as string)
		change shape of selected pixels of image 1 to {type:Poly, class:polygon, vertices:MyPoly}
		crop document 1
		-- resize the image
		resize image 1 to "4000 pixels" by 
			"3600 pixels" vertical resolution 72 
			without dimensions constrained and file size constrained
		repeat with MyX from 0 to 7
			repeat with MyY from 0 to 7
				change shape of selected pixels of image 1 to {500 * (MyX), 3600 - 450 * (MyY + 1), 500 * (MyX + 1), 3600 - 450 * (MyY)}
				copy
				make new image at beginning 
					with properties {width:"450 pixels", height:"500 pixels", horizontal resolution:72.0, vertical resolution:72.0, color space:colors 256}
				
				paste
				set MyFName to (MyFdrName & MyX & MyY & ".pict") as string
				save document 1 in file MyFName replacing yes
				close document 1
			end repeat
		end repeat
		revert document 1
		
	end tell
	
end MyProc


Copyright by Akira Kihara, Last changes: