PHP MapScript
Day 5
PHP Configuration
ใหตรวจสอบวา PHP เรียกใช Extension File ที่ไหน ดูที่
่
php.ini ในบรรทัดทีมี ขอความ “extension_dir”
extension_dir = /ms4w/Apache/php/ext/
ไปตรวจสอบที่/ms4w/Apache/php/ext/ วามีไฟล
php_mapscript.dll อยูหรือไม
่
แกไข php.ini ทีอยูใน D:\ms4w\Apache\cgi-bin ดังนี้
extension= php_mapscript.dll
PHP MapScript Configuration
restart Apache ตรวจสอบการเรียกใช
phpMapScript ด วย phpinfo()
MapScript Architecture
PHP MapScript
phpms-1.php
draw();
$img_url=$img-> saveWebImage();
?>
Example 1: Displaying a map
>
phpms-2.php
….
Navigation
> Full Extent
> Pan
> Zoom In
> Zoom Out
” SIZE=2> Size
Layers
>
อําเภอ
>
ตําบล
>
โรงพยาบาล
>สถานีอนามัย
Map Object
Create Map Object
$map = ms_newMapObj("ex-03.map")
จํานวน Layers
$map->numlayers
Extent
$map->extent->minx
$map->extent->miny
$map->extent->maxx
$map->extent->maxy
setextent(minx, miny, maxx, maxy)
Layer Object
กําหนด Layer ที่ตองการ
$lyr0 = $map->getLayer(0);
จํานวน Class ใน Layer ที่ระบุ
$lyr0 ->numclasses;
ชื่อ Class ใน Layer ที่ระบุ
$class0 = $lyr0->getClass(0);
กําหนด Labelitem
$class0->labelitem
Scale
$class0->maxscale
Class Object
กําหนด Class ใน Layer ที่ระบุ
$class0 = $lyr0->getClass(0);
ชื่อ Class ที่ระบุ
$class0->name;
Style
$cstyle =$class0-> getStyle(0)
Expression ของ Class
$class0-> setexpression(string expression)
$class0-> getexpression(string expression)
Style Object
สรางฐานขอมูลตัวอยาง
http://172.20.26.100/mapdemo.zip
Start Programs PostgreSQL 8.2 Command
Prompt
>createdb –E win874 mapdemo
>psql –U postgres mapsemo psql –U postgres mapsemo
mapdemo=#\d
mapdemo=#\dt c_cancer
mapdemo=#select * from c_cancer limit 10;
mapdemo=#\q
สรางฐานขอมูล PostGIS
Start Programs PostgreSQL 8.2 Command
Prompt
>shp2pgsql province.shp province >province.sql
>psql -U postgres -l
>createdb –E win874 mapserver –T template_postgis
>psql –U postgres mapserver psql –U postgres mapserver
mapserver=#\d
mapserver =#\dt province
mapserver =#\q
PostGIS
CREATE TABLE
Data type “geometry”
ImportData From Vector
shp2pgsql
shp2pgsql province.shp province > province.sql
gr2ogr
ogr2ogr -f "MapInfo File" provinve.tab PG:dbname=gisdb province
-f "ESRI Shapefile"
-f "TIGER"
-f "MapInfo File"
-f "GML"
-f "PostgreSQL"
PHP connect to PostgreSQL
";
echo "";
while ($row = pg_fetch_row($result)) {
echo "";
echo "$row[0]$row[1]";
echo "";
}
echo "";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
PostGIS
วัดระยะทาง
SELECT distance(the_geom,the_geom)
ี่
พื้นที่ทมีขอบเขตติดตอกัน
SELECT provincename FROM thailand
WHERE touches(thailand.the_geom, (SELECT the_geom
FROM thailand WHERE province =67));
ี่
ตําแหนงที่อยูในรัศมีทกําหนด
SELECT provincename FROM thailand
WHERE province =67 AND distance(the_geom, SELECT
the_geom
FROM thailand WHERE province =67)<100;
เชื่อมโยงกับ non-spatial data