Showing posts with label mapping. Show all posts
Showing posts with label mapping. Show all posts

Tuesday, October 18, 2011

Google Maps - Image Overlay Tutorial


I have recently been working with my father on expanding our family tree and adding information to individuals. One of the items he had was some annotated maps produced by his uncle showing the various pieces of property owned by the family in a small country town in NSW.

When I first saw these maps I immediately thought that it would be a good idea to have them overlayed onto a Google map to allow other members of the family to view them in context.

At the time, I had no idea of how to do this, but had seen the results on some other history websites. It was only when I watched the 'Map Your Business - Inside and Out' presentation from Google IO 2011 that I obtained the necessary knowledge and tools to produce these maps.

Although this presentation told me what tools were required to build the maps it was lacking in instructions on how to use the tools. I am hoping this blog post will provide a bit more guidance and some helpful hints on getting a result from these tools.

 The general workflow for producing a map overlay from a hand-drawn or annotated map is:
  • Obtain Source Maps
  • Geo Reference the Source Maps
  • Produce Overlay Tiles
  • Build Page to display Overlap Map on Google Maps.

Obtain Source Maps

My source maps were hand-annotated maps that had been scanned as TIFF files. I resized these images and uploaded them to my hosting account. This was necessary to use the Overlay-Tiler tool in the next section. For the purposes of this tutorial I will use a historic map from Gosford, NSW.

Geo-reference the Source Maps

The first step to displaying these maps as overlays on Google Maps is to determine the latititude/longitude for the corners of the map. To make this easier, the Maps team from Google has provided a tool called Overlay-Tiler. This is an interactive map where you can drag the corners of a overlay image around until it lines up with the underlying Google Map. The output of this tool is a GDAL_TRANSLATE command line script which you can run against the image to produce a geo-referenced TIFF.

Step 1.
Open the Overlay-Tiler web application in Chrome. The initial screen below allows you to specify the image location (published on web-site) and the initial location for the Google Map.

Step 1 - Provide Overlay Image and Initial Location
Step 2.
Pressing the Upload button will display the main screen for the Overlay-Tiler application. Your initial map will be displayed along with a semi-transparent overlay of your map image. This image is shown with control-points on three corners to allow you to drag and rotate the image to match the underlying Google Map.

Step 2 - Overlay Image displayed on Google Map
Step 3.
By dragging the handles of overlay image and changing the zoom levels of the underlying Google Map it should be possible to line up major features of both maps. This can be quite time-consuming depending on the accuracy of the overlay map.

Step 3. Overlay Map re-sized and rotated to line-up with Google Maps
Step 4.
Once the overlay map has been aligned to the Google Map the GDAL_TRANSLATE command line will be displayed in the box in the bottom right-hand corner of the screen. Copy this command line to a safe place. I store these in the same directory as my maps.


The GDAL_TRANSLATE command line script will produce a new geo-referenced image. To run this command you will need to have the GDAL tools installed on your machine. Various versions of this toolset exist for most operating systems. I am using Windows so I downloaded and installed the desktop version of OSGeo4W (Open Source GEO for Windows). This will install an environment on your machine to run GDAL tools.

Step 5.
To produce the geo-referenced image, start the OSGeo4W command prompt and copy the command line script from Step 4 above. The '\' characters will need to be removed from the command script.

Step 5 - Run the GDAL_TRANSLATE script to produce the geo-referenced image.
The output from this section is a PNG image that includes embedded geo information.

Produce Map Tiles for your map

The final output from this process is a collection of tiles that can be referenced by the Google Maps API to overlay over the standard Google Maps tiles. A common way to produce these tiles is to use the GDAL2TILES Python script. This will produce a series of tiles that are named appropriately to publish and use in Google Maps API. As I do not currently have a Python environment installed I decided to use the MapTiler application which is a Graphical Interface to the GDAL2TILES script.

Step 1.
Run the MapTiler desktop application. Select the type of Tileset to create. We are creating a Google Map overlay so will select the first option.


Step 2.
Add a new Source Data file (Overlay Image created in the previous section). If the geo-referencing has occurred correctly, the Georeference column will show 'GCPs'.

Step 2 - Add a Source Data File

Step 3.
Select a Spatial Reference System - for Google Maps overlays the most appropriate is WGS84.

Step 3 - Confirm the Spatial Reference System

Step 4.
The next step in the MapTiler application is to select the Google Map zoom levels your overlay will be shown on. The application will default to the most appropriate zoom levels however you can adjust the levels   to suit. The higher zoom levels will require a higher resolution image to avoid 'jaggies'.

You can also select the file format at this point.

Step 4 - Tile Pyramid
Step 5
Enter the location where you would like the files to created.

Step 5 - File Location
Step 6
Select the Web Viewers you would like MapTiler to generate. These are a HTML page that contains the appropriate code to display the overlay on either a Google Map or OpenLayers Map. These can be used as a base for your own pages.

Step 6 - Selection of Web Viewer

Step 7
The next step in the process is to configure the Google Maps API Key. If you are testing only on your local machine you do not require a Maps API Key. If you want to publish on the web you will need to obtain a Google Maps API Key. This key is restricted to a single domain.

Step 7 - Enter Google Maps API Key

Step 8
The final step of the process is to Render the tiles. This will create a series of image tiles at each zoom level and the Map Viewer HTML.

Step 8 - Render the Tiles
Publish your Map

The output from the MapTiler application is the collection of tiles (at various zoom levels) and one or two HTML Pages (depending on map options selected).
This directory structure can be copied directly to your web host, where it can be viewed as a full page map. Due to the simplicity of the HTML it is very strait-forward to modify the layout and contents of the page.

Conclusion

Using this technique to show overlay maps on Google Maps is a great way to show historic mapping in context of the current day. It also allows the overlay of other information (floor plans, evacuation maps)

The following examples show a Google Map and OpenLayers Map created as part of this tutorial.

Google Map Example
OpenLayers Example

I hope you find this tutorial useful. Feedback is always welcome.

Enjoy.

Sunday, June 12, 2011

Nearmap Aerial Mapping

Nearmap is a Photomap and location-based media company that provides high resolution aerial photography of Australias major population centres. These photographs are updated on a regular basis and the historical imagery is available.

A majority of the imagery is at 7.5cm resolution. This means that each pixel in the image represents 7.5cm of the earth surface. This means these images show more detail than many other mapping services.

Sample Image from Nearmap
One of the more unique features of the Nearmap service is the fact that the imagery is updated on a regular basis. Many metropolitan areas are updated on a monthy basis and the other major population centres are updated quarterly. Once captured and processed these new images are available very quickly. As the older imagery is also available it is possible to view and compare images from one month to the next.

Nearmap also provide a Javascript API  to allow developers to embed maps into their own webpages. I have a simple example of this API here.

Overall, I find this service extremely useful. It is well worth signing up to.

Sunday, February 20, 2011

GPS Visualiser

One of the online tools I use regularly while working with GPX files and mapping is the GPS Visualizer website. The GPS Visualizer website is a collection of tools that work with GPX files to produce maps and profiles of GPS tracks.

The main functions I use on the website are:

1. Draw a Map

The Draw a Map page allows you to select a GPX file and display it overlayed on a variety of different map types including Google Streetmap, Google Satellite and Google Terrain. Once created the image can be captured as an image file.

2. Draw a Profile

The Draw a Profile page allows you to select a GPX file and display a elevation profile for this GPX file. The profile can be colorcoded to show elevation, speed, heart rate and other data points. Where a GPX file does not include elevation data the form gives the ability to add elevation data from a DEM dataset.

3. Lookup Elevations

The Lookup Elevation page allows you to recreate the elevation data for a GPX track using a DEM dataset. This is useful if the existing GPX file does not have elevation data or the data is incomplete. Rather than directly rendering a profile (as in point 2) the page gives you the option to save a new GPX file.

As well as these easy to use functions there are a multitude of ways to make use of the GPS Visualizer service. If you are using GPX files on a regular basis this service is a very handy addition to your tools.

Sunday, November 7, 2010

Endomondo Android Application

In previous posts here and here I documented how I use GPS enabled mobile phones to record my mountain bike rides. I have recently been evaluating Endomondo. Endomondo is an Android application which records your rides, runs, swims, and any other exercise.

The Endomondo service consists of a mobile application (Android, iPhone, Blackberry and Symbion) that makes use of the GPS functionality of the phone to track your workouts. This is paired with a web-based service that will store a history of your workouts along with allowing you to see your workouts overlayed on a Google Map.

Some of the key features of the Endomondo service which make it interesting to use are:

  1. Audio Coach: the Audio Coach uses the text to speech functionality on your Android phone to announce your current progress at each kilometer. It means you do not need to constantly check your progress on your phone.
  2. Live Tracking: if you have a mobile connection active on your phone, the application will constantly update the web service with your progress. This will allow interested people to follow your progress via your profile page. An interesting addition to this is the ability for someone to send a message to your device which will then be read out by your device.
  3. Routes: if you have a favourite ride/run this can be published as a route on the web service which means that anybody can ride/run this course and compare their times to yours. 

Overall, the application and web service work together very well. The workout history is reasonably comprehensive and the statistics collected can be used to see how many kilometers are ridden in a year.

Sunday, October 17, 2010

Android App Inventor - Location

I recently got a new HTC Desire phone. One of the main reasons for purchasing an Android phone was the ability to write and deploy my own applications to it. Just prior to getting the phone I had seen a post from Google regarding the new App Inventor for Android tool. The tool is in beta at this time so I signed up hoping that I would get an invite and I would be try out this new tool. Last week I got the invite and started playing with App Inventor.

As I am interested in GPS and location aware applications I decided to develop a small application that would show the current location, current address and the option to launch the Google Maps application on the phone.

 The Android App Inventor is a web application that has a visual GUI builder to create the GUI and uses 'blocks' in place of code to provide the logic in the application.

The screenshot below shows the GUI builder with the 4 controls used to display the current latitude and longitude and the street address if known from the Google geocoding service. It also has a button to initiate the display of a Google map centered on the current co-ordinates.

To obtain the GPS co-ordinates you will need to add a LocationSensor to the non-visible components. This sensor allows you to access the built-in GPS on Android devices. It includes methods to enable/disable the internal location sensor, read the sensors and get the current address.

The next screenshot shows the logic required to display the latitude, longitude and address on the screen whenever the phone is moved.

It also shows the logic for the ActivityStarter to create and display a Google Map. Information on how to setup the properties for the Google Maps ActivityStarter is in the MapTour tutorial.



Once the properties are configured you will need to generate the URI to pass to the Map Activity. I have shown this above as it took a couple of attempts to get this right. As it is not currently possible to simulate the location sensor in App Inventor the app will need to be compiled and deployed to either the Android SDK emulator or a real phone.I did this a number of times prior to getting it to work.

I hope this information helps if you are trying to use LocationSensor and Google Maps activities on App Inventor.

I have added a link to the source code here.

My other App Inventor tutorials are here:
App Inventor - Lists
App Inventor - SMS Services

Thursday, September 16, 2010

My Tracks for Android

In the past I have done some mapping of the various mountain bike tracks around the Central Coast. In a previous blog post I documented how I used my Nokia phone and a bluetooth GPS dongle to do mapping.

Now I have a HTC Desire this process has now become much easier to do and I only have to carry one device while I ride.

The key to using the HTC Desire for mapping is the My Tracks for Android application. This application was built by some Google engineers in their 20% time and the results have been open-sourced for the community to benefit.

The My Tracks application uses the GPS in your Android device to record your location as you walk, run or ride. The resulting information can then be exported to either Google Documents to record the details or Google Maps to visualise the route.

Here is an example of a map produced by the My Tracks application.


View 2GO Track in a larger map

An example of the data collected and archived in Google Docs is here
.
My experience so far with Google My Tracks has been very positive and I will continue to use it for both my riding and running.

Thursday, April 8, 2010

Latitude/Longitude Converter Class Library

A few weeks ago I found an old photograph taken while we were doing a 4wd tour on the Mid North Coast of NSW. I wanted to scan and post this photo to the blog along with a Google Maps location.

The issue with this was I only had a rough idea where the photo was taken. During this 4wd tour we followed the directions in a printed book. This was 10 years ago and we did not have the use of a GPS to record our track. All I had to go on was the directions in the book. These directions made little sense trying to follow them on Google Maps as in many cases the tracks we followed are not named or marked in Google Maps.

However, the book did give GPS co-ordinates for key points on the tracks (major intersections or landmarks). I decided these could be used to provide a rough path followed and allow me to get my bearings while trying to follow the directions on Google Maps.

Once I tried to plot each of these points in Google Earth I realised it would be a slow process to import each of these points. An easier way would be to create a KML file of the points and load that into Google Earth. I had already written some code to produce a KML file of points from a CSV file so it was just a matter of loading the GPS co-ordinates into the CSV file and running the program.Unfortunately, KML files need GPS co-ordinates in Decimal Degrees and all my co-ordinates were in Degrees, Minutes and Seconds.

At this point I could have used any number of web based conversion pages to convert each co-ordinate manually. Instead, I decided to write a JAVA class library to convert co-ordinates between Degrees, Minutes and Seconds and Decimal Degrees.

The code was reasonably simple but as I had not been able to find an equivalent class on the net I decided that I would try to make it as versatile as possible with the aim to releasing it onto the web for anybody to use. It would also be a good learning exercise for me as I have created a Java class library previously.

After a weeks worth of coding I have now got the library to the point that I feel comfortable releasing a alpha version of the library to the net. There is a simple tutorial available and I am currently developing the Javadocs to go with the library.

Eventually, I will also post the source under an open source license to allow others to build or improve the library.

Saturday, October 24, 2009

Using JAK and Google Geocoder

In a previous post I mentioned that I would be doing some experimenting with the JAK - Java API for KML. I have now created a simple program that creates a KML file using co-ordinates obtained from calling the Google Geocoder.

If you wish to review the whole program I have made it available here (4mb).

The main parts of the code are as follows:

GeoCoder class
  • converts a street address into a longitude/latitude point.
  • call getLocation method with a string representing the address.
  • class uses Google Geocoder.

Refer to the Geocoder.java class file in the download for more information on how this works.



Main Class
  • assigns an address from the first command line argument
address = args[0];
  • calls the GeoCoder.getLocation method with Address String
location = Geocoder.getLocation(address).toString(); 
  • creates a KML file using the location value returned by the GeoCoder class
final Kml kml = new Kml();
kml.createAndSetPlacemark()
   .withName(address)
   .withOpen(Boolean.TRUE)
   .createAndSetPoint()
   .addToCoordinates(location);

try {
kml.marshal(new File("HelloKml.kml"));
} catch (FileNotFoundException ex) {
     Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

In the future I will expand on this application to provide more information in the KML.

Friday, October 9, 2009

JAK - Java API for KML

In a previous blog post I showed how it was possible to take information recorded by a GPS device and mobile phone and plot the resulting track using Google Maps.

Recently, I found a link to a JAVA API that allows you to interact with the KML files produced by the process using a JAVA application.

The project aims to provide an

"automatically generated full reference implementation of the KML object model defined by OGC’s KML standard and Google’s GX extensions. It is an object orientated API that enables the convenient and easy use of KML in existing Java environments."
Over the next couple of weeks I am going to do some experimentation using this API and try and develop some simple applications to take GPS tracks from Nokia Sports Tracker and my GPS and create interesting KML files.

Stay tuned...



Sunday, June 21, 2009

GPS Mapping

Over the last 10 years I have ridden many of the trails in the Central Coast area, often more than once. Recently, I have started to map these trails using a GPS with the aim to document them so other riders may enjoy them.

To do the mapping I use the following hardware and software.

Hardware

Software


An example of the embedded map produced by this technique is below. It shows the various information available from the file produced from Nokia Sports Tracker.


View Larger Map

Capturing the Data Points (GPS Track)

To capture the data used for the KML file I use my Nokia mobile phone connected to a bluetooth GPS Module. Nokia have released an application called Nokia Sports Tracker which allows you to record a GPS track. For further information on the use of Nokia Sports Tracker visit the Nokia website.

The Nokia Sports Tracker application has the option to output the file of data points to a variety of formats (GPS, CSV, or KML). We are most interested in KML here because it allows us to import the track into Google Earth or Google Maps.

Viewing the Map

Now that we have a KML file we can open this file directly into Google Earth to check that it looks correct. If you have Google Earth installed, double-clicking the KML file in Windows will open the path and display.

To use the path in Google Maps is a little more involved as you need to host the KML file somewhere on the web. I use a folder on my hosting provider.

Once you have the KML file hosted on the web you can now use it within Google Maps. To use within Google Maps copy/paste the URL into the Google Maps Search Bar and press 'Search' button.


Google Maps will now display the path on the map with some additional information about the path from the KML file.


Embedding the Map

Once you have the map displayed you can now Print, Send, or Link to this map. To embed this map into a blog or another web page use the 'Link' menu and paste the HTML in the second box into your website code.

You can use the 'Customise and preview embedded map' to change the settings of the embedded map.

For more information refer to the examples on the Google Maps site.