お手伝い仕事で、地図を作成している。MANDARAというフリーウエアGISソフト
を使って無料でもそこそこのことができる。
国がGISの基盤を整備していたり、google-MAP等インターネット環境も定着してきているので、これからもう一段伸びる分野でしょうね。
http://ktgis.net/mandara/
そこで、問題となってくるのが、住所から緯度経度を算出する「ジオコーディング」である。国からの提供ソフトで、ある程度(以下の例では「△△市△△町△-■」△の部分まで)のジオコーディングができるのだが、特定の地域でスポッと抜ける場合がある、、特に旧住所ということではないんですけど。
その抜けた場合の補完手段として、delphiで算出する方法をつくってみた。
以下のサンプルのからなんですけど、googleMAP-API を使わずにできる。
http://www.okada.jp.org/RWiki/?R%A4%C7%A5%B8%A5%AA%A5%B3%A1%BC%A5%C7%A5%A3%A5%F3%A5%B0
以下は、無償版 Turbo Delphi で動作するサンプル。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WinInet, StdCtrls,StrUtils ;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//参照
//http://wiki.landhere.info/index.php?cmd=read&page=Delphi%2FURL%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%89
function URLEncode(src: String): String;
var
i: Integer;
begin
Result:='';
for i:=1 to Length(src) do begin
Result:=Result+'%'+IntToHex(Ord(src[i]),2);
end;
end;
//参照
//http://mrxray.on.coocan.jp/Delphi/plSamples/770_WinInetTest.htm
procedure TForm1.Button1Click(Sender: TObject);
const
URL ='http://www.geocities.jp/asumaroyuumaro/program/tips/tipstop.html';
var
hSession, hReqUrl :hInternet;
Buffer :array [0..1023] of Char;
ReadCount :Cardinal;
HtmlStr :string;
Wkurl1,Wkurl2,Wkurl3,wk01 : string;
WkSu,wksu2,timeoutcnt : integer;
begin
Wkurl1 := 'http://maps.google.com/maps?q=';
wkurl2 := Edit1.text;
wkurl3 := ',&output=kml' ;
wk01 := Wkurl1 + URLEncode(AnsiToUtf8(wkurl2)) + wkurl3;
edit3.Text := wk01;
edit3.Show;
// wk01 := 'http://maps.google.com/maps?q=%e9%87%91%e6%b2%a2%e5%b8%82%e9%9e%8d%e6%9c%88%ef%bc%91%e4%b8%81%e7%9b%ae%31%e7%95%aa%e5%9c%b0&output=kml';
timeoutcnt:=100;
Memo1.text:='';
hSession :=InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
try
if Assigned(hSession) then
begin
//URLのハンドルを取得
hReqUrl :=InternetOpenUrl(hSession,PChar(wk01),
nil, 0,INTERNET_FLAG_RELOAD, 0);
try
if Assigned(hReqUrl) then
begin
while true do begin
//URLハンドルを元にBufferに読み込む(ファイル最後まで繰り返す)
InternetReadFile(hReqUrl, @Buffer, Sizeof(Buffer), ReadCount);
//ファイルの最後までいったら抜ける
if ReadCount = 0 then
begin
inc(Timeoutcnt);
sleep (100);
if Timeoutcnt > 100 then
Break;
end;
HtmlStr :=HtmlStr +string(Buffer);
end;
Memo1.Text :=Utf8ToAnsi(HtmlStr);
end;
finally
InternetCloseHandle(hReqUrl);
end;
end;
finally
InternetCloseHandle(hSession);
end;
wkSu:=PosEx('<coordinates>',Memo1.Text, 1);
if Wksu = 0 then
edit2.text := 'non'
else
begin
wkSu2:=PosEx('</coordinates>',Memo1.Text, wksu+2);
edit2.text := copy (Memo1.Text,wksu +13,wksu2 - wksu - 13);
edit2.Show;
end;
end;
end.
を使って無料でもそこそこのことができる。
国がGISの基盤を整備していたり、google-MAP等インターネット環境も定着してきているので、これからもう一段伸びる分野でしょうね。
http://ktgis.net/mandara/
そこで、問題となってくるのが、住所から緯度経度を算出する「ジオコーディング」である。国からの提供ソフトで、ある程度(以下の例では「△△市△△町△-■」△の部分まで)のジオコーディングができるのだが、特定の地域でスポッと抜ける場合がある、、特に旧住所ということではないんですけど。
その抜けた場合の補完手段として、delphiで算出する方法をつくってみた。
以下のサンプルのからなんですけど、googleMAP-API を使わずにできる。
http://www.okada.jp.org/RWiki/?R%A4%C7%A5%B8%A5%AA%A5%B3%A1%BC%A5%C7%A5%A3%A5%F3%A5%B0
以下は、無償版 Turbo Delphi で動作するサンプル。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WinInet, StdCtrls,StrUtils ;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//参照
//http://wiki.landhere.info/index.php?cmd=read&page=Delphi%2FURL%E3%82%A8%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%89
function URLEncode(src: String): String;
var
i: Integer;
begin
Result:='';
for i:=1 to Length(src) do begin
Result:=Result+'%'+IntToHex(Ord(src[i]),2);
end;
end;
//参照
//http://mrxray.on.coocan.jp/Delphi/plSamples/770_WinInetTest.htm
procedure TForm1.Button1Click(Sender: TObject);
const
URL ='http://www.geocities.jp/asumaroyuumaro/program/tips/tipstop.html';
var
hSession, hReqUrl :hInternet;
Buffer :array [0..1023] of Char;
ReadCount :Cardinal;
HtmlStr :string;
Wkurl1,Wkurl2,Wkurl3,wk01 : string;
WkSu,wksu2,timeoutcnt : integer;
begin
Wkurl1 := 'http://maps.google.com/maps?q=';
wkurl2 := Edit1.text;
wkurl3 := ',&output=kml' ;
wk01 := Wkurl1 + URLEncode(AnsiToUtf8(wkurl2)) + wkurl3;
edit3.Text := wk01;
edit3.Show;
// wk01 := 'http://maps.google.com/maps?q=%e9%87%91%e6%b2%a2%e5%b8%82%e9%9e%8d%e6%9c%88%ef%bc%91%e4%b8%81%e7%9b%ae%31%e7%95%aa%e5%9c%b0&output=kml';
timeoutcnt:=100;
Memo1.text:='';
hSession :=InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
try
if Assigned(hSession) then
begin
//URLのハンドルを取得
hReqUrl :=InternetOpenUrl(hSession,PChar(wk01),
nil, 0,INTERNET_FLAG_RELOAD, 0);
try
if Assigned(hReqUrl) then
begin
while true do begin
//URLハンドルを元にBufferに読み込む(ファイル最後まで繰り返す)
InternetReadFile(hReqUrl, @Buffer, Sizeof(Buffer), ReadCount);
//ファイルの最後までいったら抜ける
if ReadCount = 0 then
begin
inc(Timeoutcnt);
sleep (100);
if Timeoutcnt > 100 then
Break;
end;
HtmlStr :=HtmlStr +string(Buffer);
end;
Memo1.Text :=Utf8ToAnsi(HtmlStr);
end;
finally
InternetCloseHandle(hReqUrl);
end;
end;
finally
InternetCloseHandle(hSession);
end;
wkSu:=PosEx('<coordinates>',Memo1.Text, 1);
if Wksu = 0 then
edit2.text := 'non'
else
begin
wkSu2:=PosEx('</coordinates>',Memo1.Text, wksu+2);
edit2.text := copy (Memo1.Text,wksu +13,wksu2 - wksu - 13);
edit2.Show;
end;
end;
end.