Reading .OV2 TomTom POI Files using Java

December 31st, 2009 by admin No comments »

I’m posting today some source code about the famous TomTom One .OV2 file formats. These files are the one used by TomTom to store Point of Interest information within their navigation systems. However such format is proprietary, the data specs can be found in the TomTom website (see this PDF at section 2.4). I wrote down a simple procedure that gathers record by record only the simple POI records. Actually the OV2 format is a little bit more complicated than a simple list of POIs and it can be subjected to changes and version incompatibilities. I tested it with POIs taken from my TomTom ONE XL and ti worked great, however if the OV2 files contains proprietary or special record types (not specified in TomTom data sheets) these procedures will simply stop since it is not possible for this format to distinguish between a corrupted file or non standard encoding.

I hope you’ll find it interesting.

package readers;

import java.io.FileInputStream;
import java.io.IOException;

public class OV2RecordReader {

	public static String[] readOV2Record(FileInputStream inputStream){
		String[] record = null;
		int b = -1;
		try{
			if ((b = inputStream.read())> -1) {
				// if it is a simple POI record
				if (b == 2) {
					record = new String[3];
		    	    long total = readLong(inputStream);

		    	    double longitude = (double) readLong(inputStream) / 100000.0;
		    	    double latitude = (double) readLong(inputStream) / 100000.0;

		    	    byte[] r = new byte[(int) total - 13];
		    	    inputStream.read(r);

		    	    record[0] = new String(r);
		    	    record[0] = record[0].substring(0,record[0].length()-1);
		    	    record[1] = Double.toString(latitude);
		    	    record[2] = Double.toString(longitude);
		    	}
				//if it is a deleted record
				else if(b == 0){
					byte[] r = new byte[9];
		    	    inputStream.read(r);
				}
				//if it is a skipper record
				else if(b == 1){
					byte[] r = new byte[20];
		    	    inputStream.read(r);
				}
				else{
					throw new IOException("wrong record type");
				}
			}
			else{
				return null;
			}
		}
		catch(IOException e){
			e.printStackTrace();
		}
		return record;
	}

	private static long readLong(FileInputStream is){
		long res = 0;
		try{
			res = is.read();
			res += is.read() <<8;
			res += is.read() <<16;
			res += is.read() <<24;
		}
		catch(IOException e){
			e.printStackTrace();
		}
		return res;
	}
}

GeoMondrian Example

November 18th, 2009 by admin 1 comment »

As soon as I’ve started digging into OLAP Architectures I realized how complicated things might become whenever looking for extra features. Most of the commercial OLAP solutions are providing “classic” OLAP features for data warehousing. It means that only simple numeric, strings and dates would be supported. Spatial Data Warehouses  architectures instead, are still in their infancy and there exists no commercial product that is actually providing such SOLAP functionalities. There exists several academic proposals instead which can provide a good overview on the features that can be supported by SOLAP Servers.

One of these acedemic prototypes is Geo Mondrian.

GeoMondrian is a spatially-enabled version of Pentaho Analysis Services (Mondrian). It has been released under the EPL. GeoMondrian is the first implementation of a true SOLAP server. It provides a consistent integration of spatial objects into the OLAP data cube structure, instead of fetching them from a separate spatial database, web service or GIS file. To make a simple analogy, GeoMondrian brings to the Mondrian OLAP server what PostGIS brings to the PostgreSQL database management system.

Unfortunately the developer team seemed to be quite busy during the last year, and even communicating with them is quite a challenge! That’s why I’ve decided to publish a couple of advices to whom may decide to use GeoMondrian for  developing SOLAP applications. Here attached you can find an archive that contains all that you need to setup a sample SOLAP server with geographic data source. It is designed to be working on PostgreSQL+Postigs since it is the only spatial database to be supported right now.

What you have to do in order to be able to use this unofficial build release of GeoMondrian is to load the .SQL script into your postgresql+postgis database and than run the Test application (be sure that the .XML schema definition is in the same parent directory, to have set up properly your JDBC connection and have included the libraries that are present in the “lib” folder).

I hope that it will help!

zip-icon1

Supported Spatial Data Formats

October 15th, 2009 by admin No comments »

crystal_clear_action_db_status

GIS People often have to fight agains data conversions. The constellation of Desktop GIS suites make our life harder and harder while approaching to ETL processes. A relevant issue in ETL processes is the so called “data formats discovery”. Finding information about which software is supporting which spatial data type can turn a simple routing task into a “mission impossible” waist of time.

To overcome this inconvenient we can refer to the support guide of a famous ETL software: FME. FME is a complete spatial ETL solution that enables GIS Professionals to quickly translate, transform, integrate and distribute spatial data. In our case it simplifies our life by means of the “Supported Formats” guide.

Visiting this link [WWW] you may find a list of supported types from this software (quite a huge list!), however by clicking on each single data types you will be able to access to PDF version data sheets of each data source, complete of description, supported types, versions, and lot more.

Image Rectification

October 9th, 2009 by admin No comments »

conversion

hi to all… here you can find an easy guide to image rectification using Hugin software. This is the italian translation to the image rectification guide that can be found on the Hugin website.

Ecco qui una guida tutta italana alla rettificazione di immagini (utile per esempio nei processi di rilievo fotografico di edifici e reperti storici). E’ la traduzione e riadattamente italiano della guida inglese che può essere trovata sul sito ufficiale del software Hugin. All’interno del documento vi sono ulteriori dettagli sulle fonti utilizzate.

Download it ! Pdf Document

Choosing the perfect Free Software License

August 25th, 2009 by admin No comments »

Every time you start developing a new piece of software that needs external libraries to be used and integrated, the licensing dilemma strikes again. If you are a developer of a well standardized software company you can have stronger restrictions on the licenses to be used (even a list of usable licenses), however when you have to start your software from scratch, or start a software “business idea”, it is important to know something more on what you can take and what you can reuse without breaking somebody’s heart. I would like to dedicate this “in progress” post to collect in one page a brief description of the major families or licenses that can be used while developing free software but with possible commercial purposes! I hope it will help and I warmly advise anybody that would suggest any further detail to post a comment and I will be glad to integrate my content with that!

Apache License 2.0

  • Free Software
  • OSI Compatible
  • Linking from code with a different license
  • no Copyleft
  • GPL v3 Compatible

software can be redistributed in any other license, but should be noticed that Apache software is included
Two files that must be put at the top directory of redistributed software packages:

* LICENSE – a copy of the license itself.
* NOTICE – A “notice” text document listing the names of licensed libraries used, together with their developers.

In every licensed file, any original copyright or patent notices in redistributed code must be preserved, and in every licensed file changed a notification must be added stating that changes have been made to that file.

Gnu LGPL License

  • Free Software
  • OSI Compatible
  • Linking from code with a different license
  • Copyleft
  • GPL Compatible

an author may, through a copyleft licensing scheme, give every person who receives a copy of a work permission to reproduce, adapt or distribute the work as long as any resulting copies or adaptations are also bound by the same copyleft licensing scheme.

primarly used for software libraries; has copyleft restrictions. it is something in between GPL and BSD/APACHE like licenses.

BSD Licenses

  • Free Software
  • OSI Compatible
  • Linking from code with a different license
  • no Copyleft
  • GPL Compatible

Eclipse Public License

  • Free Software
  • OSI Compatible
  • Linking from code with a different license
  • Copyleft
  • no GPL  Compatible

is designed to be business friendly. allows developers to create their own licenses on the portion of the codes that are added.

Academic Free License

  • Free Software
  • OSI Compatible
  • Linking from code with a different license
  • no Copyleft
  • GPL  Compatible unknown

considered redundant specifically to the Apache License 2.0

MIT License

considered a duplicate of BSD-like licenses

PostgreSQL Custom Types

May 16th, 2009 by admin 1 comment »

postgresql

In the last year I’ve spent six months digging into a PostgreSQL project. PostgreSQL is one of the most interesting and fast developed database management systems. However it is still a little bit behind the major commercial competitors, it is without any doubt, the most advanced OpenSource and Free DBMS. On the great features of PostgreSQL is the documentation of its architecture, that is maintained updated constantly by its vivid and active community. Although this community provides one of the best (the fastest that I’ve every experienced as a single user) developer on-line support system, at that time (and still now!) I had serious difficulties to find out information about on of the most used and useful coding extensions: custom types. Some of you may had to work with PostgreSQL extensions like PostGIS (the simplest and most effective spatial extension that integrates spatial information into PostgreSQL) and wanted to extend or to provide similar functionalities so easy to use and comfortable. I was mentioning the user-friendly constructors for spatial objects. Custom Types for defining spatial objects are defined in the SQL language like that

POINT('37','-97');

(for more information, take a look to this link)

This type of syntax is only possible (as far as I know) if the type is defined using a C function, and for instance compiled into a .so shared object library provided to PostgreSQL. C PostgreSQL custom types are defined by two functions that translate the low level description of the type into SQL usable constructors. Here it follows the code  to define constructors for a Currency type, and attached into this file, there is the source code for other operations like equals, greater and exchange rate calculation (the source of this piece of code is PostgreSQL C Reference Documentation).

/*
**  Name: fcur_in()
**
**        Converts an fcur value from external form
**	  to internal form.
*/

PG_FUNCTION_INFO_V1(fcur_in);

Datum fcur_in(PG_FUNCTION_ARGS)
{
    char  * src     = PG_GETARG_CSTRING(0);
    char  * workStr = (char *)palloc( strlen( src ));
    char  * units   = NULL;
    char  * name    = NULL;
    char  * xrate   = NULL;
    fcur  * result  = NULL;
    char  * endPtr  = NULL;

    strcpy( workStr, src );

    units = strtok( workStr, "(" );
    xrate = strtok( NULL, "/)" );
    name  = strtok( NULL, ")" );

    result = (fcur *)palloc( sizeof( fcur ));

    memset( result, 0x00, sizeof( fcur ));

    result-&gt;fcur_units = strtod( units, &amp;endPtr );

    if( xrate )
    {
	result-&gt;fcur_xrate = strtod( xrate, &amp;endPtr );
    }
    else
    {
	result-&gt;fcur_xrate = 1.0;
    }

    if( name )
    {
	strncpy( result-&gt;fcur_name,
		 name,
		 sizeof( result-&gt;fcur_name ));
    }
    else
    {
	strncpy( result-&gt;fcur_name,
		 unknownCurrencyName,
		 sizeof( result-&gt;fcur_name ));
    }

    PG_RETURN_POINTER( result );
}

/*
**  Name: fcur_out()
**
**        Converts an fcur value from internal form
**	  to external form.
*/

PG_FUNCTION_INFO_V1(fcur_out);

Datum fcur_out(PG_FUNCTION_ARGS)
{
    fcur  * src  = (fcur *)PG_GETARG_POINTER( 0 );
    char  * result;
    char    work[16+1+sizeof(src-&gt;fcur_name)+16];

    sprintf( work, "%g(%g/%s)",
	     src-&gt;fcur_units,
	     src-&gt;fcur_xrate,
	     src-&gt;fcur_name );

    result = (char *)palloc( strlen( work ) + 1 );

    strcpy( result, work );

    PG_RETURN_CSTRING( result );

}

the Italian @

May 9th, 2009 by admin No comments »

@

I was reading the New York Times, where I discovered an interesting article standing out again from the crowd of tech reviews. I’m always attracted by the searticles that describe Italians and Italian researches, since the objectivity of  NY Times journalists make easier to understand the real value of that piece of work. In this case the article was digging some years ago (nine to be precise) into “La Repubblica’s” archive which explained why the @ symbol was firstly used by italian merchants. A Florentine merchant named Francesco Lapi used the symbol @ in a letter written 473 years ago today, on May 4, 1536. As prof. Giorgio Stabile (Full professor of   Science’s  history at “La Sapienza” university, Rome) explained to The Guardian in 2000, Francesco Lapi’s letter was sent from Seville to Rome and described the cargo on three ships that had just returned to Spain from Latin America:

“There, an amphora of wine, which is one thirtieth of a barrel, is worth 70 or 80 ducats,” Mr. Lapi informs his correspondent, representing the amphora with the now familiar symbol of an “a” wrapped in its own tail.The Spanish word for amphora was “arroba,” and the Oxford English

Dictionary explains that the unit was approximately 25 pounds of a solid or about 3 gallons of a liquid. In modern Spanish, the @ symbol on keyboards is still called an arroba — as a Google image search illustrates. The word “arroba” itself was a Spanish corruption of an older Arabic word.

(src)

All roads lead to Flash

May 3rd, 2009 by admin No comments »

 

 

Flash

When approaching a new design of a rich content web application, the same questions always come out: which is the best framework for the purpose?

Well.. depending on your definition of “rich” and also to the complexity of the interactions within the platform that you want to built up, a few approaches exist to solve this problem. The first possible I will call it the “Javascript” approach. Thanks to the affirmed level of the Javascript technology, there are a lot of interesting libraries (such as JQuery or Dojo) that can provide the developer of a powerful toolkit for building fancy interactions and ready to go components. Especially if paired up with other strong Ajax frameworks (like Zend Framework), it can create a spicy mixture that boosts the development process. But what about the “after”? Usually independent programmers  don’t care that much about the maintenance of the code… and more generally about the application development process, since the majority of software project failures are registered in the development phase.

But what if the project results successful? Code maintenance could be as much harmful as software development! In such situation I would personally have preferred to have chosen the second approach, that I will call “the Flash approach”. Nowadays flash players are installed in every PC, and a web browser without flash player support… has more than a half of the websites unavailable for its users. Flash movies are embedded everywhere (for Video streaming, Audio streaming, Slideshows…) but the power of flash movies is not only on the easy interface and interfacing power (i.e. a .swf movie can be considered as a small, fast web  embedded application). A lot of programming languages have moved forward to match that standard and provide different languages to create complex flash compiled web applications . Those ones built in flash are not only fast to develop, but also to maintain. Opposing to their javascript competitors, websites built in flash (e.g. the famous French music website Deezer) take both positive aspects from website applications and standalone ones. Hence  from a developer point of view, those websites are nothing more than a set of compiled applications, merged together in a light fashion to be served by the Internet community.

Just to have a taste of what is outside for the Flash development,  I listed some swf generators APIs:

  • Flex: obviously the mastered languages from Adobe to create flash applications, it provides an XML based language as support to the Actionscript interactions
  • OpenLaszlo: a direct competitor of Flex. It provides a similar XML based syntax to build .swf web applications
  • Ming: a C , C++, PHP, Python, Ruby, and Perl (yes you have understood…) library to generate SWF files

Time for cleaning…

May 1st, 2009 by admin No comments »

hi there! as you can see those pages have been cleaned again, since Wordpress platform seems to hate me and my writing skills…

Sorry for this issue but I promise I will refill my pages with the whole old content!

stay in touch!