Upload
kristopher-stevenson
View
219
Download
0
Embed Size (px)
DESCRIPTION
Why WMS Serving maps as WMS is an efficent method of rendering maps online. It is a secure method of sharing data (maps) online. It follows an internationally accpeted standard and is interoperatble to a wide range of platforms and applications.
Citation preview
AIST=Innovation
TRAINING GUIDE II
TASKS
Setup a Wep Wap Service (WMS)Test the WMSsRendering Maps Served as WMSsWMS Clients
Why WMS
Serving maps as WMS is an efficent method of rendering maps online.
It is a secure method of sharing data (maps) online.
It follows an internationally accpeted standard and is interoperatble to a wide range of platforms and applications.
<html><head><meta name="viewport" content="height=device-height,width=device-width" /><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0" /><meta name="apple-mobile-web-app-status-bar-style" content="red" /><script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script><script type="text/javascript">
function initialize() { var myLatlng = new google.maps.LatLng(14.35,121.33); var mapOptions = { zoom: 4, center: myLatlng } var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, }); var the_info = new google.maps.InfoWindow( { content:"Laguna Caldera", size: new google.maps.Size(50,50) }); the_info.open(map,marker);}
google.maps.event.addDomListener(window, 'load', initialize);</script></head><body ontouchmove="BlockMove(event);" ontouchstart="window.scrollTo(0, 1)"><div id="map-canvas" style="width:100%; height:100%"> </div></body></html>
Displaying data in vector format is very inefficient when data volume is huge.
Displaying data in vector format is very inefficient when data volume is huge.
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document><description>Description of the Database</description><Placemark><description>Query Results</description><name>Valley Fault System, West Valley Fault</name><seamless_style_code>15</seamless_style_code><Style><LineStyle><width>2</width><color>ff0000ff</color></LineStyle><PolyStyle><color>ff0000ff</color></PolyStyle></Style><MultiGeometry><LineString><coordinates>121.083824922554896,14.64469699754069 121.083916395645417,14.645028306786946 121.084015980704436,14.645340348543012 121.084056554436074,14.645473056532749 121.084126406761413,14.645681500357936 121.084198376092047,14.645839012850146 121.084236623511671,14.645961528465286 121.084349068575861,14.646186855602471 121.084484009447863,14.646475627340946 121.084602294369319,14.646789327849108 121.084697703745675,14.64703787337889 121.084857385599378,14.647381336727941 121.085005847637433,14.647770751868491 121.085066921773503,14.647926271753255 121.085129608983351,14.648076907393758 121.085229156227427,14.64827416242294 121.085313962464454,14.64846066119452</coordinates></LineString></MultiGeometry></Placemark></Document></kml>
AIST=Innovation
Creating Web Map Service (WMS)
POSTGIS
GeoSpatial Database
Requests
Returned Results
WMS Server
WMS Software
Creating WMS
1. MapFile
2. WMS Script
Two Documents Needed for WMS
Creating WMSMapFile fragments
MAP NAME OGC_WMS STATUS ON SIZE 256 256 EXTENT 120.331497192383 12.5718898773193 124.068504333496 18.2501106262207 UNITS dd IMAGECOLOR 255 255 255 IMAGETYPE gif PROJECTION "init=epsg:4326" END
METADATA WMS_TITLE "Active Fault Map of the Philippines" WMS_ABSTRACT "None" WMS_ONLINERESOURCE "http://222.127.18.125/cgi-bin/wms/active_fault_philippines_wms?" WMS_CONTACTPERSON "Dr. Renato Solidum" WMS_CONTACTORGANIZATION "Director, Philippine Institute of Volcanology and Seismology" WMS_ADDRESSTYPE "postal" WMS_ADDRESS "PHIVOLCS Building, C.P. Garcia Avenue, UP Campus Diliman, 1101 Quezon City" WMS_CONTACTVOICETELEPHONE " 63 02 426.1468" WMS_CONTACTELECTRONICMAILADDRESS "[email protected]" WMS_FEES "none" WMS_ACCESSCONSTRAINTS "None" WMS_FEATURE_INFO_MIME_TYPE "text/html" WMS_ENABLE_REQUEST "*" WMS_SRS "EPSG:4326 EPSG:4326 EPSG:900913" WMS_KEYWORDLIST "None" END END
Creating WMS
MapFile fragments
LAYER NAME active_fault_philippines METADATA WMS_TITLE "Active Fault Map of the Philippines" WMS_ABSTRACT "None" WMS_SRS "EPSG:4326 EPSG:4326 EPSG:900913" END
connectiontype postgis connection "user=postgres password=diliman2015 dbname=portal_maps host=localhost port=5432" data "geom from mymaps_schema.active_fault_philippines_table using unique gid"
TYPE LINE STATUS ON DUMP TRUE PROJECTION "init=epsg:4326" END
Creating WMS
MapFile fragments
CLASSITEM "trace_type"
class name "Approximate" expression "Approximate" STYLE COLOR 255 0 0 WIDTH 2 PATTERN 10 5 10 5 END END end
class name "Approximate Offshore Projection" expression "Approximate Offshore Projection" STYLE COLOR 255 0 0 WIDTH 2 PATTERN 10 5 10 5 END END end
class name "Certain" expression "Certain" symbol "Solid“ size 2 color 255 0 0 end
Fault Line (Line)
Creating WMS
MapFile fragments
CLASSITEM "province"
class name "Abra" expression "Abra" style color 129 30 77 outlinecolor 0 0 0 width 1 end end class name "Agusan del Norte" expression "Agusan del Norte" style color 154 192 29 outlinecolor 0 0 0 width 1 end end class name "Agusan del Sur" expression "Agusan del Sur" style color 66 162 179 outlinecolor 0 0 0 width 1 end end
Provinces (Polygon)
Creating WMSMapFile fragments
class name "Magnitude <=5 " expression (([magnitude]<=5) AND ([depth]<50)) style symbol "Circle" color 252 81 4 outlinecolor 0 0 0 size 8 end end class name "Magnitude <=5 “ expression (([magnitude]<=5) AND ([depth]>=50) AND ([depth]<100)) style symbol "Circle“ color 250 250 6 outlinecolor 0 0 0 size 8 endend
class name "Magnitude 8.1 - 9.0 " expression (([magnitude]>=8.1) AND ([magnitude]<=9.0) AND ([depth]<50)) style symbol "Circle" color 252 81 4 outlinecolor 0 0 0 size 20 end end
Earthquake (Point)
Creating WMS ServiceCopy sample MapFiles and WMS Scripts from the server to
your computer using WinSCP
Paths:/home/phivolcs_users/sample_mapfiles/your_first_mapfile.map/home/phivolcs_users/sample_wms_script/your_first_wms_script
HOST: 153.120.126.61User ID: cvsu_users
Password: indang2015
Creating WMS Service
1. Provinces (Polygon)2. Fault Lines (Lines)3. Luzon Volcanoes (Point)4. 2014 Earthquakes (Point)
Edit Sample Mapfiles for the following
Creating WMS ServiceEdit MapFiles
MAP NAME OGC_WMS STATUS ON SIZE 256 256 EXTENT minX minY maxX marY UNITS dd IMAGECOLOR 255 255 255 IMAGETYPE gif PROJECTION "init=epsg:4326" END
Philippines Extent: WGS84 (epsg:4326)
Min X: 116.88Min Y: 4.53Max X: 126.65Max Y: 21.02
92.6219863891602 9.81379795074463 100.56526184082 27.7735614776611
116.880485534668 4.53367280960083 126.654167175293 21.0186023712158
Creating WMS ServiceEdit MapFiles
LAYER NAME lao_mineral_occurence_table METADATA WMS_TITLE “Lao Mineral Occurrence Map" WMS_ABSTRACT "Autogenerated map file" WMS_SRS “EPSG:32648 EPSG:4326 ESRl:54004 EPSG:4612 EPSG:4301 EPSG:900913" END
connectiontype postgis connection "user=postgres password=joelbandibas dbname=JICA_DB1 host=localhost port=5432" data "the_geom from lao_mineral_occurence_table using unique gid"
TYPE POLYGON STATUS ON DUMP TRUE PROJECTION "init=epsg:32648" END
Edit MapFiles
SQL to Determine all possible values of CLASSITEM (e.g. trace_type)select distinct <CLASSITEM> from <Table Name>;
Exampleselect distinct soildesc from maps.soiltable;
Creating WMS ServiceEdit MapFiles
Save the mapfiles in the following format.
group1_data.mapgroup2_data.mapgroup3_data.mapgroup4_data.mapgroup5_data.map
Creating WMS ServiceEdit MapFiles
Upload Your MapFiles to the Server using WinSCP
Upload to the Folder (Path):
/var/www/wms_new/
Example of MapFile path:
/var/www/wms_new/joelb.map
Creating WMS ServiceEdit MapFiles
Upload Your MWS Scripts to the Server using WinSCP
Upload to the Folder (Path):
/var/www/cgi-bin/wms_new/
Example of WMS Path:
/var/www/cgi-bin/wms_new/joel_mws
URL: http://222.127.18.125/cgi-bin/wms_new/joel_wms
Creating WMS ServiceEdit WMS Script
WMS Script Format
#!/bin/shexport MS_MAPFILE=MapFile Pathexec /usr/local/bin/mapserv
Example
#!/bin/shexport MS_MAPFILE=/var/www/map/group0_data.mapexec /usr/local/bin/mapserv
Creating WMS ServiceEdit WMS Script
Save your wms scripts in the following filename (no extension)
group1_data_wmsgroup2_data_wmsgroup3_data_wmsgroup4_data_wmsgroup5_data_wms
Creating WMS ServiceEdit WMS Script
Upload Your WMS Scripts to the Server using WinSCP
Upload to the Folder (Path):/var/www/cgi-bin/wms
Example of wms script path:/var/www/cgi-bin/wms/group0_data_wms
Creating WMS ServiceEdit WMS Script
Make your WMS Script Executable
Login to the server using Putty and do the following commands:
$chmod 755 wms script pathchmod +x wms script path
$chmod 755 /var/www/cgi-bin/wms_new/joel_wms$chmod +x /var/www/cgi-bin/wms_new/joel_wms
Example:
Creating WMS ServiceDetermine the WMS URL
Format:http://HOSTNAME/cgi-bin/wms/wms_script
Example:http://222.127.18.125/cgi-bin/wms/myscript_wms
Creating WMS ServiceTesting Your WMS
GetCapabilities
WMS URL?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&URI Format:
http://222.127.18.125/cgi-bin/wms_new/mvl_sample_wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&
URI Example:
GetCapabilities Universal Resource Identifier (URI)
Creating WMS ServiceTesting Your WMS
GetCapabilities URI Pointed by the browser (e.g. Firefox)
http://222.127.18.125/cgi-bin/wms/group0_data_wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&
AIST=Innovation
Result
Creating WMS ServiceTesting Your WMS
GetMapGetMap Universal Resource Identifier (URI)
WMS URL?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=Layer Name&FORMAT=image/png&SRS=EPSG:4326&BBOX=102,10,108,15&WIDTH=256&HEIGHT=256
URI Format
URI Formathttp://222.127.18.125/cgi-bin/wms/group0_data_wms?LAYERS=active_fault_philippines&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&FORMAT=image/png&SRS=EPSG:4326&BBOX=119.876487731934,5.56563949584961,126.775588989258, 19.9385070800781&WIDTH=512&HEIGHT=700
AIST=Innovation
Creating WMS ServiceTesting Your WMS
GetMap Result after pointing a brower to the GetMap URI
/home/phivolcs_users/sample_client/first_client_google_maps.html
Copy the sample client from the server to your pc. The file could be found at
Displaying Your Map Using a ClientGoogle Maps
Change this part of the file based on the WMS that you setup
var my_wms_layer = new google.maps.ImageMapType({ getTileUrl: function(tile, zoom) {
var proj = map.getProjection(); var zpow = Math.pow(2, zoom);
var ul = new google.maps.Point(tile.x * 256.0 / zpow, (tile.y + 1) * 256.0 / zpow);var lr = new google.maps.Point((tile.x + 1) * 256.0 / zpow, (tile.y) * 256.0 / zpow);var ulw = proj.fromPointToLatLng(ul);var lrw = proj.fromPointToLatLng(lr);var bbox = ulw.lng() + "," + ulw.lat() + "," + lrw.lng() + "," + lrw.lat(); var url = "http://222.127.18.125/cgi-bin/wms/active_fault_philippines_wms?";
url += "REQUEST=GetMap"; url += "&SERVICE=WMS"; url += "&VERSION=1.1.1"; url += "&LAYERS=" + "active_fault_philippines"; url += "&FORMAT=image/png" ; url += "&BGCOLOR=0xFFFFFF"; url += "&TRANSPARENT=TRUE"; url += "&SRS=EPSG:4326"; url += "&BBOX=" + bbox; url += "&WIDTH=256"; url += "&HEIGHT=256"; return url; }, tileSize: new google.maps.Size(256, 256), isPng: false, opacity:1, name: "Active Faults", mapTypeId:"my_first_wms_layer", credit: 'GSJ_AIST' });map.overlayMapTypes.insertAt(0,my_wms_layer);
AIST=Innovation
Displaying Your Map Using a ClientGoogle Map
Display all of WMSs that you formulated yesterday.
Displaying Your Map Using a ClientGoogle Maps
/home/phivolcs_users/sample_client/wms_with_google_earth.kml
Copy the sample kml file from the server to your pc. The file could be found at
Change the this part of the file based on the WMS that you setup
Displaying Your Map Using a ClientOpenlayers/Google Map
<href>http://222.127.18.125/cgi-bin/wms/group0_data_wms?LAYERS=active_fault_philippines&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&FORMAT=image/png&SRS=EPSG:4326&BBOX=119.876487731934,5.56563949584961,126.775588989258,19.9385070800781&WIDTH=512&HEIGHT=700</href>
AIST=Innovation
Displaying Your Map Using a ClientGoogle Earth
/home/phivolcs_users/sample_client/ first_client_openlayers.html
Copy the sample client from the server to your pc. The file could be found at
Displaying Your Map Using a ClientGoogle Maps
NEXT
WebGIS Portal Development
Using PHP Scripts
Inputting maps to the database
### PHP Script Segment
$shape_final_name=“your_shape”;$sql_file_name=“sql_file”;$dbname=“TrainingDB”;$dbtable=“table_name”;$encoding =“LATIN1”;$epsg=4326;
$command_1="shp2pgsql -W $encoding -s $epsg $shape_file_name $dbtable $dbname > $sql_file_name";exec($command_1);$command_2="psql -U $dbuser -d $dbname -f $sql_file_name";exec($command_2);
[postgres@jvaio~]$shp2pgsql –W LATIN1 - s epsg_code shape_fname table_name dbname > output_file.sql[postgres@jvaio~]$psql –d dbname –f output_file.sql
Command Format:
Using PHP Scripts<?php
$shape_final_name=“your_shape_file”;$sql_file_name=“sql_file”;$dbname=“TrainingDB”;$dbtable=“table_name”;$encoding =“LATIN1”;$epsg=4326;
$connect=pg_connect("host=localhost port=5432 dbname=$dbname user=postgres password=joelbandibas");
$command_1="shp2pgsql -W $encoding -s $epsg $shape_file_name $dbtable $dbname > $sql_file_name";
exec($command_1);$command_2="psql -U postgres -d $dbname -f $sql_file_name";exec($command_2);
pg_close($connect); #####
echo “You got it right!”;?>
Using PHP ScriptsSaving and Executing the PHP Script
1. Save the text with a .php extension. Preferably, the format should be groupname.php
2. Upload the file to the server using WinScp. It should be saved to the publicly accessible directory. In this exercise, it should be saved in the directory /var/www/html/training_scripts/
The resulting URL of the script would be http://hostname/training_scripts/groupname.php
3. Execute the script by pointing your browser (e.g. Firefox) to the script’s URL (http://hostname/training_scripts/groupname.php).
4. Check the database using phpPgAdmin
Using PHP Scripts
$shape_final_name=“your_shape_file”;$sql_file_name=“sql_file_name”;$dbname=“TrainingDB”;$dbtable=“table_name”;$encoding =“LATIN1”;$epsg=4326;
Dynamic PHP Scripts
The PHP script that we used earlier is static and not flexible. I you want to use another shape file, table name or database, you have to edit the php script.Dynamic PHP accepts inputs in the URL and editing the script is not necessary.
$shape_final_name =$_GET[‘shape_file'];$sql_file_name =$_GET[‘sql_file'];$dbname =$_GET[‘database'];$dbtable =$_GET[‘table'];$encoding =$_GET[‘encoding'];$epsg =$_GET[‘epsg'];
Static Dynamic
http://hostname/training_scripts/groupname.php?shape_file=your_shape_file&sql_file=sql_file&database=TrainingDB&table=table_name&encoding=LATIN1&epsg=4326
URL URI (Universal Resource Identifier)
Using PHP Scripts
<?php$shape_final_name =$_GET[‘shape_file'];$sql_file_name =$_GET[‘sql_file'];$dbname =$_GET[‘database'];$dbtable =$_GET[‘table’];$encoding =$_GET[‘encoding'];$epsg =$_GET[‘epsg'];
$connect=pg_connect("host=localhost port=5432 dbname=$dbname user=postgres password=joelbandibas");$command_1="shp2pgsql -W $encoding -s $epsg $shape_file_name $dbtable $dbname >
$sql_file_name";exec($command_1);$command_2="psql -U postgres -d $dbname -f $sql_file_name";exec($command_2);pg_close($connect); ?>
http://hostname/training_scripts/groupname.php?shape_file=your_shape_file&sql_file=sql_file&database=TrainingDB&table=table_name&encoding=LATIN1&epsg=4326
Using PHP Scripts
http://hostname/training_scripts/groupname.php?shape_file=your_shape_file&sql_file=sql_file&database=TrainingDB&table=table_name&encoding=LATIN1&epsg=432
Save and Execute the PHP Script
URL URI (Universal Resource Identifier)
http://192.168.8.108/phpPgAdmin/index.php
Edit MapFiles
SQL to Determine all possible values of CLASSITEM (e.g. geology)
select distinct <CLASSITEM> from <Table Name>;
Exampleselect distinct geology from sample_data1;
http://jcbwebgis.com/cgi-bin/wms/group/onegeology_new/east_asia_2m_wms?
Layer Name: east_asia_2m
URL:
Title: Geological Map of East Asia
Joel C. [email protected]@gmail.com
http://222.127.18.125/phpPgAdmin/index.php
Querying the Database UsingphpPgAdmin and Sequential Query Language (SQL)
select mineral_co,mine_depos, ST_Distance( the_geom, ST_Geomfromtext('POINT(96.129 19.744) ',4326 )) from myanmar_minerals_table ORDER by ST_Distance(the_geom, ST_Geomfromtext('POINT(96.129 19.744) ', 4326 )) ASC LIMIT 1;
Spatial Query
Distance in RadianceDetermining the Distance
select mineral_co,mine_depos, ST_Distance(
ST_Transform(the_geom,23946) ,ST_Transform(ST_Geomfromtext('POINT(96.144 16..793) ',4326 ),23946)
) from myanmar_minerals_table where mineral_co= ‘Gypsum’ ORDER by ST_Distance(the_geom, ST_Geomfromtext('POINT(96.144 16.793) ',4326 )) ASC LIMIT 5;
Distance in Meters (Myanmar is UTM 46N; EPSG Code: 23946
The SQL:
The SQL: