Web Maps with Leaflet GEOG 319/658 November 24, 2014.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Database management system (DBMS)  a DBMS allows users and other software to store and retrieve data in a structured way  controls the organization,
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
TileMill Quickly and Easily Design Maps for the Web Shaky Sherpa Matt Berg Modi Research Group The Earth Institute. Columbia University.
1 Topic 6 Processing Form Input. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction Form.
GEOG 319/658 November 24, Planning Data & Metadata Geography Programming Feedback, repeat as needed.
Geodatabase basic. The geodatabase The geodatabase is a collection of geographic datasets of various types used in ArcGIS and managed in either a file.
Web Page Development Identify elements of a Web Page Start Notepad
Lecture 4 Geodatabases. Geodatabases Outline  Data types  Geodatabases  Data table joins  Spatial joins  Field calculator  Calculate geometry 
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
CSE3310: Web training A JumpStart for Project.
Attribute Data in GIS Data in GIS are stored as features AND tabular info Tabular information can be associated with features OR Tabular data may NOT be.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
PHP meets MySQL.
GIS Tutorial 1 Lecture 4 Geodatabases. Outline  Data types  Geodatabases  Data table joins  Spatial joins  Field calculator  Calculate geometry.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
Website Development with PHP and MySQL Saving Data.
Chapter 5 Database Processing. Neil uses software to query a database, but it has about 25 standard queries that don’t give him all he needs. He imports.
Microsoft Access Database Software.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
ECE 3553 Final Project by Brian Robl. What is Eventor? A simple, yet effective, website for event planning and searching.  Influence from Facebook Events.
GIS 1 GIS Lecture 4 Geodatabases Copyright – Kristen S. Kurland, Carnegie Mellon University.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
Security Considerations Steve Perry
Geographic Data in GIS. Components of geographic data Three general components to geographic information Three general components to geographic information.
1 Final Review. 2 Final Exam  30% of your grade for the course  December 9 at 7:00 p.m., the regular class time  No makeup exam or alternate times.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Form Handling IDIA 618 Fall 2014 Bridget M. Blodgett.
Secure Authentication. SQL Injection Many web developers are unaware of how SQL queries can be tampered with SQL queries are able to circumvent access.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Thematic Mapping with Google Maps. "US-KS":{code:"US-KS", name:"Kansas", center:{lat: ,lng: },
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Connecting to External Data. Financial data can be obtained from a number of different data sources.
This was written with the assumption that workbooks would be added. Even if these are not introduced until later, the same basic ideas apply Hopefully.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Introduction to GIS Programming Final Project Submitted by Todd Lenkin Geography 375 Spring of 2011 American River College.
CHAPTER 7 LESSON B Creating Database Reports. Lesson B Objectives  Describe the components of a report  Modify report components  Modify the format.
Lecture 2: GIS Fundamentals  Data layers  Feature classes  GIS data properties  Data types –vector and raster  Scale  Accuracy and precision.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Chapter 1: GIS Data Outline Representing the world as a map Coordinate systems Map scale Data quality issues About ArcGIS.
Web Database Programming Using PHP
PHP (Session 2) INFO 257 Supplement.
A Look at Creating & Updating Point Files
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
This shows the user interface and the SQL Select for a situation with two criteria in an AND relationship.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Touring Data with Power Map
Performance and User Experience Improvements to the ASU/NASA Space Grant Website
Website Development Basics with PHP MySQL
Web Systems Development (CSC-215)
Leaflet maps in R Gene Leynes
PHP: Security issues FdSc Module 109 Server side scripting and
Spreadsheets, Modelling & Databases
Tutorial 6 PHP & MySQL Li Xu
PHP Forms and Databases.
September 12-14, 2018 Raleigh, NC.
Presentation transcript:

Web Maps with Leaflet GEOG 319/658 November 24, 2014

Steps Planning Data & Metadata Geography Programming Feedback, repeat as needed Steps

Planning Start by outlining the project: What is the purpose of the map? Who are the intended users? What features are needed? Planning

Data & Metadata Gather data Gather or produce metadata Design and create MySQL tables Data & Metadata

Geography Define geographic scope/scale of map Determine required map layers Collect boundaries or XY data Convert boundary data, as needed Geography

Write code Write more code Test Programming

http://ipsr.ku.edu/ksdata/apps/KCMOtracts.php Specifics

MySQL Relational database with 4 tables for data 1 table for metadata 1 table for boundaries http://www.mysql.com/ MySQL

MySQL Social Characteristics (DP2) GEOID GEOID2 GEOLABEL HC01_VC03 … Economic Characteristics (DP3) GEOID GEOID2 GEOLABEL HC01_VC04 … HC04_VC175 Housing Characteristics (DP4) GEOID GEOID2 GEOLABEL HC01_VC03 … HC04_VC199 Demographic Characteristics (DP5) GEOID GEOID2 GEOLABEL HC01_VC03 … HC04_VC98 Metadata File Type Variable Description Units dec_places Universe Topic Detail1…Detail4 Boundaries GEOIDTXT GEOIDNUM Name INTPTLAT INTPTLON COORDINATES COORDINATES2 MySQL

MySQL Social Characteristics (DP2) GEOID GEOID2 GEOLABEL HC01_VC03 … Economic Characteristics (DP3) GEOID GEOID2 GEOLABEL HC01_VC04 … HC04_VC175 Housing Characteristics (DP4) GEOID GEOID2 GEOLABEL HC01_VC03 … HC04_VC199 Demographic Characteristics (DP5) GEOID GEOID2 GEOLABEL HC01_VC03 … HC04_VC98 Metadata File Type Variable Description Units dec_places Universe Topic Detail1…Detail4 Boundaries GEOIDTXT GEOIDNUM Name INTPTLAT INTPTLON COORDINATES COORDINATES2 MySQL

SELECT * FROM ACS12_METADATA Returns all 2,035 rows and 12 columns in this table SQL

SELECT Description FROM ACS12_METADATA WHERE FILE="DP02" AND variable="HC01_VC03"; SQL

SELECT a. namelsad, b. HC01_VC03, c SELECT a.namelsad, b.HC01_VC03, c.* FROM GeoJSON_Tracts AS a, ACS12_5YR_DP02 AS b, ACS12_METADATA AS c WHERE b.geoid2=20209042002 AND b.geoid2=a.geoidnum AND c.variable="HC01_VC03" AND c.file="DP02" SQL

Reference Peterson text figure 17. 5 on page 330 Reference Peterson text figure 17.5 on page 330. The INSERT INTO code shown in figures 17.5 and 17.7 could be easily generated from an Excel table containing the city names and coordinates. Excel: friend or foe?

Maximum string length in Excel is 32,767 characters. MySQL text field limit is 2^16 or 65,535 characters. Excel: friend or foe?

GeoJSON is a format for communicating geographic data that includes some properties and pairs of coordinates. A point can be simply represented as [-104.99404, 39.75621] GeoJSON

A line can be represented as [ [-105, 40], [-110, 45], [-115, 55] ] GeoJSON

A polygon can be represented as [[ [-104. 05, 48. 99], [-97. 22, 48 GeoJSON

GeoJSON http://ogre.adc4gis.com/ In the case of KCMO, I didn’t have coordinates for the polygon boundaries I only had a shapefile from the U.S. Census Bureau. I was able to clip the shapefile in ArcGIS to the KCMO metro, but post-conversion filtering could occur in notepad. GeoJSON

http://leafletjs.com/ Leaflet

Link to the Leaflet CSS Leaflet

Link to the Leaflet JavaScript

Put a div element where you want the map on the page. Leaflet

Leaflet Start putting elements on you map. Set view and scale Background tile Point Circle Leaflet Polygon Leaflet Quick Start Guide Example - http://leafletjs.com/examples/quick-start-example.html Popup Event

PHP works inside HTML and generates the page on the fly PHP works inside HTML and generates the page on the fly. The simplest example is: <html> <body> <? php echo “Hello World!”; ?> </body> </html> http://ipsr.ku.edu/ksdata/apps/leaflet.php?lat=38.958426&lon=-95.251558 PHP

SAFETY PRECAUTION – if you allow users to enter anything, your application is open to hacking or malicious use. To help prevent misuse, escape potentially harmful characters and validate input. PHP

PHP & Leaflet http://ipsr.ku.edu/ksdata/apps/leaflet.php How might one validate latitude and longitude? Suggest: if (isset($_GET['lat']) && $_GET['lat']>=-90 && $_GET['lat']<=90) { $mylat=$_GET['lat']; }else $mylat=51.5; if (isset($_GET['lon']) && $_GET['lon']>=-180 && $_GET['lon']<=180) { $mylon=$_GET['lon']; }else $mylon=-0.09; PHP & Leaflet

http://ipsr. ku. edu/ksdata/apps/leaflet. php. lat=38. 958426&lon=-95 http://ipsr.ku.edu/ksdata/apps/leaflet.php?lat=38.958426&lon=-95.251558 PHP & Leaflet

Putting it all together Connect to MySQL Run addslashes Check for and validate user input HTML/Javascript to set up page with Leaflet Query MySQL Use PHP to write Javascript for Leaflet based on query results Putting it all together

Reference Peterson text page 347 Reference Peterson text page 347. Author has put the connect code in a separate file and used an include. Connect to MySQL

Run addslashes (just in case)

Check for user input

Set up HTML

Start Javascript

Create classes

Set colors and popup label

Query data & boundaries

Write out Javascript

Write out Javascript

var KCMOtracts =[{ "type": "Feature", "properties": { "STATEFP": "20", "COUNTYFP": "059", "TRACTCE": "954100", "GEOIDTXT": "20059954100", "GEOID2":20059954100, "GEOLABEL": "Census Tract 9541, Franklin County, Kansas", "LABEL": "6,935 +/-312 ", "VALUE": 6935}, "geometry": { "type": "Polygon", "coordinates": [ [ [ -95.056412, 38.738587 ], [ -95.056412, 38.737225 ], …, [ -95.056412, 38.738587 ] ] ] } }, … (repeat for 534 remaining Census Tracts) View of JavaScript being written by the PHP code from the previous two slides.

http://ipsr.ku.edu/ksdata/apps/KCMOtracts.php Test

Other types of coordinates The sample shows PHP writing Javascript for coordinates stored as single values (aka long, skinny table) Other types of coordinates

Other types of coordinates The sample shows PHP reading a GeoJSON feed from USGS. The data are already formatted so PHP just reads the data and writes it out. Other types of coordinates

Xan Wedel Senior Research Data Engineer Institute for Policy & Social Research 607 Blake Hall xan@ku.edu Other links: Google Maps API http://www.ipsr.ku.edu/ksdata/ksah/portal.shtml http://www.ipsr.ku.edu/BIDC/region.php http://ipsr.ku.edu/ksdata/apps/bike/map.php Leaflet http://ipsr.ku.edu/ksdata/apps/KSCountyMap.php http://ipsr.ku.edu/ksdata/apps/earthquakes.php Questions?