logo
Test to use GIS (graphic information system) by perl and fly
ทดสอบ maptest.pl เพื่อประยุกต์เป็น Graphic Information System (GIS)
ผมได้รับมอบหมายให้ศึกษาเรื่องของ Graphic information system เพื่อนำมาใช้ทำเว็บ จากความรู้ที่มีอยู่คือเรื่องของ perl และ fly ที่เคยเขียนไว้ที่ [ การเขียน graphic ในรูปแบบ gif ] เมื่อกลับไปดูพบว่า มีคำสั่งที่นำมาประยุกต์สำหรับเรื่อง GIS ได้คือ fill และ filltoborder จึงได้ทำบทเรียนนี้ขึ้นอย่างง่าย ๆ ให้เห็นว่า ทำ GIS ได้อย่างไร .. และยังให้ลองส่งค่าดูได้ด้วย .. ลองดูนะครับ แล้วค่อย ๆ คิดว่าจะนำไปใช้อย่างไร ต่อไป .. เพราะการจะนำไปใช้เป็น GIS จะต้องแก้ปัญหาอีกเยอะ กว่าจะไปถึงจุดนั้นได้สำเร็จ
Original: maptest.gif
No parameter: maptest.pl
maptest.pl?x=150&y=30&r=255&g=0&b=0
ถ้านำไปใช้แบบไม่ใช้ฐานข้อมูลก็ใช้วิธีอ้างอิงตรง ๆ โดยมีตัวอย่างการเขียนว่า <img src=maptest.pl?x=150&y=30&r=255&g=0&b=0> แต่ถ้าใช้ฐานข้อมูลจะใช้อะไรก็ได้ เพราะใช้วิธีส่งค่าผ่านภาษาอะไรก็ได้เช่น perl, php, asp เพื่อสร้างหน้าเว็บใหม่ขึ้นมา แล้วในหน้าเว็บนั้นก็มี tag img ข้างบนนี้พร้อมค่าที่ส่งมา แต่ในการสร้างภาพนั้น ตัวอย่างนี้ต้องเป็น perl และ fly เท่านั้น ส่วนฐานข้อมูลจะใช้ text, mysql, mdb ก็ไม่น่ามีปัญหาอะไร

ทดสอบภาพโดยกำหนด parameter เองในเบื้องต้น
x(col) :
y(row) :
Red :
Green :
Blue :
Source code of maptest.pl
    !/usr/local/bin/perl # fill x=30&y=150&r=0&g=0&b=0 &parse_form; $flyprog = "/usr/local/bin/fly -q"; $outfile = "/home/lampang/tempfile.txt"; open(FLY,">$outfile") || die "Can't Open File : $!\n"; print FLY "new\n"; print FLY "size 200,200\n"; print FLY "copy 0,0,-1,-1,-1,-1,/home/lampang/maptest.gif\n"; print FLY "circle 32,32,32,0,0,0\n"; print FLY "filltoborder 75,75,0,0,0,0,255,255,\n"; print FLY "fill $c{'x'},$c{'y'},$c{'r'},$c{'g'},$c{'b'}\n"; close(FLY); $output = `$flyprog -i $outfile`; print "Content-type: image/gif\n\n"; print "$output"; sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $c{$name} = $value; } if (length($c{'x'}) eq 0) { $c{'x'}=30; } if (length($c{'y'}) eq 0) { $c{'y'}=150; } if (length($c{'r'}) eq 0) { $c{'r'}=0; } if (length($c{'g'}) eq 0) { $c{'g'}=0; } if (length($c{'b'}) eq 0) { $c{'b'}=0; } }