Saturday, June 30, 2012

Using a scanned map for digitizing in Potlatch2 for OpenStreetMap

I had a map that I wanted to use as an online base layer for adding features to OpenStreetMap using a Windows machine. I was successful in doing so using all open source tools and lots of trial and error.

Here's how I did it.

  1. I scanned my map using my flatbed scanner. I have an HP 6500A Plus. I scanned it in at 300 dpi and saved it as a TIFF file.
  2. Now I needed to GeoReference the TIFF file. For this I used QGIS Desktop. You can download it for free. The best way to install it is with the OSGeo4W Installer which can be found here:  http://trac.osgeo.org/osgeo4w/. The projection of my scanned map was UTM 10 NAD83 aka EPSG:26910 so I set the Coordinate Reference System (CRS) to  26910  under Settings => Project Properties and checked the "Enable 'on the fly' CRS transformation". For reference sakes I loaded some layers from a WMS for the area my map was in. The WMS I used was from DataBC Geographic Services. I used the 'Quick Base' WMS. The WMS URL for this can be found at:  http://www.data.gov.bc.ca/dbc/geo/wms/index.page. In QGIS I added all the 'Base Layers' and 'Transportation'  layers that were available from the WMS.  Next, I enabled the Georeferencer GDAL plugin and fired it up. It runs in a separate window. I loaded my TIFF file in the Georeferencer GDAL plugin window. Now I setup the tool under Settings => Transformation Settings. I set my Output raster and set my Target SRS to the known projection of my map. In my case it was 26910. I also checked Load in QGIS when done. Next I used the 'Add Point' tool to pick points on my map that I knew were in the WMS I loaded. My favourite points are road intersections. Once I added a point to the map in the Georeferencer I then clicked the 'From map canvas' button which switches screens back to the QGIS main window. I then found the same point in the WMS and clicked which autopopulated the X and Y values in the Georeference window. I did this for about 4 points and then hit the Green play button which 'start[s] Georeferencing'.
  3. I now had a georeferenced TIFF but, in its original projection. In order for it to be used efficiently as a base layer I wanted to eliminate on the fly transformation so I reprojected the TIFF into the the projection my final product would be in, Google Spherical Mercator aka EPSG:900913. I used the GDAL Tools plugin and under Raster => Projections => Warp (Reproject). Again I set the Output filename and the Target SRS to 900913.
  4. After reprojecting the TIFF I needed a WMS that served it via HTTP. This is easily accomplished using QGIS Server which I installed using the same OSGeo4W: http://trac.osgeo.org/osgeo4w/. I followed the tutorial here:  http://hub.qgis.org/projects/quantum-gis/wiki/QGIS_Server_Tutorial#Windows. One thing missing from this tutorial was picking the Fast CGI package when choosing packages to install and then fcgi works fine and you don't need to change the c:/osgeo4w/httpd.d/httpd_qgis.conf. After following the tutorial I had a WMS up and running.
  5. I tested my WMS using OpenLayers. I swapped out an example WMS for my own using this example: view-source:http://dev.openlayers.org/releases/OpenLayers-2.11/examples/lite.html. I just swapped out the url for the one from the tutorial. You can check a WMS with QGIS as well. If you want to see the call that's being made you can check the C:\OSGeo4W\apache\logs\access.log.
  6. Now that I had a WMS that I knew worked I needed to convert in into a Tile Mapping Service so it could be consumed by OpenStreetMap Potlatch2. I would accomplish this by adding TileCache to the mix. I downloaded the package from here:  http://tilecache.org/. I unzipped it into C:\OSGeo4W\apps\tilecache. I then set up the folder the same way qgis was set up; with C:\OSGeo4W\httpd.d\httpd_tilecache.conf with the following contents:

    Alias /tilecache/ C:\OSGeo4W/apps/tilecache/

    <Directory "C:\OSGeo4W/apps/tilecache/">
      SetHandler cgi-script
      Options ExecCGI
      Order allow,deny
      Allow from all

    </Directory>

    I also installed a separate instance of Python27 to run TileCache. Thus I needed to update my C:\OSGeo4W\apps\tilecache\tilecache.cgi to reflect this, putting the following line in the first line:#!C:/Python24/python.exe -u
  7. With a Tile Mapping Service in place I now needed to set up a TMS layer that consumed my WMS. This is where the magic happens. In the C:\OSGeo4W\apps\tilecache\tilecache.cfg I added the following entry:

    [omg_bg]type=WMS
    url=http://localhost:8080/qgis/qgis_mapserv.fcgi.exe?map=C:/gis/project/omg_bg.qgs
    extension=png
    layers=omg_bg
    bbox=-20037508.34,-20037508.34,20037508.34,20037508.34
    maxResolution=156543.0339
    srs=EPSG:900913

    tms_type=google
  8. I was now able to log into OpenStreetMap.org and add a background under Background => Edit => Add. I gave it the name ogm_bg and the URL http://localhost:8080/tilecache/tilecache.cgi/1.0.0/omg_bg/$z/$x/$y.png
Voila! I was now able to digitize the features from my scanned map and add them to OpenStreetMap.

Monday, June 11, 2012

Adapting a Travel Easy Wind-up Charger for USB Devices

Today I finally got around to a project that has been on the to-do list for a long time. I made a little video:
Overall I am quite satisfied with how it turned out it and it will be a useful tool when traveling or camping etc.

Wednesday, May 23, 2012

Facebook Font

Ever need the facebook font for desktop publishing? Instead of paying $300 for the official one try this one free one. It comes in OpenType format. I needed to update my OpenOffice to version 3.4 in order to use in in  OpenOffice Draw.

http://www.maxfonts.com/fonts/f/facebook-letter-faces.font

Monday, August 30, 2010

Linux Tip of the Day - sudo saving within VIM




I browse a lot of files across different servers with different configurations. It is very helpful for me to be able to save changes I've made to a file I've opened with limited read only privileges. The last thing I want to do is save to a temprorary file and overwrite the target file with the temp file.

:w !sudo tee %

Thanks to the Ubuntu Forums and user singlow

Sunday, June 13, 2010

Linux Tip of the Day - Hard Drive Identification





Here is a command I found very useful today. I needed to identify the hard drive with out opening the enclosure.

sudo lshw -businfo -C disk

Thanks to the Ubuntu Forums and user Temüjin