Friday, November 08, 2013

Android speculation

This is just some idle speculation on my part, and should not be considered as having any authority whatsoever.

Android to support alternative to Java

For some time, I have thought it must sit a little awkward with Google having Java so firmly entrenched in Android. Of course Google bought Android, so the original decision to use Java was not theirs, but have they considered moving away from it?

That would be a huge task. A number of things would need to be put in place before that could be considered. The development tools would have to be able to use the new language, and the runtime engine will have to be flexible enough to use the ne language as well as support the existing Java written apps.

Google have recently previewed a new IDE called Android Studio. Would this be better suited to supporting different languages?

With the recent introduction of Android 4.4, there is now the option to use an alternative runtime to Dalvik. ART. It would make sense to me that this would be an ideal opportunity to include the possibility of having an alternative programming language to Java.

As I said before, this is just speculation, but I really do wonder if by the time Android 5.0 comes out, will we be able to use something other than Java to write applications for android phones SDK? I know that is possible now with the NDK but that does not count!

Saturday, October 19, 2013

PDF editing and PS hacking

I have a PDF book that is a good reference. It would be great to be able to have it available on my tablet computer, but the PDF reader apps that have been tried are rubbish at navigating. Being a reference book, it is often required to skip to a specific chapter. This is slow when the PDF does not contain a sensible linked index. The only index it does have is in alphabetical order!

My initial thought was to use something like pdftk to split the book into separate files for each chapter. Having these in a folder, and using a file manager to select the required chapter as needed. This would work, but seems untidy. A better solution was required.

What I really wanted was to change the original PDF as little as possible. So I decided to add a single page to the start of the file with a linked list of the chapters. To do this required a little PostScript.

The Index

Create a file called, say, And in the file add some PostScript commands to create the index. First we can set a title. The word "Index" is placed near the top of a 4.5 x 6.5 inch page.

/Times-BoldItalic findfont 20 scalefont setfont
100 430 moveto (Index) show

Next the text for the chapters needs to be added.

/Helvetica findfont 12 scalefont setfont

20 400 moveto (Chapter 1) show
20 380 moveto (Chapter 2) show

The first line sets the font size, and then the next lines position and set the text. This is repeated as much as required.

Now we need to make the text clickable. This was done using pdfmarks.

[/Page 4 /View [/XYZ null null null] /Rect [8 393 52 413] /Subtype /Link /ANN pdfmark
[/Page 5 /View [/XYZ null null null] /Rect [8 373 52 393] /Subtype /Link /ANN pdfmark

The coordinates for each rectangle needs to align with the relevant text above, and the page number adjusted to point to the correct page in the PDF document for that chapter. This part was a bit long winded, and I am sure could have been made better with some more fancy PostScript tricks, but at least this works.


The Index was intended to go at the front of the PDF file so that it was the first page seen when the document is opened. If this was placed there directly, I would have to adjust the page numbers above by one to account for the extra page taken by the index itself. This would work, but caused an issue with the existing index in the PDF. This would also then be out by one page. So it was decided to put the index as the last page in the PDF. This way it would still be easy to find without disturbing the rest of the document.

The code to combine my new index with the existing PDF looks like this:

   -sDEVICE=pdfwrite \
   -dAutoRotatePages=/None \
   -sOutputFile=temp.pdf \
   MyBook.pdf -f

This adds the Index to the back of the PDF MyBook, and puts the result into temp.pdf.

The final stage was discovered by accident. I found that if I used pdftk to manipulate the book, it would update the internal links to keep them pointing to the correct page. So I could use pdftk to move the index to the front of my PDF as I first intended, and also, the existing index would also still point to the correct pages and not be shifted by one due to my added page.

The command I used with pdftk is as follows:

pdftk A=temp.pdf cat A228 A1-227 \
    output MyBook_Index.pdf

I now have a quick index card at the front of my PDF book that can be used to navigate to the required chapter.

Saturday, May 11, 2013

Tracing buildings from OS OpenData Street View for Openstreetmap

First, it needs to be said. Automatic tracing and dumping data into Openstreetmap is not a good idea. This page is something I have been playing with as an aid to manual edits.

This is a simple summary of the steps I used. If you need more information, then you probably should not be doing this.

Source Data
Grab some data for the area of interest from Ordnance Survey.
The Gimp
Find the tile required and open in The Gimp. The following steps should isolate the buildings.
  • Select by colour, threshold set to 26, pick the centre of a building, avoiding the antialiased edges.
  • Sharpen selection.
  • Fill whole selection with black
  • Invert Selection
  • Fill whole selection with white.
  • Save image in bmp format.
Make sure that you have the latest potrace that does geojson. With the required tif image from the OS data, run to following command:
potrace -b geojson -L XXXXXX -B YYYYYY -O 1 -a 0 tile.bmp
Replace XXXXXX and YYYYYY with the appropriate offsets for the tile being worked on. The required data is in the package downloaded from OS.
Quantum GIS
  • Create a new project with CRS OSGB 1936 / British National Grid. EPSG:27700.
  • Load a new vector layer, select the json file from potrace and make sure the CRS is as above. Make sure that the scale is making sense. It would be possible to load another layer of known good data as a check. Be sure to allow on the fly CRS transforms if the data you check against is not OSGB 1936.
  • Save the layer as a shapefile. Use the same CRS as the layer for the shapefile.
The shapefile can now be loaded into JOSM. The polygons should line up well with the OS OpenData StreetView background images. However, there will still be a lot of manual cleaning up required. Extra nodes need to be deleted and squaring up done.

I am not sure if this actually makes much improvement over simply clicking over the background imagery by hand. Maybe someone else can improve this process a bit more. This is really written as a reminder to myself incase I come back to this later.

All this is done with free software. The initial idea came from the openstreetmap wiki. There is also a python program that can do this called Mapseg, but it is not very fast on my little computer.

Thursday, February 21, 2013

Ubuntu Touch pre-Alpha on Nexus 10

First Boot

Curiosity got the better of me. Having seen a few YouTube demos of the new Ubuntu touch interface on the phone, I was excited to learn that the developer preview was going to be released for the Nexus 10. Not that I am a developer though.

First thing I needed to do was decide that there was nothing on my tablet that I needed. Once I was happy about that, I went ahead and followed the instructions. The only problem I had was after unlocking the boot-loader  the tablet would not boot up. It was stuck at the boot animation. As I needed to be in Android to complete the next step, I had to reinstall Android first.

After that little hiccup, it all went fine. Then I was presented with the image above.

There is still allot that does not work. Most of what does work, works well. There are many rough edges, and a few little quirks that no doubt will be adjusted over the next few months. The one thing that did strike me was the lack of a back button. That was probably the most unintuitive aspect to the interface.

It seemed that allot of what was working were internet apps. Gmail, Maps, Twitter, Facebook etc. And they all thought they were running on an iPad.

So far it seems like a good effort. Not sure I fully grasp the point though. It seems to be trying to do what Android does, but differently. What I was hoping for was something more like the Ubuntu Desktop. For that I would need at least a terminal, ssh, vim, LaTeX, apt-get etc. If proper user access control is implemented, that could be a real advantage.

In the meantime, I will be running Android on my tablet, as I only have the one. It would be nice to have a spare that I could keep on Ubuntu so that the development can be tracked. In a few months time, it may be worth trying again.

It is going to be interesting to see where this goes.

Monday, October 29, 2012

Openstreetmap Zoom

I have played around with this before. Having recently set up Mapnik again to render Openstreetmap data. Currently it is using the standard Openstreetmap osm.xml file so should look like the mad used on the main website.

This animation is created by rendering each frame with Mapnik. The script is based on a hack of the standard script that comes with Mapnik. It simply loops, and for each loop a new bounds is calculated to provide the zoom effect.

A seperate script is used that adds the watermarks in the bottom corners of each frame. This was done with the help of ImageMagick. Finally, avconv was used to convert the frames into an mp4 file.

The next step is to make an animation based on a GPX file. That will take a GPX file as input and provide a zooming animation that shows the start, and an overview of the whole GPX track.

Wednesday, October 10, 2012

Garmin Vista HCx

Some time ago, I purchased a Garmin etrex Vista HCx. Certainly not the most sophisticated GPS system available, but still good fun. It works well in the car, the pocket and on the bike. The only real downside was that the maps that come with it are fairly limited, and it would work out expensive to purchase all the maps I may want to use with it.

That said, it still works very well for recording tracks. When I first had the device, Openstreetmap was still fairly incomplete in my area, so it was good fun uploading GPX traces to help add detail to the map.

Eventually, I found out how to create a map from the Openstreetmap data that can be loaded into the Garmin etrex Vista HCX device. It requires a number of steps, but these are easy in Linux.

Grab the data

The data that is used to build the Openstreetmap map is freely available. There are a number sources for the data, but it would not be normal to want the entire world database. The people at Geofabrik provide a usefull service where they maintain a selection of extracts. Please remember this is provided as a service, so be kind to their servers. The extract I get is the one for Great Britain.


Get the tools

A number of tools are required to process the data to make it useful for the Garmin. Following is a list of tools that I have found work for me.

Used to split the map into manageable pieces.
Converts the OSM data into format suitable for Garmin device

Use the tools

These tools can be used as follows. This is not a definitive guide. Best refer to the relevant sites for the tools, but this is how I am using the commands.


java -Xmx1536m -jar splitter.jar \
   --max-nodes=1000000 \
   --mapid=63240001 \

This will generate a series of files from the input.


CMD="java -Xmx1024m -jar mkgmap.jar \
   --route --remove-short-arcs \
   --add-pois-to-areas --index \
   --location-autofill=bounds \
for f in 6324*.osm.pbf
    echo $f
    $CMD $f

After this is run, we should have a number of .img files. At this point, it may be possible to use these tiles with the Garmin map tool for the PC. But why bother. Let us just bundle these all up into one large file.

java -Xmx1024m -jar mkgmap.jar \
   --gmapsupp --family-id=50 --product-id=1 63*.img

This should result in a single map file named gmapsupp.img. All we need to do now is copy this to the Garmin directory on the SD card used by the Etrex Vista HCx.


Thursday, August 09, 2012

Windows 7 use NTP when in domain

Having recently had to reload windows, one of the little things to irritate me was the clock being wrong. It would seem logical that any computer with a reliable web connection should have the correct time. Well the default situation for Windows 7, when in a domain is to not allow the user to select a NTP server to sync with. Sensibly, it will sync with the domain controller.

Unfortunately our domain controller does not have the correct time. So my clock was wrong, and there was no 'point and click' way to fix it.

After some searching around a solution was found.

  • Click 'Start' and type cmd in the search box
  • Right click cmd.exe in the results, and select 'Run as administrator'
  • At the command prompt, run the following:

c:\>w32tm /config /update /manualpeerlist:"" /syncfromflags:manual
c:\>net stop w32time
c:\>net start w32time

It would be good to change the URL in the first command to a suitable pool from this list based on your location.