20
DSA Week 15 1 DSA Week 15 Mashups, Google Earth and Geo-coding

DSA Week 151 Mashups, Google Earth and Geo-coding

  • View
    217

  • Download
    2

Embed Size (px)

Citation preview

Page 1: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 1

DSA Week 15

Mashups, Google Earth

and Geo-coding

Page 2: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 2

Agenda

• XPath continued

• Mashups

• Google Earth

• Keyhole Markup Language

• Generating kml

Page 3: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 3

Mashups (1)

• Mashups are about information reuse. Just as code reuse was the holy grail of object-oriented development, enabled through class (code) libraries, so mashups are about data reuse and recombination.

• An alternative term is ‘bricolage’, a term used in the IS context by Claudio Ciborra.

• ProgrammeableWeb documents over 1520 (700 at the beginning of May 2006), nearly half of which use location data associated with photographs (Flickr), house sales (Craig’s List) and news items (RSS) linked to maps( Google Map.)

Page 4: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 4

Mashups (2)

• Combining information from multiple sources – Application gets data from a source

• Page-scraping (parsing HTML)• Application Programmer Interface (API)

– SOAP / REST /JavaScript functions

• RSS (Real Simple Syndication)

– Standard identifiers to link data (e.g. Currency codes)– Combine data on server or client

• E.g. Using Google Map Javascript API

• E.g.– Subletr at Waterloo University on Canada

Page 5: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 5

Google Earth

• Blog entry• Google Earth is a client-side mapping

application (needs a download) so not used in this list of Mashups– Image based on satellite and aerial imagery (200

terabytes)– Uses can add annotations such as Placemarks, with a

position and description– User defined overlays can be saved and distributed

as XML

• Google Maps now can use the same overlays .

Page 6: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 6

Google Earth Demo

• StudentsOnline

• Google Earth operations– Creating Folders– Creating Placemarks– Editing Location and Description– Editing Icons– Saving as kml

• Partner Organisations map

Page 7: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 7

Creating a static GE overlay

• Create a new folder• Go to a location• Create a new Placemark and add to folder• Edit the Placemark• Save the Folder as kml (kmz is zipped kml)• View the saved file in a text editor.• Edit the description of a Placemark in this file• Load the modified kml file • Place the kml file in your public-html directory• Reference this file from a browser (Firefox)• This should then start up GE and load the overlay

Page 8: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 8

Example kml file

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.1"><Folder>

<name>UWE</name><open>1</open>

….<Placemark>

<name>Bower Ashton</name><description><![CDATA[The home of the Faculty of

<a href="http://www.uwe.ac.uk/amd/">Art, Media and Design</a>]]></description>

<Point><coordinates>-2.632474205298138,51.44408935082485,0</

coordinates></Point>

</Placemark>

….

This is very minimal but it is enoughUses default iconUses default viewpoint

Page 9: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 9

CDATA

• Problem – XML has a strict definition of what is allowable, but what if you have to include content which is not allowed e.g. Un-nested tags as pure data.

• Answer 1 – Replace all characters by their character entities or

decimal character i.e. < becomes &lt;

• Answer 2 – Enclose the messy data in the special tag

• <![CDATA[ ……. ]]>

Page 10: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 10

Understanding kml

• Experimental:– Use a text editor (Notepad, PFE32) to load

the text file, change a description, save and reload (after deleting the original) ?

• Online documentation– the Google Earth specification

• Draw a tree diagram to explain the general structure

Page 11: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 11

Advanced Google Earth

• Icons– Style can be designed

• For each Placemark• For a set of placemarks by creating a style with an

id• Small icons can be selected from the big pallette

png’s – each is 32* 32 pixels, arranged in 8 rows of 8, numbered 0- 7 from the bottom-left.

• Specific icons can be selected with the appropriate x, y, h, w parameters

Page 12: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 12

Understanding Latitude and Longitude

Lines of equal latitude

Lines of equal longitude

(0, 0) of the West coast of Africa

0 longitude is the Greenwich Meridian

0 latitude is the Equator+,++, -

Bristol

51 ° 27’ N2 ° 36’ W

1 minute of latitude = 1 Nautical Mile = 1.150779 miles

60 seconds in 1 minute60 minutes in 1 degree360 degrees in a full circle

1 minute of longitude goes to zero at the poles

50

0-1-2

As decimal

51.45-2.6

Page 13: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 13

Geocoding• To determine the latitude and longitude of an address or

postcode• One at a time

– Use Google Earth to find a place by name or full postcode and note the latitude and longitude

– Hint – select the option to display latitude and longitude in decimal degrees not degrees, minutes and seconds

• In Bulk• UK Postcodes

– commercially available in bulk– Use one of the free XML-based services supplied Mikel Maron

who resides in the Dominican Republic. • http://brainoff.com/geocoder/rest?post=BS7

Page 14: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 14

Examples of location data

<Point> <coordinates> -2.6, 51.45 ,0</coordinates></Point>

<geo:lat>51.45</geo:lat><geo:long>-2.6</geo:long>

<georss:point>51.45 -2.6</georss:point>

Page 15: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 15

Inconsistant Geocoding data• Just as we saw with the weather data, there are lots of ways of

marking up position data.• Nearly all in Latitude and Longitude expressed as decimal degrees

but also in OS northing and easting• Compare the different markups in

– Weather Channel– BBC– Yahoo– kml– GeoRSS

• Kml also includes altitude• Different mapping systems will return different positions – one cause

are different datums because the earth is not round. Google Earth uses WSG84

• This creates difficulties in system integration

Page 16: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 16

Dynamic kml

• kml is just another XML file so we can get PHP to output kml just as we did html

• A few differences– You have to set the mime-type to kml– You have to create a valid kml file

• The full definition of the syntax of kml is very large, but most developers work from examples (XML schema has only recently been defined)

Page 17: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 17

A trivial kml generator

• Basic demonstration– Read a BBC weather feed from a file– Generate a kml file with one Placemark

• Key features– header("Content-type: application/vnd.google-

earth.kml+xml;");– Minimal elements

• On GoogleEarth– http://www.cems.uwe.ac.uk/~cjwallac/apps/phpxml/

showPlace.php?name=Bristol• On GoogleMaps

– http://maps.google.com/maps?q=http://www.cems.uwe.ac.uk/~cjwallac/apps/phpxml/showPlace.php?name=Bristol

Page 18: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 18

PHP script<?php$name = $_REQUEST["name"]$places = simplexml_load_file("places.xml");$place = $places->xpath("//Place[name='$name']");$place= $place[0];header("Content-type: application/vnd.google-earth.kml+xml; charset=UTF-8");?><Document> <name>A sample overlay</name> <Placemark> <name><?php print $name; ?></name> <description> A very interesting place </description> <Point> <coordinates><?php print "$place->longitude,$place->latitude,0"; ?> </coordinates> </Point> </Placemark></Document>

Page 19: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 19

Typical output

<Document> <name>A sample overlay</name> <Placemark> <name>Bristol</name> <description> A very interesting place </description> <Point> <coordinates>-2.6,51.45,0</coordinates>

</Point> </Placemark></Document>

Page 20: DSA Week 151 Mashups, Google Earth and Geo-coding

DSA Week 15 20

Workshop

• Use Google Earth to create a kml file• Inspect it with a text editor• Get the PHP code to convert from a Place name

to a kml file working• Read the current weather directly from the BBC• Use Mikal’s geocoding service in a script which

accepts a UK place name and generates a kml file

• [Use a public server to host the scripts and use GoogleMap to display the locations]