Decimal degrees do dd°mm'ss"

A quick task - convert decimal degrees back to dd°mm'ss''. Not sure if there are other ways of doing this in manifold at this stage so an active column did the trick.

A script is in c#, so just copy and paste it to the script attached to a table when creating an active column. Then simply put the appropriate method name to be used by a column and that's basically it.


using Manifold.Interop.Scripts;
using System;

class Script {

	static string Decimal2Degrees(double decimalDegrees)
		int fullDegrees = (int) Math.Floor(decimalDegrees);
		double decimalMinutes = (decimalDegrees - fullDegrees) * 60;
		int fullMinutes = (int) Math.Floor(decimalMinutes);

		double decimalSeconds = (decimalMinutes - fullMinutes) * 60;
		int fullSeconds = (int) Math.Round(decimalSeconds);

		string strMinutes = fullMinutes.ToString();
		if(fullMinutes < 10){
			strMinutes = "0" + fullMinutes.ToString();

		string strSeconds = fullSeconds.ToString();
		if(fullSeconds < 10){
			strSeconds = "0" + fullSeconds.ToString();

		return fullDegrees.ToString() + "°" + strMinutes + "'" + strSeconds + "\"";

	static object getLongitude()
		return Decimal2Degrees((double)Context.Record.get_Data("Longitude (I)"));

	static object getLatitude()
		return Decimal2Degrees((double)Context.Record.get_Data("Latitude (I)"));

[EDIT] As Adam has pointed out, the code in its first form could return 60 for seconds what of course does not make too much sense. Now, there are a few ways of fixing it - one can use floor and drop the remaining decimal part, or a test can be performed to check if the number of seconds does not exceed 59 seconds, or maybe if the number of seconds rounds to 60 one should increase number of minutes by one and then degrees by one if minutes reach 60 and... Well, to keep it simple at this stage one line of the code needs to be added just after assigning a value to the fullSeconds variable:

fullSeconds = fullSeconds > 59? 59: fullSeconds;

This works as if one used Math.Floor but only if the number rounds to 60. Not perfect for all uses but...

One more thing - as I started thinking a bit more about what the code actually does it appeared to me that for negative coordinates it will return wrong values as it uses Math.Floor - so for -37.50 one will get -38... Living on the northern hemisphere east of Greenwich and not having to deal with negative coordinates on a daily basis, huh?

A first post or a post without an interesting title...

It's been already quite a while since we decided to launch a blog so it's the high time to publish a first post ;-)

A 'knowledge base' in a form of a web blog appeared to us as a good idea and it was the main reason behind creating yet another blog. This site will be a common place where we describe the projects we work or worked on, some problems we have encountered and the way they were solved. Of course some of them were and will be simple, some more sophisticated, but in general they would appear to be struggling enough to be worth remembering - not always obvious solutions are so obvious after a day of work you know...

The site will also contain a portfolio section where one will find some examples of the projects we take part in. One will find here some decent examples of cartographic design, web mapping solutions and such. We will do our best to share live examples whenever possible, although in some cases (due to licensing restrictions for example) video clips will be published instead.

And cartoninjas... The inspiration came after watching a cinema version of a Japanese series called Zatoichi. Ninja's samersault walk is what it was exactly ;-) There couldn't be a better way of getting to a desired place quickly, could there?
We're skilled in the geo-spatial technologies and often work on interesting projects, not to mention dirty jobs we are quite often contracted to do. Hence the logical connection - cartoninjas. We walk rather normally though and tend to keep stuff as simple as possible.

Over the next few weeks this site will be undergoing some changes - graphical appearance will be one amongst many. We will also be gathering some more stuff to fill in the portfolio section and alike.

Ok, sit comfortably and relax, cartoninjas are swinging into action ;-)