Postgis mapserver
From DreamsteepWiki
mapfile
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>webapp node visualizer for project keithrox</title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map({div: 'map', allOverlays: true ,
maxExtent: new OpenLayers.Bounds(-3 ,-3.7, 5.58029, 2.59539),
maxResolution: "auto", controls: [] ,units:"feet", projection:"epsg:26915"});
t1 = new OpenLayers.Layer.MapServer( "t1_lay","http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/apps/keithrox/htdocs/keithrox.map" ,
{layers: "t1"}, {gutter: 15} ,{transparent: true } );
map.addLayer(t1);
nav = new OpenLayers.Control.Navigation();
///
map.addControl(nav);
map.addControl(new OpenLayers.Control.LayerSwitcher());
///
map.events.register('click', map, function (e)
{
findLayerClick(e);
// alert(e);
});
////
function findLayerClick(event) {
mouseLoc = map.getLonLatFromPixel(event.xy);
//grab layer to query form html UI
//alert(read("formatType"));
//GETQUERYLAYER = "t1" ;//read("formatType")
//######################
//######################
//this builds a query to send to mapserver via url
var url = t1.getFullRequestString({
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.gml", // vnd.ogc.se_xml", //# /
STYLES: "",
BBOX: map.getExtent().toBBOX(),
X: event.xy.x,
Y: event.xy.y,
INFO_FORMAT: "application/vnd.ogc.gml",//"application/vnd.ogc.gml", //'text/plain',
QUERY_LAYERS: "t1",
FEATURE_COUNT: 1,
WIDTH: map.size.w,
HEIGHT: map.size.h
} );
//alert(url) ; //this is the actual query string
OpenLayers.loadURL(url, '', this, show_browser ); // show_log //show_popup //OR// show_browser
} //findlayerclick
////
function show_browser(response) {
alert(response.responseText);
}
////
} //end init function
</script>
</head>
<body onload="init()">
<p id="shortdesc">
procedural node based mapping system .. Keith Legg 2007-2009
</p>
<div id="map" class="smallmap"></div>
<div id="status"></div>
</body>
</html>
#URL IS #http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/apps/keithrox/htdocs/keithrox.map&mode=map&layer=t1
MAP
IMAGETYPE PNG24
EXTENT -3 -3.7 5.58029 2.59539
SIZE 200 300
IMAGECOLOR 0 0 0
##############
#i dont know if this block helps with postgis or not
#WEB
#IMAGEPATH "/ms4w/tmp/ms_tmp/"
#IMAGEURL "/ms_tmp/"
# METADATA
# "wfs_title" "post_test_queue_elle" ## REQUIRED
#"wfs_onlineresource" "http://127.0.0.1/cgi-bin/mapserv.exe?" ## Recommended
#"wfs_srs" "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326" ## Recommended
#"ows_schemas_location" "http://ogc.dmsolutions.ca" ## Optional
# END
#END
#############
SYMBOL
NAME "Circle"
FILLED true
TYPE ellipse
POINTS 1 1 END
END
OUTPUTFORMAT
NAME 'gml3'
MIMETYPE "image/png"
DRIVER AGG/PNG
########################
### DEBUG SHOULD BE :
# MIMETYPE 'text/xml; subtype=gml/3.2.1'
# DRIVER GML3
########################
END
LAYER
NAME "t1"
TEMPLATE 'dummy'
CONNECTIONTYPE postgis
CONNECTION "user=postgres password=password dbname=twatme host=127.0.0.1 port=5432"
DATA "geom from gtestt USING unique id "
STATUS ON
#####
PROJECTION
"init=epsg:4326"
END
#####
DUMP TRUE ## REQUIRED
TYPE POLYGON
METADATA
#"wfs_title" "Provinces" ## REQUIRED
"gml_featureid" "ID" ## REQUIRED
"gml_include_items" "all"
END
CLASS
COLOR 200 255 0
SYMBOL "Circle"
OUTLINECOLOR 255 0 0
EXPRESSION ([id] >= 2)
END
END
END
#URL IS #http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/apps/keithrox/htdocs/keithrox.map&mode=map&layer=t1
MAP
IMAGETYPE PNG24
EXTENT -2 -2.7 4.58029 1.59539
SIZE 200 200
SHAPEPATH "../data"
IMAGECOLOR 196 196 196
LAYER
NAME "t1"
CONNECTIONTYPE postgis
CONNECTION "user=postgres password=password dbname=mydatabase host=127.0.0.1 port=5432"
DATA "geom from gtestt USING unique id "
STATUS ON
TYPE POLYGON
CLASS
COLOR 255 255 0
END
END
END
WITH EXPRESSION IN CLASS
LAYER
NAME "t1"
CONNECTIONTYPE postgis
CONNECTION "user=postgres password=password dbname=twatme host=127.0.0.1 port=5432"
DATA "geom from gtestt USING unique id "
STATUS ON
TYPE POLYGON
CLASS
COLOR 255 255 0
EXPRESSION ([id] >= 0)
END
END
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>webapp node visualizer for project keithrox</title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map({div: 'map', allOverlays: true ,
maxExtent: new OpenLayers.Bounds(-2 ,-2.7, 4.58029, 1.59539),
maxResolution: "auto", controls: [] ,units:"feet", projection:"epsg:26915"});
t1 = new OpenLayers.Layer.MapServer( "t1_lay","http://127.0.0.1/cgi-bin/mapserv.exe?map=/ms4w/apps/keithrox/htdocs/keithrox.map" ,
{layers: "t1"}, {gutter: 15} ,{transparent: true } );
map.addLayer(t1);
nav = new OpenLayers.Control.Navigation();
map.addControl(nav);
map.addControl(new OpenLayers.Control.LayerSwitcher());
} //end init function
</script>
</head>
<body onload="init()">
<p id="shortdesc">
procedural node based mapping system .. Keith Legg 2007-2009
</p>
<div id="map" class="smallmap"></div>
<div id="status"></div>
</body>
</html>
UNTESTED QUERIES
CREATE VIEW qry_users AS SELECT * FROM users WHERE user_type LIKE 'professional' ORDER BY gid;
DATA "the_geom from (select * from qry_ nutzung) as foo using unique gid using SRID=31467"
DATA "the_geom from (SELECT landuse.object_id, landuse.area, forest.type, forest.the_geom FROM landuse INNER JOIN forest ON landuse.gid = forest.gid) as foo using unique gid using SRID=4326"
FILTERS
FILTER "[filteritem] = [Kriterium]" Example: Selection of users with type = "professional" DATA "the_geom from (select * from qry_users) as foo using unique gid using SRID=4326" FILTER "user_type > 'professional'"
DATA "the_geom from tbl_streets" FILTER "(substr(street_name, (length(street_name)-1), 1)) BETWEEN 0 and 9"
Load CSV File:
Upload CSV files (comma separated value), for example if oyu need to include data from a DBF file (which contains the alphanumerical attributes of a flat GIS Shape file.
>>Load DBF file with OpenOffice.org and store it as CSV >>Create table with corresponding fields: CREATE TABLE mytable (id int8, area float8, boart varchar) WITH OIDS; >>Copy CVS file from hard disk COPY mytable FROM ‘/data/postgis_schulung/poi.csv’;
> CONNECTIONTYPE postgis > > DATA "the_geom from sample" > > #DATA "the_geom from mytilus USING UNIQUE id using srid=4326" > > #DATA "the_geom from (select sample.sample_key as id, > sample.the_geom, species.name as name from sample inner join species > on species.sample_key = sample.sample_key where species.name= > '%speciesname%' ) as foo USING UNIQUE id using srid=4326" > > #DATA "the_geom from (select species.taxon_key as id, > sample.sample_key, sample.the_geom, species.name as name from sample > inner join species on species.sample_key = sample.sample_key where > species.name= 'Mytilus edulis' ) as foo USING UNIQUE id using > srid=4326"

