Filed under: Fusion Table | Tags: Authenticate fusion table, forbidden fusion table, fusion table api key, fusion table api oauth, Login required fusion table, OAuth 2, OAuth 2 fusion table, oauth 2 php
Google has deprecated the fusion table SQL API and will be shutdown on December 26, 2012. Like me, many app developers are preparing for migration work.
Google already give a guideline docs to the developer for smooth up-gradation. It is fine but not sufficient for advance work. New api’s basic operation like select, update and delete is very much similar to older api. The main challenging part is the authentication to fusion table.
The fusion API v1 support below to authentication/authorization,
a. API Key: Allow only view public, unlisted(exportable) fusion table. Unfortunately not allow any update/insert/delete operation.
b. OAuth 2: Allow all kind of operation like fusion table CRUD, view of public/private table.
Authenticate using API Key:
It is very simple implementation. First, we need to generate API key using google console and then have to pass the generated key with fusion table sql. We have to follow below steps,
- login https://code.google.com/apis/console
- Click Services from left top menu
- ”ON” fusion table api.
- Now click “API Access” menu link
- Create a browser/Server Key. For test purpose you keep blank referrer box. But must specify the production site referrer after deployment.
- Use the generated key(Simple API Access) in fusion table HTTP sql request . Below is a sample
https://www.googleapis.com/fusiontables/v1/query?sql=SELECT * FROM 1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4&key=[your API key]
The API key is limited to select public/non listed(exportable) fusion table. Your Google account must have Edit/View permission of the targeted fusion table. To change add/modify fusion table access permission, click share button of the fusion table.
Authentication using OAuth 2
Google strongly recommended OAuth 2 authentication for fusion table api. If you read fusion table developer reference documentation, you will get Oauth 2 authentication step for different use-case. Unfortunately all of those need human interaction to allow app access. It is totally useless when we need to do crud operation by script. Interestingly fusion table support “service account” thought it not listed in documentation.
- Click “API” access and click new auth 2 account.
- Check service account and click “Create client ID”
- keys will be created for service account and google prompt pop for download binary key file. Download this and save your code directory.
- Now most important part is that both the gmail and “Service account” email have EDIT permission of the targeted fusion table. So allow permission both “xxxxxxxx@developer.gserviceaccount.com” and gmail account by click share button of the fusion table. Interestingly i did not find this information any where in fusion table developer api documentation except mighty Stack overflow.
Now we can authenticate fusion table by service account. I have been using google api client php version to play with fusion table API. Sample code for fusion table authentication using OAuth 2 can be found from here. This sample code used google api client php library.
Yes, hopefully we get the OAuth 2 token. Now we use this token in fusion table HTTP sql request like we have used in simple API KEY. We will always store generated token in session for repeated use.
OAuth has taken some of my night’s sleep. Now “all is well”
Filed under: Javascript | Tags: default numeric keypad, input numaric keypad, ipad numaric pad, numaric keypad, number, tel
Tablets and mobile user always expect numeric keypad by default for number text box entry. HTML5 have introduced two text type named “tel” and “number”. All modern browsers supports this new type. Both “tel” and “number” will bring default numeric keypad for tablels like ipad/andoid tab.
<input type=”tel” class=”someclass”/ > <input type=”number” class=”someclass”/ >
The basic difference between “tel” and “number” is that “tel” type does not allow decimal number, is useful for only telephone number entry.
One problem I have found when I have used this new type in jqery modal. Modal by default setfocus first text and if we use first textbox “tel” or “number” type, ipad does not show numeric keypad.
I do not find any good solution for this. Alternatively we can change default foucs of jqueryui modal to button instead of text box.
open: function(event, ui) {
$(":button:contains('Submit')").focus(); // 'Submit' is the button text
}
Filed under: Javascript | Tags: integer conversion, parseInt problem, parseInt wrong, string to integer
Javascript is great. But some over intelligency cause also great problem to the developer.
Here I give some string to integer conversion result in JavaScript,
1. parseInt(“01″)=>1
2. parseInt(“05″)=>5
3. parseInt(“08″)=>0
4. parseInt(“09″)=>0
Here javascript is giving wrong result for 3 and 4.
Problem:
When javascript get Zero leading string as parseInt parameter, it takes 8 base system for conversion automatically instead of 10 base.
Solution:
Simply set the base explicitly like below,
3. parseInt(“08″,10)=>8
4. parseInt(“09″,10)=>9
It is best practice in javascript to set the conversion “base” during any type number parsing.
Filed under: Openlayer | Tags: geoserver with openlayer, openlayer geoserver, openlayer with geosever, openlayer WMSGetFeatureInfo, WMSGetFeatureInfo
GeoSever is very good map repository. It supports most of the request including WMS. Open layer work well with Geoserver. Here I try to give a sample to use openlayer with Geoserver especially for beginner.
Add MapSever WMS Layer:
The main goal is that we will add geoserver layer as wms in the open layer. So the layer definition should be,
var dist = new OpenLayers.Layer.WMS(
"dist_GEO - Tiled", "http://localhost:8088/geoserver/wms",
{
srs: 'EPSG:4326',
width: '395',
styles: '',
height: '512',
layers: 'bdadmin:dist_GEO',
format: format,
tiled: 'true',
tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom,
isBaseLayer: true,
visibility: true
},
{
buffer: 0,
displayOutsideMaxExtent: true
}
);
This will include Bangladesh district boundary as base wms layer. Note that we set the srs value wgs84 projection of our data. The example geoserver is running on 8088 port.
Now we add the road layer from wms as openlayer overlay layer.
var bdhw = new OpenLayers.Layer.WMS(
"Bangladesh Highway",
"http://localhost:8088/geoserver/wms",
{
transparent: 'TRUE',
srs: 'EPSG:4326',
layers: 'bdadmin:rds_nr_geo',
format: format,
isBaseLayer: false,
visibility: true
}
);
Now for implantation of identity feature, we need to apply some ticks. We need call a java script ajax request in click/hover event for WMSGetFeatureInfo request to Geserver. In this point, most of the develop have to face problem in cross domain. If hosting apache and geo server(tomcat) listening in sampe pc but different host, there have to take special care for cross domain ajax call. I wrote a post regarding this issue here. Please read this article first to proceed to the next steps.
infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8088/geoserver/wms',
title: 'Identify features by clicking',
layers: [bdhq,bdhw,dist],
queryVisible: true,
infoFormat:'application/vnd.ogc.gml'
})
};
Here we set request url to http://localhost:8088/geoserver/wms . but it cannot directly call the request. We have to go via proxy request. So, write a proxy script and bypass the request.
File: geoproxy.php
<?php $url=$_GET["url"]; $res = file_get_contents($url); echo $res; ?>
Now we define proxy in openlayer at top,
OpenLayers.ProxyHost = “geoproxy.php?url=”;
Below the full source code is available,
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MapServer Layer</title>
<link rel="stylesheet" href="theme/default/style.css" type="text/css" />
<style>
.opmap
{
height:500px;
width:550px;
}
/* The map and the location bar */
#map {
clear: both;
position: relative;
width: 400px;
height: 450px;
border: 1px solid black;
}
.mypopuphtml{
padding-left:5px;
padding-top:0px;
padding-bottom:0px;
padding-right:5px;
font-family:Arial;
font-size:8pt;
background-color:white;
}
</style>
<script src="OpenLayers.js"></script>
<script defer="defer" type="text/javascript">
var zoom = 5;
var map;
var infoControls;
var highlightlayer;
var aktLayer=-1;
// pink tile avoidance
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
// make OL compute scale according to WMS spec
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
OpenLayers.ProxyHost = "geoproxy.php?url=";
function init(){
format = 'image/png';
var bounds = new OpenLayers.Bounds(
88.011, 20.59,
92.683, 26.634
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.023609375,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
// setup tiled layer
var dist = new OpenLayers.Layer.WMS(
"dist_GEO - Tiled", "http://localhost:8088/geoserver/wms",
{
srs: 'EPSG:4326',
width: '395',
styles: '',
height: '512',
layers: 'bdadmin:dist_GEO',
format: format,
tiled: 'true',
tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom,
isBaseLayer: true,
visibility: true
},
{
buffer: 0,
displayOutsideMaxExtent: true
}
);
var bdhw = new OpenLayers.Layer.WMS(
"Bangladesh Highway",
"http://localhost:8088/geoserver/wms",
{
transparent: 'TRUE',
srs: 'EPSG:4326',
layers: 'bdadmin:rds_nr_geo',
format: format,
isBaseLayer: false,
visibility: true
}
);
var bdhq = new OpenLayers.Layer.WMS(
"Bangladesh Dist HQ",
"http://localhost:8088/geoserver/wms",
{
transparent: 'TRUE',
srs: 'EPSG:4326',
layers: 'bdadmin:dist_hq_geo',
format: format,
isBaseLayer: false,
visibility: true
}
);
highlightLayer = new OpenLayers.Layer.Vector("Highlighted Features", {
displayInLayerSwitcher: false,
isBaseLayer: false
}
);
//map.addLayers([gphy, gmap, ghyb, gsat]);
map.addLayers([dist,bdhw,bdhq,highlightLayer]);
// build up all controls
map.addControl(new OpenLayers.Control.PanZoomBar({
position: new OpenLayers.Pixel(2, 15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
map.addControl( new OpenLayers.Control.LayerSwitcher() );
map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));
map.zoomToExtent(bounds);
map.updateSize();
infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8088/geoserver/wms',
title: 'Identify features by clicking',
layers: [bdhq,bdhw,dist],
queryVisible: true,
infoFormat:'application/vnd.ogc.gml',
eventListeners: {
getfeatureinfo: function(event) {
map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",
map.getLonLatFromPixel(event.xy),
null,
GenPopText(event),
null,
true
));
}}
}),
hover: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8088/geoserver/wms',
title: 'Identify features by clicking',
layers: [bdhq],
hover: true,
// defining a custom format options here
formatOptions: {
typeName: 'water_bodies',
featureNS: 'http://www.openplans.org/topp'
},
queryVisible: true,
infoFormat:'text/html'
})
};
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
infoControls.click.activate();
//infoControls.hover.activate();
// Active layer combo
populateLayer(0);
}
// sets the HTML provided into the nodelist element
function setHTML(response){
document.getElementById('nodelist').innerHTML = response.responseText;
};
function errorHTML(response)
{
alert("req erro:" + response.responseText);
}
function showInfo(evt) {
if (evt.features && evt.features.length) {
highlightLayer.destroyFeatures();
highlightLayer.addFeatures(evt.features);
highlightLayer.redraw();
$('nodelist').innerHTML = GenPopText(evt);
} else {
$('nodelist').innerHTML = evt.text;
}
}
function GenPopText(evt){
var temstr="<b><i>" + evt.features[0].gml.featureType + "</i></b><br/>";
for(var key in evt.features[0].attributes)
{
temstr += "<b>" + key + "</b>:" + evt.features[0].attributes[key] + "<br/>";
}
return temstr
}
</script>
</head>
<body onLoad="init()">
<div id="title">Geosever Layer</div>
<div id="layerswitcher" class="olControlLayerSwitcher"></div>
<div id="map"></div>
<div id="wrapper">
<div id="location" style="float:left">location</div>
<div id="scale" style="float:left"></div>
<div id="scale" style="clear:both"></div>
</div>
<div id="nodelist">
<em>Click on the map to get feature info</em>
</div>
</body>
</html>
………………………………………………
Abul Khayer
GIS Programmer
CEGIS
Filed under: Openlayer | Tags: mapserver with openlayer, mapserver wms, openlayer with mapserver, osgeo mapserver wms
Openlayer can add mapserver wms layer. In this writing, I discuss how work with mapserver wms layer using openlayer. I also wrote an article on how to create mapserver wms repository in my another writing here.
So let assume that we have a well configure mapserver repository and now want to view this maps using openlayer.
Add MapSever WMS Layer:
var dist = new OpenLayers.Layer.WMS( "Bangladesh Admin Bourndary",
"http://localhost:8080/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map",
{layers: 'dist_geo',
srs: 'EPSG:4326',
format: format,
isBaseLayer: true,
visibility: true
}
);
This will include Bangladesh district boundary as base wms layer. Note that we set the srs value wgs84 projection of our data.
Now we add the road layer from wms as openlayer overlay layer.
// add road layer as overlay layer
var bdhw = new OpenLayers.Layer.WMS(
"Bangladesh Highway",
"http://localhost:8080/cgi-bin/mapserv.exe",
{
map: 'C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
transparent: 'TRUE',
layers: 'road_geo',
srs: 'EPSG:4326',
format: format
},
{'reproject': true}
);
Now we implement identity features. When user click on map, we make WMSGetFeatureInfo request to mapserver.
infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
title: 'Identify features by clicking',
layers: [dist],
infoFormat:'text/html',
queryVisible: true
})
};
Below the full source code is available,
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MapServer Layer</title>
<link rel="stylesheet" href="theme/default/style.css" type="text/css" />
<style>
.opmap
{
height:450px;
width:550px;
}
</style>
<script src="OpenLayers.js"></script>
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
<script type="text/javascript">
/*######################
Author: Md Abul Khayer
Year: 2010
khayer.wordpress.com
#######################*/
var map, layer;
var infoControls;
function init(){
format = 'image/png';
var bounds = new OpenLayers.Bounds(
88.011, 20.59,
92.683, 26.634
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.023609375,
projection: "EPSG:4326",
};
map = new OpenLayers.Map('map', options);
// Add Google Layer as baselayer
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{type: G_PHYSICAL_MAP}
);
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, numZoomLevels: 22}
);
map.addLayers([gphy, gmap, ghyb, gsat]);
// Add Custom base layer. Bangladesh District boundary.
var dist = new OpenLayers.Layer.WMS( "Bangladesh Admin Bourndary",
"http://localhost:8080/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map",
{layers: 'dist_geo',
srs: 'EPSG:4326',
format: format,
isBaseLayer: true,
visibility: true
}
);
// add road layer as overlay layer
var bdhw = new OpenLayers.Layer.WMS(
"Bangladesh Highway",
"http://localhost:8080/cgi-bin/mapserv.exe",
{
map: 'C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
transparent: 'TRUE',
layers: 'road_geo',
srs: 'EPSG:4326',
format: format
},
{'reproject': true}
);
// Bangladesh distric head queater as overlay layer.
var bdhq = new OpenLayers.Layer.WMS(
"Bangladesh Dist HQ",
"http://localhost:8080/cgi-bin/mapserv.exe",
{
map: 'C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
transparent: 'TRUE',
layers: 'dist_hq_geo',
srs: 'EPSG:4326',
format: format
},
{'reproject': true}
);
// Get identities of the map. Can be either click or hover is activated.
infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
title: 'Identify features by clicking',
layers: [dist],
infoFormat:'text/html',
queryVisible: true
}),
hover: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/distwms.map',
title: 'Identify features by clicking',
layers: [dist],
hover: true,
infoFormat: 'text/html',
queryVisible: true
})
}
map.addLayers([dist, bdhw, bdhq]);
map.zoomToMaxExtent();
map.addControl( new OpenLayers.Control.LayerSwitcher() );
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
infoControls.click.activate();
}
function showInfo(evt) {
if (evt.features && evt.features.length) {
//highlightLayer.destroyFeatures();
//highlightLayer.addFeatures(evt.features);
//highlightLayer.redraw();
$('nodelist').innerHTML=evt.text;
} else {
$('nodelist').innerHTML=evt.text;
}
}
</script>
</head>
<body onLoad="init()">
<div id="title">MapServer WMS Layer with Google map.</div>
<div id="layerswitcher" class="olControlLayerSwitcher"></div>
<div id="map" class="opmap"></div>
<div id="wrapper">
<div id="location" style="float:left">location</div>
<div id="scale" style="float:left"></div>
<div id="scale" style="clear:both"></div>
</div>
<div id="nodelist">
<em>Click on the map to get feature info</em>
</div>
</body>
</html>
………………………………………………
Abul Khayer
GIS Programmer
CEGIS
Filed under: Mapserver | Tags: mapserver wms, mapserver wms server, openlayer wms, osgeo mapserver wms, umn mapserver wms
While I have been working with Google map api, a lots tutorial over the web can be found. But unfortunately, Map server developer are only working but not willing to anything for new developer. May be they think it is very simple, why you need more than the mapserver documentation? But true is that it is very difficult to new developer to run their first hello world program. So, very first time in my blog I have started to write tutorial on map server related issue.
The main objective of this writing is that a simple wms map repository will be created using Osgeo Mapserver and view the map with openlayer. In this example I have used three layers Bangladesh district boundary, Main Road and District head quarter location. The first two layer map source is ESRI Shape file and third one is postgis. For all the layer I have used wgs84(EPSG:4326) projection system. In my another post I wrote on mapserver projection system, click here to check article.
Map file Creation with WMS support:
I am using osgeo mapserver in windows OS. Below definition have been added for top level in mapfile,
NAME BdDistMap STATUS ON SIZE 500 550 # Extent based on full extent of QGIS view EXTENT 86.7316 20.5896 93.9623 26.6341 UNITS dd IMAGECOLOR 225 225 255 IMAGETYPE png FONTSET "fontlist.txt"
Now the web section is very important for wms. It requires to add meta data information to give WMS support. This example I have added minimum wms definition which are all most mandatory.
WEB
IMAGEPATH "/OSGeo4W/tmp/tmp_img/"
IMAGEURL "/tmp/tmp_img/"
HEADER "query_header.html"
FOOTER "query_footer.html"
METADATA
"wms_title" "WMS Demo Server"
"wms_onlineresource" "http://localhost:8080/cgi-bin/mapserv.exe?map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map"
"wms_srs" "EPSG:4326"
"wms_feature_info_mime_type" "text/html"
END
END
In metadata section, wms_title, wms_srs are mendatory. Wms_srs is the projection system definition. wms_feature_info_mime_type is used to GetFeatureInfo request output format.
I have used map lavel projection system for all layers. Below is definition,
PROJECTION
"init=epsg:4326"
END
Now in layer definition, I have added meta info tag again. Below is the definition,
LAYER
NAME dist_geo
PROJECTION
"init=epsg:4326"
END
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
METADATA
"wms_title" "distwms"
END
TYPE POLYGON
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/dist_GEO.shp"
CLASS
NAME "State Boundary"
STYLE
COLOR 150 123 90
OUTLINECOLOR 229 210 191
END
END
END
Here I add projection parameter again. If you want use map level projection, this section can be removing. This include Bangladesh administrator boundary with wms support. The data source is shape file in wgs84 projection.
Below the complete working mapfile is given which is able response wms request.
MAP
NAME BdDistMap
STATUS ON
SIZE 500 550
# Extent based on full extent of QGIS view
EXTENT 86.7316 20.5896 93.9623 26.6341
UNITS dd
IMAGECOLOR 225 225 255
IMAGETYPE png
FONTSET "fontlist.txt"
WEB
IMAGEPATH "/OSGeo4W/tmp/tmp_img/"
IMAGEURL "/tmp/tmp_img/"
HEADER "query_header.html"
FOOTER "query_footer.html"
METADATA
"wms_title" "WMS Demo Server"
"wms_onlineresource" "http://localhost:8080/cgi-bin/mapserv.exe?map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map" "wms_srs" "EPSG:4326"
"wms_feature_info_mime_type" "text/html"
END
END
QUERYMAP
STATUS ON
SIZE 500 550
STYLE HILITE
COLOR 255 255 0
END
SYMBOL
NAME "Circle"
FILLED true
TYPE ellipse
POINTS 5 5 END
END
PROJECTION
"init=epsg:4326"
END
LAYER
NAME dist_geo
PROJECTION
"init=epsg:4326"
END
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
METADATA
"wms_title" "distwms"
END
TYPE POLYGON
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/dist_GEO.shp"
CLASS
NAME "State Boundary"
STYLE
COLOR 150 123 90
OUTLINECOLOR 229 210 191
END
END
END
LAYER
NAME road_geo
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "Cities"
END
TYPE LINE
STATUS OFF
DATA "C:/OSGeo4W/apache/htdocs/openlayer/sampleapps/shp/rds_nr_geo.shp"
CLASS
NAME "State Road"
STYLE
COLOR 32 32 32
END
END
END
LAYER
NAME dist_hq_geo
# for HTML queries
HEADER "hq_query_header.html"
TEMPLATE "hq_query_body.html"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "DistHQ"
END
TYPE POINT
STATUS OFF
CONNECTION "user=postgres password=cegis dbname=postgis host=localhost port=5432"
CONNECTIONTYPE postgis
DATA "the_geom from dist_hq_geo USING UNIQUE gid"
LABELITEM "distname"
CLASS
NAME "dist_hq_geo"
COLOR 200 255 0
SYMBOL "Circle"
LABEL
COLOR 132 31 31
SHADOWCOLOR 218 218 218
SHADOWSIZE 2 2
TYPE TRUETYPE
FONT arial
SIZE 11
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
END # end of label
STYLE
OPACITY 100
END
END
END
END # Map File
Call mapserver WMS Layer:
Now the important part, how we can test this repository? Write below address in your web browser,
http://localhost:8080/cgi-bin/mapserv.exe?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities&map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map
This will return respose wms request if everything is okay. And also write below address for testing map image generation of mapserver,
http://localhost:8080/cgi-bin/mapserv.exe?mode=map&layer=dist_geo&layer=road_geo&map=C:\OSGeo4W\apache\htdocs\openlayer\sampleapps\distGeo.map
In another article, I wrote how to add mapserver wms layer using openlayer.
Click here
For more information about wms layer, please check below links,
here
here
……………………………..
Abul Khayer
GIS programmer
CEGIS
Bangladesh
Filed under: Mapserver | Tags: BTM, btm projection, BUTM, EPSG:3106, mapserver bangladesh, mapserver porjection, osgeo mapserver projection, umn mapserver projection
I am not a projection expert. So, who know projection very well, this article does not come to any help. Here I give some reference information for new mapserver developer.
We can add projection parameter in map file by two ways,
1. Inline projection
It use detail projection parameter. If you use shape file, using arcgis parameter can be found. And also there .prj file where contains this parameters. Below I give the projection parameter of wgs84,
PROJECTION
“proj=longlat”
“ellps=WGS84″
“datum=WGS84″
“no_defs”
END
2. EPSG Projection reference
For simplicity, some reference number is introducing to identify a set of projection parameter, known as ESPG. We can find epsg from below site,
http://spatialreference.org
In all list reference tab, require reference number can be search. For example, if we search Bangladesh then we get EPSG:3106 code for Bangladesh(BUTM).
EPSG list can be found also in local pc in “OSGeo4W\share\proj\epsg” file.
Now for WGS84 projection, we have add below projection code in map file in EPSG,
PROJECTION
“init=epsg:4326″
END
The projection can be add in layer level in map file. But if the entire layers are in same projection, then no need to add projection in layer level. It is better at in map level.
If we use WMS layer, wms_srs is a mandatory parameter. So the for wgs84 parameter value should be,
METADATA
“wms_srs” “EPSG:4326″
END
Fow more mapserver project documentation, click here.
…………………………
Abul Khayer
GIS programmer
CEGIS



