What readers are saying about GIS for Web Developers This book is a perfect introduction to integrating robust mapping capabilities into your web applications, using highly maintainable, standards-compliant techniques. Scott manages to convey an enor- mous amount of GIS domain knowledge in a very succinct and under- standable way. Donald Marino GIS SoftwareEngineer, ITT Visual Information Solutions The best published introduction to getting started with GeoServer quickly and effectively. Scott introduces all the concepts needed to get going and then puts these into action with clear examples. I highly recommend this book to any web developer looking to get up to speed with the geospatial world. Chris Holmes Chair, GeoServer Project Steering Committee A friendly, informativeguide through the wilderness of GIS tools and specifications. Scott has an upbeat, optimistic quality that comes through on almost on every page. His explanations are clear and understandable, and he never makes light of the complexities of the subject. Kenneth A., Kousen, Ph.D. President, Kousen IT, Inc. Scott’s conversational style is easy to read and well informed. I’m thrilledto see him opening up what he aptly refersto as “black boxes of geographical wonder.” It reminds me of the whole reason I dove into open source in the first place. It’s a good read and provides a handy introduction to fundamental concepts as well as several tools that have not be introduced in a book before. Tyler Mitchell Author, Web Mapping Illustrated I really enjoyed the book, and I came from a background where I had no knowledge of GIS. I enjoyed the author’s great sense of humor throughout the book. I feel I understand GIS a lot better now both in termsof what GIS is and the open source tools available for devel- opers. The book has you implement a real-world application, which really helps you learn the material in a way that just reading about the tools cannot accomplish. Greg Ostravich President, Denver Java Users Group GIS for Web Developers Adding Where to Your Web Applications Scott Davis The Pragmatic Bookshelf Raleigh,NorthCarolina Dallas,Texas Many of the designations used by manufacturers and sellers to distinguish their prod- uctsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andThe Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The PragmaticProgrammer,PragmaticProgramming,PragmaticBookshelfandthelinkingg devicearetrademarksofThePragmaticProgrammers,LLC. Every precaution was taken in the preparation of this book. However, the publisher assumesnoresponsibility for errorsor omissions,or for damagesthatmay result from theuseofinformation(includingprogramlistings)containedherein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatictitles,pleasevisitusat http://www.pragmaticprogrammer.com Copyright©2007ThePragmaticProgrammersLLC. Allrightsreserved. Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmit- ted, in any form, or by any means, electronic,mechanical,photocopying, recording, or otherwise,withoutthepriorconsentofthepublisher. ISBN-10:0-9745140-9-8 ISBN-13:978-0-9745140-9-3 Contents Preface 10 Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . 11 1 Introduction 13 1.1 Demystifying GIS . . . . . . . . . . . . . . . . . . . . . . 13 1.2 Finding Free Data Sources and Applications . . . . . . 14 1.3 Becoming a GIS Programmer . . . . . . . . . . . . . . . 16 1.4 What Are You Getting Yourself Into? . . . . . . . . . . . 16 2 Vectors 19 2.1 Raw Materials . . . . . . . . . . . . . . . . . . . . . . . . 19 2.2 Raster Data . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.3 Vector Data . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Types of Vector Data . . . . . . . . . . . . . . . . . . . . 24 2.5 What Data Is Available? . . . . . . . . . . . . . . . . . . 29 2.6 Know Your File Formats . . . . . . . . . . . . . . . . . . 31 2.7 Anatomy of a Shapefile . . . . . . . . . . . . . . . . . . . 32 2.8 The Downloadable States of America. . . . . . . . . . . 32 2.9 Downloading a Viewer . . . . . . . . . . . . . . . . . . . 34 2.10 Styling Your Layers . . . . . . . . . . . . . . . . . . . . . 37 2.11 Viewing Multiple Basemap Layers . . . . . . . . . . . . 38 2.12 More Data, Please . . . . . . . . . . . . . . . . . . . . . . 40 2.13 More International Data, Please . . . . . . . . . . . . . 40 2.14 When Good Data Goes Bad . . . . . . . . . . . . . . . . 41 2.15 Saving Your Map in ArcExplorer . . . . . . . . . . . . . 42 2.16 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 44 3 Projections 45 3.1 The Round Earth . . . . . . . . . . . . . . . . . . . . . . 45 3.2 Cartesian Planes . . . . . . . . . . . . . . . . . . . . . . 48 3.3 What Is a Projection? . . . . . . . . . . . . . . . . . . . . 52 3.4 Changing Projections in ArcExplorer . . . . . . . . . . . 54 CONTENTS 8 3.5 What Does Round Really Mean, Anyway? . . . . . . . . 55 3.6 Coordinate Reference Systems . . . . . . . . . . . . . . 57 3.7 Getting Your Data Layers Aligned . . . . . . . . . . . . 65 3.8 Reprojection Utilities . . . . . . . . . . . . . . . . . . . . 67 3.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 70 4 Rasters 71 4.1 Getting Startedwith Raster Data . . . . . . . . . . . . . 71 4.2 Terraserver-USA: Another Source of Free Raster Imagery 74 4.3 Mosaics and Tessellation . . . . . . . . . . . . . . . . . 76 4.4 Temporal Analysis . . . . . . . . . . . . . . . . . . . . . 78 4.5 Panchromatic vs. Multispectral . . . . . . . . . . . . . . 81 4.6 Scale and Resolution . . . . . . . . . . . . . . . . . . . . 86 4.7 Orthorectification . . . . . . . . . . . . . . . . . . . . . . 90 4.8 Downloading Free Rasters . . . . . . . . . . . . . . . . . 93 4.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5 Spatial Databases 108 5.1 Why Bother with a Spatial Database? . . . . . . . . . . 108 5.2 Installing PostgreSQL and PostGIS . . . . . . . . . . . . 109 5.3 Adding Spatial Fields . . . . . . . . . . . . . . . . . . . . 111 5.4 Inserting Spatial Data . . . . . . . . . . . . . . . . . . . 117 5.5 Querying Spatial Data . . . . . . . . . . . . . . . . . . . 118 5.6 Introspection of Spatial Data . . . . . . . . . . . . . . . 119 5.7 Importing Data . . . . . . . . . . . . . . . . . . . . . . . 121 5.8 Manipulating Data . . . . . . . . . . . . . . . . . . . . . 122 5.9 Exporting Data . . . . . . . . . . . . . . . . . . . . . . . 123 5.10 Indexing Data . . . . . . . . . . . . . . . . . . . . . . . . 126 5.11 Spatial Queries . . . . . . . . . . . . . . . . . . . . . . . 128 5.12 Visualizing Data. . . . . . . . . . . . . . . . . . . . . . . 132 5.13 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 133 6 Creating OGC Web Services 134 6.1 Sharing the Wealth . . . . . . . . . . . . . . . . . . . . . 134 6.2 OGC SOA for GIS . . . . . . . . . . . . . . . . . . . . . . 135 6.3 Installing GeoServer . . . . . . . . . . . . . . . . . . . . 137 6.4 Adding Shapefiles Using the GUI . . . . . . . . . . . . . 139 6.5 Adding Shapefiles Manually . . . . . . . . . . . . . . . . 143 6.6 Adding PostGIS Layers . . . . . . . . . . . . . . . . . . . 148 6.7 Styling with SLD . . . . . . . . . . . . . . . . . . . . . . 151 6.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 156 CONTENTS 9 7 Using OGC Web Services 157 7.1 Understanding WMS . . . . . . . . . . . . . . . . . . . . 157 7.2 WMS GetCapabilities . . . . . . . . . . . . . . . . . . . . 158 7.3 WMS GetMap . . . . . . . . . . . . . . . . . . . . . . . . 164 7.4 Understanding WFS . . . . . . . . . . . . . . . . . . . . 165 7.5 WFS GetCapabilities . . . . . . . . . . . . . . . . . . . . 166 7.6 WFS DescribeFeatureType . . . . . . . . . . . . . . . . . 169 7.7 WFS GetFeature . . . . . . . . . . . . . . . . . . . . . . 170 7.8 Filtering WFS GetFeature Requests . . . . . . . . . . . 171 7.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8 OGC Clients 179 8.1 Mapbuilder . . . . . . . . . . . . . . . . . . . . . . . . . 179 8.2 OpenLayers . . . . . . . . . . . . . . . . . . . . . . . . . 190 8.3 uDig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 8.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 201 9 Bringing It All Together 202 9.1 From CSV to SQL . . . . . . . . . . . . . . . . . . . . . . 202 9.2 Geocoding Your Data . . . . . . . . . . . . . . . . . . . . 215 9.3 Adding PostGIS Fields . . . . . . . . . . . . . . . . . . . 223 9.4 Setting Up OGC Services . . . . . . . . . . . . . . . . . 226 9.5 Tiling vs. Styling . . . . . . . . . . . . . . . . . . . . . . 229 9.6 Creating a Slippy Map . . . . . . . . . . . . . . . . . . . 233 9.7 Beyond the Web: 3D Viewers . . . . . . . . . . . . . . . 237 9.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 242 A Mac/Linux Installation 243 A.1 Installing GDAL/Proj/Geos . . . . . . . . . . . . . . . . 243 A.2 Installing PostgreSQL and PostGIS . . . . . . . . . . . . 245 A.3 LibTIFF and LibGeoTIFF . . . . . . . . . . . . . . . . . . 248 B Installing Groovy 249 B.1 Unix, Linux, and Mac OS X . . . . . . . . . . . . . . . . 249 B.2 Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Index 253 Preface We are on the edge of the next big wave of technology, and it has GIS written all over it. Soon every new cell phone will have GPS (or some form of location-based services) built in as a standard feature. Nearly every major database vendor now includes native geographic data types. Free sources of geographic data and free applications are just waiting for you to pull themtogether and do something clever. You might create a simple digital version of the pushpin map, or you might writethe next Google Maps killer. All of our lives we’ve asked “Where am I?” and “How do I get from here to there?” You start by rolling over, then crawling, and then walking. You walked to school or were driven or took the bus. Maybe you eventually drove yourself. When you got older, you joined a society of people who use different modes of transportation every day. We ride subways to work. We take airplane flights to far-off places. We visit client locations. We attend conferences or night classes. We go shopping. We eat out at restaurants. Unless you spend your days physically tied to something large,heavy, andimmobile, you probably spend a significant portion of your timethinkingabout how togetfromheretothereandback again. Andhowdoestraditionalgeographymakethateasier?Itoffersyouvec- torandrasterdata,orthographicallyrectifiedandportrayedintheUni- versal Transverse Mercator projection. (Don’t you feel better already?) Even asking a simple question like “What is your current latitude and longitude?” will likely cause most people to back away slowly, hands up, muttering, “That’s OK—I’ll ask someone else for directions.” In GIS for Web Developers we’ll talk about GIS in simple terms and demonstrate its real-world uses.
Description: