Archive for December, 2010

MapInfo Tools published on Codeplex

December 18, 2010 Leave a comment

I published tfw2tab.ps1 along with a new script for creating seamless tab files on codeplex today. The project is called MapInfo Tools.

Categories: Uncategorized

Create MapInfo TAB files from TFW files

December 17, 2010 Leave a comment

A simple powershell script to create .tab files from .tfw files. Inspiration from

# sample usage: dir *.tfw | & c:\scripts\tfw2tab.ps1

param($coordsys = “CoordSys Earth Projection 8, 1000, `”m`”, 15, 0, 1, 5500000, 0″)

# ref:

# parse coefficients from .tfw file
$tfw = Get-Content $_
$dx = [double]$tfw[0];
$dy = [double]$tfw[3];
$x0 = [double]$tfw[4];
$y0 = [double]$tfw[5];

# calculate additional points for .tab file
$x1 = $x0 + $dx
$y1 = $y0
$x2 = $x0
$y2 = $y0 + $dy

# figure out filenames for target
$tab = $_.FullName.SubString(0, $_.Fullname.Length $_.Extension.Length) + “.tab”
$tif = $_.Name.SubString(0, $_.Name.Length $_.Extension.Length) + “.tif”

# create tab file content
$text = @”
!version 300
!charset WindowsLatin2

Definition Table
File “$tif”
($x0,$y0) (0,0) Label “Pt 1”,
($x1,$y1) (1,0) Label “Pt 2”,
($x2,$y2) (0,1) Label “Pt 3”
Units “m”


# create tab file and set content
new-item -path $tab -type file -force -value $text

EDIT: Do not use this code. Download the latest version from instead.

Categories: Uncategorized

Padding numbers with zeros using regular expressions and powershell

I had a very small scripting task today. A bunch of text files contained numbers that should be padded with initial zeros.

For example, the following text:

some text
identifier: “12”
some text
identifier: “8”
some text

Should be replaced by:

some text
identifier: “012”
some text
identifier: “008”
some text


Using regular expressions this task can be accomplished by:

function Pad-Numbers
        $text = Get-Content $_.FullName
        $text = $text -creplace “identifier: `”(\d)`””, “identifier: `”00`$1`””
        $text = $text -creplace “identifier: `”(\d\d)`””, “identifier: `”0`$1`””
        Set-Content -path $_.FullName -value $text

Get-ChildItem -path data -filter *.txt | Pad-Numbers

A good source for regular expressions for powershell users is

Categories: Uncategorized