Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Beginning Mapserver open source GIS development
Nội dung xem thử
Mô tả chi tiết
Beginning MapServer
Open Source GIS Development
■■■
Bill Kropla
Kropla_4908Front.fm Page i Wednesday, July 20, 2005 7:00 AM
Beginning MapServer: Open Source GIS Development
Copyright © 2005 by Bill Kropla
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN (pbk): 1-59059-490-8
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Jason Gilmore
Technical Reviewers: Howard Butler and Stephen Lime
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore,
Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Associate Publisher: Grace Wong
Project Managers: Tracy Brown-Collins and Beckie Stones
Copy Edit Manager: Nicole LeClerc
Copy Editor: Damon Larson
Assistant Production Director: Kari Brooks-Copony
Production Editor: Kelly Winquist
Compositor: Susan Glinert
Proofreader: Linda Seifert
Indexer: Carol Burbo
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Downloads section.
Kropla_4908Front.fm Page ii Wednesday, July 20, 2005 7:00 AM
For my children.
Kropla_4908Front.fm Page iii Wednesday, July 20, 2005 7:00 AM
Kropla_4908Front.fm Page iv Wednesday, July 20, 2005 7:00 AM
v
Contents at a Glance
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
■CHAPTER 1 Building MapServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
■CHAPTER 2 Simple MapServer Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
■CHAPTER 3 Creating the Mapping Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
■CHAPTER 4 Modifying a Map’s Look and Feel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
■CHAPTER 5 Using Query Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
■CHAPTER 6 Using Perl MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
■CHAPTER 7 Using Python MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
■CHAPTER 8 Using PHP/MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
■CHAPTER 9 Extending the Capabilities of MapScript with MySQL . . . . . . . . . . 231
■CHAPTER 10 Utility Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
■CHAPTER 11 MapServer Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
■APPENDIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Kropla_4908Front.fm Page v Wednesday, July 20, 2005 7:00 AM
Kropla_4908Front.fm Page vi Wednesday, July 20, 2005 7:00 AM
vii
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
■CHAPTER 1 Building MapServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Planning the Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Selecting Supporting Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Getting the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Building and Installing the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Building and Installing zlib. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Building and Installing libpng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Building and Installing libJPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Building and Installing FreeType. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Building and Installing GD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Building and Installing Proj.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Building and Installing GDAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Building and Installing shapelib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Building and Installing MapServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Configuring MapServer and Apache . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
■CHAPTER 2 Simple MapServer Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Building a “Hello World” Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Creating the Mapfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Creating the Initialization File and HTML Template . . . . . . . . . . . . . 20
Contents
Kropla_4908Front.fm Page vii Wednesday, July 20, 2005 7:00 AM
viii ■CONTENTS
Building the First Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Creating the first.map Mapfile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Building the HTML Template for the First Map . . . . . . . . . . . . . . . . . 28
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
■CHAPTER 3 Creating the Mapping Application . . . . . . . . . . . . . . . . . . . . . . . . 31
Mapfile Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
The Structure of the Mapfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The LAYER Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The CLASS Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Mapfile Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The Mapfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Layer 1: Urban Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Layer 2: Water Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Layer 3: State Boundaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Layer 4: Road Network. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
The HTML Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
The Initialization File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
The Template File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
■CHAPTER 4 Modifying a Map’s Look and Feel . . . . . . . . . . . . . . . . . . . . . . . . 55
The Graphic Design of Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Labeling for Clarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Color. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Using Scale to Reduce Clutter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Classifying Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Using Expressions to Define Classes . . . . . . . . . . . . . . . . . . . . . . . . . 74
Using Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Using Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Using Annotation Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Creating Scale Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Creating Legends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Using Reference Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Kropla_4908Front.fm Page viii Wednesday, July 20, 2005 7:00 AM
■CONTENTS ix
■CHAPTER 5 Using Query Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
How MapServer Processes a Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Query Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Query Templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Maintaining State in Query Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Querymaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Map-Only Query Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Query Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Query Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
QUERY Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
NQUERY Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
ITEMQUERY Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
ITEMNQUERY Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
FEATUREQUERY Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
FEATURENQUERY Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
ITEMFEATUREQUERY Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
ITEMFEATURENQUERY Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
INDEXQUERY Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Query Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Map-Level Query Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Layer-Level Query Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Class-Level Query Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
The QUERYMAP Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
The JOIN Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Substitution Strings and CGI Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Query Substitution Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Query CGI Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
A Query Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
The Mapfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
The Initialization File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The HTML Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
The Query Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Kropla_4908Front.fm Page ix Wednesday, July 20, 2005 7:00 AM
x ■CONTENTS
■CHAPTER 6 Using Perl MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Building and Installing Perl MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Building Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Building Perl MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
The Perl MapScript “Hello World” Application . . . . . . . . . . . . . . . . . . . . . 169
A Practical Perl MapScript Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
■CHAPTER 7 Using Python MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Building and Installing Python MapScript . . . . . . . . . . . . . . . . . . . . . . . . 187
Building Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Building Python MapScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The Python MapScript “Hello World” Application . . . . . . . . . . . . . . . . . . 189
A Practical Python MapScript Application . . . . . . . . . . . . . . . . . . . . . . . . 191
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
■CHAPTER 8 Using PHP/MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Building and Installing PHP/MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Building PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Building PHP/MapScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
The PHP/MapScript “Hello World” Application . . . . . . . . . . . . . . . . . . . . 210
A Practical PHP/MapScript Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
■CHAPTER 9 Extending the Capabilities of MapScript with MySQL . . 231
Describing Application Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Addressing Some Design Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Mozilla vs. IE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Creating the MySQL Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Creating the Application User Account. . . . . . . . . . . . . . . . . . . . . . . 237
Installing the JavaScript Tool Tip Code . . . . . . . . . . . . . . . . . . . . . . 238
Patching PHP MapScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Kropla_4908Front.fm Page x Wednesday, July 20, 2005 7:00 AM
■CONTENTS xi
Building the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
The Application in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Creating the Mapfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
The PHP Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Code Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
■CHAPTER 10 Utility Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
MapServer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
shp2img. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
scalebar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
sortshp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
sym2img . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
shptree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
shptreevis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
tile4ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
shapelib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
dbfcreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
dbfadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
dbfdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
shpcreate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
shpadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
shpdump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
shprewind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
dbfcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
dbfinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
shpcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
shpinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
shpcentrd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
shpdxf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
shpproj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
GDAL/OGR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
ogrinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
ogr2ogr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
ogrtindex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Kropla_4908Front.fm Page xi Wednesday, July 20, 2005 7:00 AM
xii ■CONTENTS
■CHAPTER 11 MapServer Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Mapfile Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Map Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
CLASS Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
FEATURE Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
GRID Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
JOIN Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
LABEL Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
LAYER Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
LEGEND Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
OUTPUTFORMAT Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
PROJECTION Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
QUERYMAP Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Reference Map Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
SCALEBAR Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
STYLE Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
WEB Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
CGI Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Substitution Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
■APPENDIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
The Shapefile Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
File Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Shapefile Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Cartographic Projections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Projection Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Creating and Using Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Symbol Definition Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Creating Vector Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
FONTSET Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
HTML Legends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Kropla_4908Front.fm Page xii Wednesday, July 20, 2005 7:00 AM
xiii
Foreword
Maybe it’s just me, but when someone decides it’s worth the effort and expense to actually
write a book about something like MapServer, it’s a big deal—sort of a watershed moment. So
needless to say, I was very excited when I first heard about this book. At long last, I have something to show to my wife—tangible evidence that I was really doing something during those
long nights in the basement (strangely enough, C code just makes her eyes glaze over—go figure).
First, a bit of history: MapServer arose out of necessity, since in the mid-nineties there were
few, if any, decent commercial alternatives. Initial work centered on web-based front ends to
commercial GIS software. This worked well, but was painfully slow—and I endured constant
complaints from graduate students about licenses for our expensive GIS being used by the
public to make maps online. There had to be a better way.
Mercifully, I found shapelib—which, when paired with the GD graphics library, brought
MapServer to life (and stopped the complaints). Add a few best-of-breed open source packages
(e.g., GDAL, Proj.4, PostGIS, and FreeType) and a number of talented developers—and here we
sit 10 years later with a pretty powerful piece of software.
At its essence, MapServer is conceptually very simple, but unless you share the thought
processes of the core developers, the learning curve can be a bit steep. For many open source
projects, documentation is a weak point, and MapServer is no exception. Actually, there’s a
huge amount of MapServer documentation, but it’s scattered loosely across mailing lists,
sample applications, and websites. That’s why this book is so valuable—especially to someone
new to MapServer.
Bill has brought together all of the information for someone getting started with MapServer
in one place—from installation to MapScript, it’s all here. I appreciate the fact that he read any
existing documentation and actually put it to the test, often finding syntactical inaccuracies
and undocumented features. Fortunately, we all benefit from his pain and suffering.
Bill’s work is more than a MapServer reference manual (see Chapter 11 and the Appendix
for that stuff). It’s full of numerous detailed examples—mapfiles, templates, and scripts that
make learning this stuff far easier. When writing about a technical subject, perspective is everything. As a developer, I often find myself glossing over important details, such as installing the
software—in the case of MapServer, however, these details are crucial.
I continue to enjoy working with this software everyday—either building applications with
it or doing core development. I hope that this book will help users get up to speed quickly so
they can move on to the fun part!
Stephen Lime
MapServer/MapScript Creator
Kropla_4908Front.fm Page xiii Wednesday, July 20, 2005 7:00 AM
Kropla_4908Front.fm Page xiv Wednesday, July 20, 2005 7:00 AM