SlideShare une entreprise Scribd logo
1  sur  31
MapServer #ProTips 
FOSS4G Portland 09/11/14 
MapServer for Power Users 
A collection of tips to streamline your mapping workflow
#Protip: Use OGR Output format for 
generating GeoJSON 
FOSS4G Portland 09/11/14
WFS OGR Outputformat - GeoJSON 
FOSS4G Portland 09/11/14 
OUTPUTFORMAT 
NAME "geojson" 
DRIVER "OGR/GEOJSON" 
MIMETYPE "application/json; subtype=geojson" 
FORMATOPTION "STORAGE=stream" 
FORMATOPTION "FORM=SIMPLE" 
END 
Just add: &request=getFeature&typename=myLayer&outputformat=geojson 
Example: WFS Call - Returns XML WFS - Returns GeoJSON
#Protip: Simplify mapfiles with 
SCALETOKEN 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
SCALETOKENs 
Reduce Mapfile Clutter - Example: US HUC Codes - 6 layers -> 1 layer 
LABELITEM "HUCCODE" 
SCALETOKEN 
NAME "%table%" 
VALUES 
"0" "HUC12 as HUCCODE, shape from USDA.WBDHU12" 
"100000" "HUC10 as HUCCODE, shape from USDA.WBDHU10" 
"700000" "HUC8 as HUCCODE, shape from USDA.WBDHU8" 
"1500000" "HUC6 as HUCCODE, shape from USDA.WBDHU6" 
"3000000" "HUC4 as HUCCODE, shape from USDA.WBDHU4" 
"8000000" "HUC2 as HUCCODE, shape from USDA.WBDHU2" 
END 
END 
DATA "SHAPE from (select %table%) using SRID 4326"
#Protip: Discover performance issues, 
problems, etc with DEBUG 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
DEBUGGING - Part 1 
● set DEBUG level at MAP and/or LAYER level 
● can see GDAL/OGR debug info with CPL_DEBUGMAP 
... 
CONFIG "CPL_DEBUG" "ON" 
... 
LAYER 
... 
END 
END 
● use shp2img command line utility with 
‘-all_debug” switch maximum debug info
FOSS4G Portland 09/11/14 
DEBUGGING - Part 2 
● can execute problem query at the command line (and avoid using Apache/Web server) 
mapserv -nh “QUERY_STRING=” 
● http://www.mapserver.org/optimization/debugging.html
#Protip: Preview layers immediately 
with built in viewer 
FOSS4G Portland 09/11/14
Using Native OpenLayers Viewer 
(part1) 
● added in MapServer 6.0 
● quickly view map output using JS/’slippy’ interface 
● required parameters for CGI request: 
FOSS4G Portland 09/11/14 
&MODE=map&TEMPLATE=OpenLayers 
&LAYERS=all
Using Native OpenLayers Viewer 
(part2) 
● Notes: 
o Points to remote OpenLayers.lib ‘out-of-the-box’ (version 2.10) 
§ http://www.mapserver.org/lib/OpenLayers-ms60.js 
FOSS4G Portland 09/11/14 
o Can use own OL/template
FOSS4G Portland 09/11/14 
Using Native OpenLayers Viewer (demo)
#Protip: Simply your mapfile (and your 
life) with INCLUDEs 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
MapFile INCLUDEs 
● Used anytime you want to reuse something or make a change in one place to affect many 
places 
● Key places: LAYERs, connection strings, metadata, settings, paths, debug info 
● Can be nested 
● File can be given any extension (.lay, .inc)
FOSS4G Portland 09/11/14 
INCLUDE Ideas: 
● Empty INCLUDE for every level (makes easy to add something to every layer) 
● For databases, CONNECTION info and PROCESSING "CLOSE_CONNECTION=DEFER" 
● Standard LAYER METADATA 
● Standard WEB METADATA / OUTPUTFORMATs 
● Projection blocks: INCLUDE "latlon.inc" 
● Standard Label style blocks 
● (Mike) use includes for data layers by category, INCLUDE "include/dam_water_levels.inc", 
which includes 12 layers about Dams
FOSS4G Portland 09/11/14 
Example Mapfile with Includes 
MAP 
NAME mymap 
INCLUDE "include/paths.inc" 
INCLUDE "include/outputformats.inc" 
INCLUDE "include/web.inc" 
#LAYERS 
INCLUDE "include/base_layers.inc" 
INCLUDE "include/mid_layers.inc" 
INCLUDE "include/top_layers.inc" 
END#map
#Protip: Make your maps more colorful 
with COLORRANGE 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
COLORRANGE 
● RFC 6 / RFC 108 / ‘easter egg’ 
● display a range of colors for a range of values 
● useful for display of DEMs 
● No Legend Output 
STYLE 
COLORRANGE 0 0 0 255 255 0 #black to yellow 
DATARANGE 0 to 2000 
RANGEITEM “[pixel]” 
END
FOSS4G Portland 09/11/14 
Multiple COLORRANGEs (7.0) 
OPACITY 60 
CLASS 
STYLE 
COLORRANGE "#0000ff00" "#0000ffff" 
DATARANGE 0 32 
END 
STYLE 
COLORRANGE "#0000ffff" "#ff0000ff" 
DATARANGE 32 255 
END 
END
#Protip: Reduce problems by following 
simple naming guidelines 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
Naming Conventions 
● Avoid, whenever possible, using LAYER NAMEs with spaces, special characters, numbers at the 
beginning, or uppercase. LAYER NAMEs are Case Sensitive. Never use colons (:), they will be 
treated as namespace characters in the OGC output 
● The issue is not MapServer, but often painful challenges ‘downstream’ (URLs, OGC Specs, 
WMS/OWS, other applications, …) 
● For Oracle, use all uppercase Column Names in the database (Oracle standard), can't start 
with numbers, max 30 characters. 
● For PostgreSQL, can’t start with numbers, use lowercase, max 63 characters.
#Protip: Combine multiple point 
features into a CLUSTER 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
CLUSTERing Points 
● Requires MapServer 6.0 or later 
● Only for POINT layers 
● Based on relative distance in pixels 
● Query all clustered features with 
PROCESSING "CLUSTER_GET_ALL_SHAPES"
#Protip: Combine TILEINDEXes across 
multiple projections 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
TILEINDEXes with SRS Support 
● Requires GDALTINDEX from 1.11 or later, MapServer 6.4 or later 
● call GDALTINDEX with -src_srs_name to add SRS field to index and -t_srs output projection 
gdaltindex -t_srs epsg:3857 -src_srs_name SRS ti.shp imagery/naip/*.jp2 
● Also make sure to add a spatial index to the TILEINDEX 
o use OGR or SHPTREE to add Shapefile spatial index 
● However, TILEINDEXes don't have to be shapefiles, can be other formats 
● If path to TILEINDEX is not absolute, it will be affected by SHAPEPATH 
● Only for RASTERS
FOSS4G Portland 09/11/14 
TILEINDEXes with SRS Support 
LAYER 
name naip16 
TYPE raster 
PROJECTION 
"init=epsg:32616" 
END 
group "naip" 
TILEINDEX "tileindexes/zones/ti_zone16.shp" 
TILEITEM "PATH" 
STATUS OFF 
FILTERITEM "PROGRAM" 
FILTER "NAIP" 
METADATA 
"ows_name" "naip16" 
... 
END 
PROCESSING "OVERSAMPLE_RATIO=1.0" 
END 
LAYER 
name naip17 
TYPE raster 
PROJECTION 
"init=epsg:32617" 
END 
group "naip" 
TILEINDEX "tileindexes/zones/ti_zone17.shp" 
TILEITEM "PATH" 
... 
16 total layers 
LAYER 
name naip 
TYPE raster 
PROJECTION 
"init=epsg:3857" 
END 
TILEINDEX "tileindexes/naip.shp" 
TILEITEM "PATH" 
TILESRS "SRS" 
STATUS OFF 
FILTERITEM "PROGRAM" 
FILTER "NAIP" 
METADATA 
"ows_name" "naip" 
... 
END 
PROCESSING "OVERSAMPLE_RATIO=1.0" 
END
#Protip: Increase performance by 
setting layer extents 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
“ows_extent” METADATA 
● set it to avoid MapServer calculating the extents of your data layer on each request 
● Sometimes solves problems for certain formats (OracleSpatial layer through OWS request)
#Protip: Catch errors quicker and 
easier with syntax highlighting 
FOSS4G Portland 09/11/14
FOSS4G Portland 09/11/14 
Syntax Highlighting - Editor 
Sublime 2 - https://github.com/richardsuematsu/sublime-text-2-mapserver 
UltraEdit - http://www.ultraedit.com/files/wf/mapserver.uew 
Notepad++ - https://github.com/AstunTechnology/MapserverSyntaxHighlighting 
VIM - http://mapserver.org/development/editing/vim.html 
Emacs - https://github.com/AxxL/mapserver-emacs-mode 
Textpad - http://www.textpad.com/add-ons/files/syntax/map_40.zip 
● Code folding is very useful to find missings/extra ENDs in mapfiles 
● Comment block macros are also very useful for mapfiles
FOSS4G Portland 09/11/14 
Thank you for using MapServer! 
@mapserving @michael_smith

Contenu connexe

En vedette

FOSS4G 2013 Osaka karaoke LT 課題スライド
FOSS4G 2013 Osaka karaoke LT 課題スライドFOSS4G 2013 Osaka karaoke LT 課題スライド
FOSS4G 2013 Osaka karaoke LT 課題スライド
Kosuke Asahi
 

En vedette (20)

FOSS4G KOREA 2012参加報告
FOSS4G KOREA 2012参加報告FOSS4G KOREA 2012参加報告
FOSS4G KOREA 2012参加報告
 
FOSS4G 2013 Osaka karaoke LT 課題スライド
FOSS4G 2013 Osaka karaoke LT 課題スライドFOSS4G 2013 Osaka karaoke LT 課題スライド
FOSS4G 2013 Osaka karaoke LT 課題スライド
 
FOSS4G Osaka 2013
FOSS4G Osaka 2013FOSS4G Osaka 2013
FOSS4G Osaka 2013
 
電子国土Part2
電子国土Part2電子国土Part2
電子国土Part2
 
Map server入門 - FOSS4G 2012 Hokkaido
Map server入門 - FOSS4G 2012 HokkaidoMap server入門 - FOSS4G 2012 Hokkaido
Map server入門 - FOSS4G 2012 Hokkaido
 
20分で語るFOSS4Gの10年
20分で語るFOSS4Gの10年20分で語るFOSS4Gの10年
20分で語るFOSS4Gの10年
 
Foss4 g2014pd xreport
Foss4 g2014pd xreportFoss4 g2014pd xreport
Foss4 g2014pd xreport
 
Foss4g資料西林
Foss4g資料西林Foss4g資料西林
Foss4g資料西林
 
Application insights で行ってみよう
Application insights で行ってみようApplication insights で行ってみよう
Application insights で行ってみよう
 
JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門JavaScript GIS ライブラリ turf.js 入門
JavaScript GIS ライブラリ turf.js 入門
 
20161030 foss4 g2016_yamakawa
20161030 foss4 g2016_yamakawa20161030 foss4 g2016_yamakawa
20161030 foss4 g2016_yamakawa
 
FOSS4G と北海道地図
FOSS4G と北海道地図FOSS4G と北海道地図
FOSS4G と北海道地図
 
地理空間オープンデータの可視化をオープンソースGISで簡単に!
地理空間オープンデータの可視化をオープンソースGISで簡単に!地理空間オープンデータの可視化をオープンソースGISで簡単に!
地理空間オープンデータの可視化をオープンソースGISで簡単に!
 
FOSS4Gと地理院地図
FOSS4Gと地理院地図FOSS4Gと地理院地図
FOSS4Gと地理院地図
 
Leaflet初級編 - Web地図サイトを構築してみよう-
Leaflet初級編 - Web地図サイトを構築してみよう-Leaflet初級編 - Web地図サイトを構築してみよう-
Leaflet初級編 - Web地図サイトを構築してみよう-
 
地理院地図を手軽に使える オープンソースソフトウェア (FOSS4G) のご紹介
地理院地図を手軽に使えるオープンソースソフトウェア (FOSS4G)のご紹介地理院地図を手軽に使えるオープンソースソフトウェア (FOSS4G)のご紹介
地理院地図を手軽に使える オープンソースソフトウェア (FOSS4G) のご紹介
 
QGIS講習会【印刷編】
QGIS講習会【印刷編】QGIS講習会【印刷編】
QGIS講習会【印刷編】
 
GESTISS_WebGIS_System_v3
GESTISS_WebGIS_System_v3GESTISS_WebGIS_System_v3
GESTISS_WebGIS_System_v3
 
QGIS(v2.2)初級編 さわってみようQGIS
QGIS(v2.2)初級編 さわってみようQGISQGIS(v2.2)初級編 さわってみようQGIS
QGIS(v2.2)初級編 さわってみようQGIS
 
LeafletでWebGIS入門
LeafletでWebGIS入門LeafletでWebGIS入門
LeafletでWebGIS入門
 

Plus de Jeff McKenna

Plus de Jeff McKenna (20)

Fostering pre-university student participation in OSGeo through the Google Co...
Fostering pre-university student participation in OSGeo through the Google Co...Fostering pre-university student participation in OSGeo through the Google Co...
Fostering pre-university student participation in OSGeo through the Google Co...
 
Brief FOSS4G Introduction
Brief FOSS4G IntroductionBrief FOSS4G Introduction
Brief FOSS4G Introduction
 
The Open Community
The Open CommunityThe Open Community
The Open Community
 
The Geo Industry Today
The Geo Industry TodayThe Geo Industry Today
The Geo Industry Today
 
OSGeo's Global Vision
OSGeo's Global VisionOSGeo's Global Vision
OSGeo's Global Vision
 
MapServer #ProTips 2015
MapServer #ProTips 2015MapServer #ProTips 2015
MapServer #ProTips 2015
 
Looking Ahead: the Open Source Geospatial Foundation
Looking Ahead: the Open Source Geospatial FoundationLooking Ahead: the Open Source Geospatial Foundation
Looking Ahead: the Open Source Geospatial Foundation
 
History of the GRASS GIS Video from 1987 (with William Shatner)
History of the GRASS GIS Video from 1987 (with William Shatner)History of the GRASS GIS Video from 1987 (with William Shatner)
History of the GRASS GIS Video from 1987 (with William Shatner)
 
OSGeo's Annual General Meeting (AGM), 2014, Opening Slides
OSGeo's Annual General Meeting (AGM), 2014, Opening SlidesOSGeo's Annual General Meeting (AGM), 2014, Opening Slides
OSGeo's Annual General Meeting (AGM), 2014, Opening Slides
 
The Open Source Geospatial Community
The Open Source Geospatial CommunityThe Open Source Geospatial Community
The Open Source Geospatial Community
 
MapServer Project Status 2013
MapServer Project Status 2013MapServer Project Status 2013
MapServer Project Status 2013
 
Open Source Geospatial: then and now
Open Source Geospatial: then and nowOpen Source Geospatial: then and now
Open Source Geospatial: then and now
 
WMS Performance Shootout 2011
WMS Performance Shootout 2011WMS Performance Shootout 2011
WMS Performance Shootout 2011
 
MapServer Project Status (from FOSS4G2010)
MapServer Project Status (from FOSS4G2010)MapServer Project Status (from FOSS4G2010)
MapServer Project Status (from FOSS4G2010)
 
WMS Performance Shootout 2010
WMS Performance Shootout 2010WMS Performance Shootout 2010
WMS Performance Shootout 2010
 
Fostering FOSS4G through International Collaboration
Fostering FOSS4G through International CollaborationFostering FOSS4G through International Collaboration
Fostering FOSS4G through International Collaboration
 
OSGeo Conferences Report
OSGeo Conferences ReportOSGeo Conferences Report
OSGeo Conferences Report
 
WMS Performance Shootout 2009
WMS Performance Shootout 2009WMS Performance Shootout 2009
WMS Performance Shootout 2009
 
MapServer Project Status Report 2009
MapServer Project Status Report 2009MapServer Project Status Report 2009
MapServer Project Status Report 2009
 
Summary of OGC Support by MapServer
Summary of OGC Support by MapServerSummary of OGC Support by MapServer
Summary of OGC Support by MapServer
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

MapServer #ProTips

  • 1. MapServer #ProTips FOSS4G Portland 09/11/14 MapServer for Power Users A collection of tips to streamline your mapping workflow
  • 2. #Protip: Use OGR Output format for generating GeoJSON FOSS4G Portland 09/11/14
  • 3. WFS OGR Outputformat - GeoJSON FOSS4G Portland 09/11/14 OUTPUTFORMAT NAME "geojson" DRIVER "OGR/GEOJSON" MIMETYPE "application/json; subtype=geojson" FORMATOPTION "STORAGE=stream" FORMATOPTION "FORM=SIMPLE" END Just add: &request=getFeature&typename=myLayer&outputformat=geojson Example: WFS Call - Returns XML WFS - Returns GeoJSON
  • 4. #Protip: Simplify mapfiles with SCALETOKEN FOSS4G Portland 09/11/14
  • 5. FOSS4G Portland 09/11/14 SCALETOKENs Reduce Mapfile Clutter - Example: US HUC Codes - 6 layers -> 1 layer LABELITEM "HUCCODE" SCALETOKEN NAME "%table%" VALUES "0" "HUC12 as HUCCODE, shape from USDA.WBDHU12" "100000" "HUC10 as HUCCODE, shape from USDA.WBDHU10" "700000" "HUC8 as HUCCODE, shape from USDA.WBDHU8" "1500000" "HUC6 as HUCCODE, shape from USDA.WBDHU6" "3000000" "HUC4 as HUCCODE, shape from USDA.WBDHU4" "8000000" "HUC2 as HUCCODE, shape from USDA.WBDHU2" END END DATA "SHAPE from (select %table%) using SRID 4326"
  • 6. #Protip: Discover performance issues, problems, etc with DEBUG FOSS4G Portland 09/11/14
  • 7. FOSS4G Portland 09/11/14 DEBUGGING - Part 1 ● set DEBUG level at MAP and/or LAYER level ● can see GDAL/OGR debug info with CPL_DEBUGMAP ... CONFIG "CPL_DEBUG" "ON" ... LAYER ... END END ● use shp2img command line utility with ‘-all_debug” switch maximum debug info
  • 8. FOSS4G Portland 09/11/14 DEBUGGING - Part 2 ● can execute problem query at the command line (and avoid using Apache/Web server) mapserv -nh “QUERY_STRING=” ● http://www.mapserver.org/optimization/debugging.html
  • 9. #Protip: Preview layers immediately with built in viewer FOSS4G Portland 09/11/14
  • 10. Using Native OpenLayers Viewer (part1) ● added in MapServer 6.0 ● quickly view map output using JS/’slippy’ interface ● required parameters for CGI request: FOSS4G Portland 09/11/14 &MODE=map&TEMPLATE=OpenLayers &LAYERS=all
  • 11. Using Native OpenLayers Viewer (part2) ● Notes: o Points to remote OpenLayers.lib ‘out-of-the-box’ (version 2.10) § http://www.mapserver.org/lib/OpenLayers-ms60.js FOSS4G Portland 09/11/14 o Can use own OL/template
  • 12. FOSS4G Portland 09/11/14 Using Native OpenLayers Viewer (demo)
  • 13. #Protip: Simply your mapfile (and your life) with INCLUDEs FOSS4G Portland 09/11/14
  • 14. FOSS4G Portland 09/11/14 MapFile INCLUDEs ● Used anytime you want to reuse something or make a change in one place to affect many places ● Key places: LAYERs, connection strings, metadata, settings, paths, debug info ● Can be nested ● File can be given any extension (.lay, .inc)
  • 15. FOSS4G Portland 09/11/14 INCLUDE Ideas: ● Empty INCLUDE for every level (makes easy to add something to every layer) ● For databases, CONNECTION info and PROCESSING "CLOSE_CONNECTION=DEFER" ● Standard LAYER METADATA ● Standard WEB METADATA / OUTPUTFORMATs ● Projection blocks: INCLUDE "latlon.inc" ● Standard Label style blocks ● (Mike) use includes for data layers by category, INCLUDE "include/dam_water_levels.inc", which includes 12 layers about Dams
  • 16. FOSS4G Portland 09/11/14 Example Mapfile with Includes MAP NAME mymap INCLUDE "include/paths.inc" INCLUDE "include/outputformats.inc" INCLUDE "include/web.inc" #LAYERS INCLUDE "include/base_layers.inc" INCLUDE "include/mid_layers.inc" INCLUDE "include/top_layers.inc" END#map
  • 17. #Protip: Make your maps more colorful with COLORRANGE FOSS4G Portland 09/11/14
  • 18. FOSS4G Portland 09/11/14 COLORRANGE ● RFC 6 / RFC 108 / ‘easter egg’ ● display a range of colors for a range of values ● useful for display of DEMs ● No Legend Output STYLE COLORRANGE 0 0 0 255 255 0 #black to yellow DATARANGE 0 to 2000 RANGEITEM “[pixel]” END
  • 19. FOSS4G Portland 09/11/14 Multiple COLORRANGEs (7.0) OPACITY 60 CLASS STYLE COLORRANGE "#0000ff00" "#0000ffff" DATARANGE 0 32 END STYLE COLORRANGE "#0000ffff" "#ff0000ff" DATARANGE 32 255 END END
  • 20. #Protip: Reduce problems by following simple naming guidelines FOSS4G Portland 09/11/14
  • 21. FOSS4G Portland 09/11/14 Naming Conventions ● Avoid, whenever possible, using LAYER NAMEs with spaces, special characters, numbers at the beginning, or uppercase. LAYER NAMEs are Case Sensitive. Never use colons (:), they will be treated as namespace characters in the OGC output ● The issue is not MapServer, but often painful challenges ‘downstream’ (URLs, OGC Specs, WMS/OWS, other applications, …) ● For Oracle, use all uppercase Column Names in the database (Oracle standard), can't start with numbers, max 30 characters. ● For PostgreSQL, can’t start with numbers, use lowercase, max 63 characters.
  • 22. #Protip: Combine multiple point features into a CLUSTER FOSS4G Portland 09/11/14
  • 23. FOSS4G Portland 09/11/14 CLUSTERing Points ● Requires MapServer 6.0 or later ● Only for POINT layers ● Based on relative distance in pixels ● Query all clustered features with PROCESSING "CLUSTER_GET_ALL_SHAPES"
  • 24. #Protip: Combine TILEINDEXes across multiple projections FOSS4G Portland 09/11/14
  • 25. FOSS4G Portland 09/11/14 TILEINDEXes with SRS Support ● Requires GDALTINDEX from 1.11 or later, MapServer 6.4 or later ● call GDALTINDEX with -src_srs_name to add SRS field to index and -t_srs output projection gdaltindex -t_srs epsg:3857 -src_srs_name SRS ti.shp imagery/naip/*.jp2 ● Also make sure to add a spatial index to the TILEINDEX o use OGR or SHPTREE to add Shapefile spatial index ● However, TILEINDEXes don't have to be shapefiles, can be other formats ● If path to TILEINDEX is not absolute, it will be affected by SHAPEPATH ● Only for RASTERS
  • 26. FOSS4G Portland 09/11/14 TILEINDEXes with SRS Support LAYER name naip16 TYPE raster PROJECTION "init=epsg:32616" END group "naip" TILEINDEX "tileindexes/zones/ti_zone16.shp" TILEITEM "PATH" STATUS OFF FILTERITEM "PROGRAM" FILTER "NAIP" METADATA "ows_name" "naip16" ... END PROCESSING "OVERSAMPLE_RATIO=1.0" END LAYER name naip17 TYPE raster PROJECTION "init=epsg:32617" END group "naip" TILEINDEX "tileindexes/zones/ti_zone17.shp" TILEITEM "PATH" ... 16 total layers LAYER name naip TYPE raster PROJECTION "init=epsg:3857" END TILEINDEX "tileindexes/naip.shp" TILEITEM "PATH" TILESRS "SRS" STATUS OFF FILTERITEM "PROGRAM" FILTER "NAIP" METADATA "ows_name" "naip" ... END PROCESSING "OVERSAMPLE_RATIO=1.0" END
  • 27. #Protip: Increase performance by setting layer extents FOSS4G Portland 09/11/14
  • 28. FOSS4G Portland 09/11/14 “ows_extent” METADATA ● set it to avoid MapServer calculating the extents of your data layer on each request ● Sometimes solves problems for certain formats (OracleSpatial layer through OWS request)
  • 29. #Protip: Catch errors quicker and easier with syntax highlighting FOSS4G Portland 09/11/14
  • 30. FOSS4G Portland 09/11/14 Syntax Highlighting - Editor Sublime 2 - https://github.com/richardsuematsu/sublime-text-2-mapserver UltraEdit - http://www.ultraedit.com/files/wf/mapserver.uew Notepad++ - https://github.com/AstunTechnology/MapserverSyntaxHighlighting VIM - http://mapserver.org/development/editing/vim.html Emacs - https://github.com/AxxL/mapserver-emacs-mode Textpad - http://www.textpad.com/add-ons/files/syntax/map_40.zip ● Code folding is very useful to find missings/extra ENDs in mapfiles ● Comment block macros are also very useful for mapfiles
  • 31. FOSS4G Portland 09/11/14 Thank you for using MapServer! @mapserving @michael_smith

Notes de l'éditeur

  1. All data: shp2img -m /home/gridusr/GRiD/vendor/corpsmap/mapfiles/lidarthon.map -map_debug 3 -o test.png -l eq_cluster Limited extent: shp2img -m /home/gridusr/GRiD/vendor/corpsmap/mapfiles/lidarthon.map -map_debug 3 -o test.png -l eq_cluster -e -121 36 -118 37
  2. mapserv -nh QUERY_STRING="map=/home/gridusr/GRiD/vendor/corpsmap/mapfiles/lidarthon.map&outputformat=geojson&service=wfs&version=1.0.0&request=getfeature&typename=earthquakes_oracle2&bbox=-121.793793%2C36.701393%2C-118.555573%2C37.546691"