Styling Navteq data using Manifold

Recently we were asked to prepare some map layers for a web application. The exercise was about styling Navteq 2010 data in manifold so created maps can be then used for rendering a tiled base map but also used by a map server.

Although manifold lacks some of the carto tools available in other GIS packages or graphic software it does offer enough to complete such task. It actually does offer some other functions that let one create some nice map features - for example the road shields labels were created from a drawing linked to a SQL query that created road label points spaced evenly along the road lines. This backed with the automatic resolution of label conflicts allowed us to nicely place the road shields on the map.

Cutting image from a bigger raster source

This script has already been posted on the ( so nothing new will be presented...

There was one interesting thing though - how to get from a bbox of a geom used by the input drawing to the actual size of the output image in pixels. The script needed to cut images and preserve their actual resolution - as one would crop an image in photoshop.

First I had to prepare a coordinate converter and to grab some data off the image coordinate system needed later for calculating the actual size of a cut image in pixels:

//prepare coordinate converter in order to properly calculate image extent in pixels later
Manifold.Interop.CoordinateConverter coordConverter = manApp.NewCoordinateConverter();
coordConverter.Prepare((Manifold.Interop.Base)map.CoordinateSystem, (Manifold.Interop.Base)inputImage.CoordinateSystem);

//also grab the input image local scales
double imageLocalScaleX = inputImage.CoordinateSystem.ParameterSet["localScaleX"].Value;
double imageLocalScaleY = inputImage.CoordinateSystem.ParameterSet["localScaleY"].Value;

The next step was to grab the bounding box of a source geometry used to cut a new image from the source raster:

//grab the bounding box of an object
Manifold.Interop.Rect geomBbox = geomSet.get_Item(n).Box;

After that I used the bottom left and top right corners of the bbox and coverted them to the source image coordsys in order to calculate the size of the new image in pixels:

//get the corner points of the geom's bbox
Manifold.Interop.Point bottomLeft = manApp.NewPoint(geomBbox.XMin, geomBbox.YMin);
Manifold.Interop.Point topRight = manApp.NewPoint(geomBbox.XMax, geomBbox.YMax);

//convert them to the image coordsys
coordConverter.Convert((Manifold.Interop.Base)bottomLeft, null);
coordConverter.Convert((Manifold.Interop.Base)topRight, null);

//image size in pixels
int imageSizeX = (int)((topRight.X - bottomLeft.X) / imageLocalScaleX);
int imageSizeY = (int)((topRight.Y - bottomLeft.Y) / imageLocalScaleY);

//and then cut tile
map.RenderAreaTo(fileName, imageSizeX, imageSizeY, geomBbox, true);

Fairly straight forward isn't it?

Anyway, if you would like to use this script it is attached below. There are some input params and they need to be set prior to running the script. The reason behind using a RenderAreaTo method of a map object instead of the image object is explained in the script.

Although perhaps it would be easier to use gdal for the task than writing a script this exercise seemed to be interesting enough to give it a go. Having a GUI environment to choose areas of interest by simply drawing a rectangle over the image is a good reason isn't it ;-) Make sure though you switch off the input drawing before rendering the new images...

Also bear in mind that if you work with a high resolution ecw for example, the image you want to cut may be quite large since and the script calculates its size based on the source image resolution - to make it simpler: trying to cut a too big image out of a high res source image may make your pc unresponsive for a longer time ;-)

EDIT: I would almost forget - the input drawing is expected to have a column with names for the new images.

tileCutter.cs (7.53 kb)

Preparing the data description for the metadata docu

Today I had to prepare a description of all the vector drawings I had in a project in a semi tabular form listing a folder, contained drawings and their column, column types and the length of the data in each column. In other words I needed to create a dataset description for the metadata document needed in my current project.

Obviously collecting such data for a drawing or two is fairly quick but manually fetching data for multiple components would a pain in the neck…

A script seemed to be the best option here so I decided to write one ;-) It searches for the drawings contained in folders (one level of nesting) and then lists the needed stuff. It can easily be adapted to list drawings in a root folder as well and to dig deeper in nested folders. It can also be adjusted to look for other types of components or to grab some info about the coordsystems used by them - I just needed the drawings though hence a rather simplistic version of the script was enough.

Anyways, feel free to use it if you like (simply add a c# script and replace its content with the attached). Bear in mind script lists info only for drawings contained in a folder.

Output example:


ColumnName	DataType	FieldLength
ID	ColumnTypeInt32U	4
LENGTH	ColumnTypeFloat64	8
KLASA	ColumnTypeInt16	2
ID 2	ColumnTypeInt32	4
NUMER	ColumnTypeAText	16

ColumnName	DataType	FieldLength
ID	ColumnTypeInt32U	4
NAME	ColumnTypeAText	100
SHAPE_LENG	ColumnTypeFloat64	8
SHAPE_AREA	ColumnTypeFloat64	8
TOPO_CLASS	ColumnTypeInt32	4

 And the script:

using Manifold.Interop.Scripts;
using System;

class Script {
	static void Main() {

    static void pullDataDescription()
        //reference the app object first
        Manifold.Interop.Application manApp = new Manifold.Interop.Application();

        //grab doc object
        Manifold.Interop.Document manDoc = (Manifold.Interop.Document) manApp.ActiveDocument;

        //create output comments component
        Manifold.Interop.Comments cmt = manDoc.NewComments("Drawings&Data", false);
        cmt.Folder = null; //so it's always in the root folder

        //record the time this summary was created
        DateTime date = DateTime.Now;
        cmt.AddText("Report generated " + date.ToLongDateString() + " " + date.ToLongTimeString() + Environment.NewLine);
        cmt.AddText(writeBreakLine("*", 40) + Environment.NewLine);

        //iterate through components
        foreach (Manifold.Interop.Component cmp in manDoc.ComponentSet)
            //check if this is a folder
            if (cmp.Type == Manifold.Interop.ComponentType.ComponentFolder)
                Manifold.Interop.Folder fld = (Manifold.Interop.Folder)cmp;
                //write the folder name
                cmt.AddText(fld.Name + Environment.NewLine);
                cmt.AddText(writeBreakLine("=", 40) + Environment.NewLine);

                //iterate through drawings
                foreach (Manifold.Interop.Component fldCmp in fld.Children)
                    //check if this is a drawing
                    if (fldCmp.Type == Manifold.Interop.ComponentType.ComponentDrawing)

                        Manifold.Interop.Drawing drw = (Manifold.Interop.Drawing)fldCmp; 

                        //write drawing name
                        cmt.AddText(drw.Name + Environment.NewLine);
                        cmt.AddText(writeBreakLine("-", 40));

                        //write headers for the tables
                        cmt.AddText("ColumnName" + "\t" + "DataType" + "\t" + "FieldLength" + Environment.NewLine);
                        //iterate through colums
                        foreach (Manifold.Interop.Column col in ((Manifold.Interop.Table)drw.OwnedTable).ColumnSet)
                            if (col.Category == (int)Manifold.Interop.ColumnCategory.ColumnCategoryNative)
                                cmt.AddText(col.Name + "\t" + (Manifold.Interop.ColumnType)col.get_Type()  + "\t" + col.Size + Environment.NewLine);
                        cmt.AddText(writeBreakLine("-", 40) +    Environment.NewLine);
                //write the folder name
                cmt.AddText(writeBreakLine("=", 40));
                cmt.AddText("eof " + fld.Name + Environment.NewLine + Environment.NewLine + Environment.NewLine);
        //open the comments component

    //writes a 'break line'
    static string writeBreakLine(string character, int length)
        string output = string.Empty;
        for (int n = 0; n < length; n++)
            output += character;
        output += Environment.NewLine;
        return output;

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 ;-)