Nous utilisons des cookies pour vous garantir la meilleure expérience sur notre site. Si vous continuez à utiliser ce dernier, nous considèrerons que vous acceptez l'utilisation des cookies. J'ai compris ! ou En savoir plus !.
banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

Pour sécuriser votre compte sur les forums du GeoRezo, nous demandons de changer votre mot de passe.

Vous allez recevoir un message pour effectuer ce changement de mot de passe.

Merci de bien respecter les règles préconisées.

#1 Fri 15 October 2004 10:49

SIG Parc Des Marais
Invité

Script de conversion fichier *.tab vers *. tfw

Je viens d'installer ce script de conversion des fichiers de georef *.tab en *. tfw. Seulement, il ne fonctionne pas.
Avez-vous rencontre ce probleme ou une solution / a ce probleme de script ou un equivalent qui fonctionne...

Merci par avance
LA

 

#2 Mon 18 October 2004 13:03

Sigeal
Invité

Re: Script de conversion fichier *.tab vers *. tfw

De: Christophe DAMOUR (SIGeal)
J'ai teste avec succes ce script trouve sur le net...
Pour l'utiliser, il suffit de le copier dans un nouveau script, de le compiler et de le lancer.

Code:

' Name:    Conv.Tab2TFW
'
' Version:   1.5
'
' Title:    Converts MapInfo TAB meta-files towards ArcView image worldfiles
'
' Topics:   Conversion, MapInfo, georeferencing, TAB
'
' Description: In MapInfo an image worldfile is called a TAB file. This script
'       converts such a worldfile towards a worldfile usable in ArcView.
'       This script doesn't just create TFW files (the worldfiles for a
'       TIFF file), but it converts to any worldfile that goes with the
'       original image.
'
'
' Requires:  None
'
' Self:    None
'
' Returns:   None
'
' Creation:  Dirk Voets, ESRI Nederland, December 16, 1999
'
' Changes:   Dirk Voets, December 21, 1999
'         TAB files may contain leading spaces, so:
'         Changed tabLine ( Type + RASTER .Quote)
'         to tabLine.IndexOf( Type + RASTER .Quote) = -1
'         Many thanks to Shane Cunnane for pointing me to it.
'       Dirk Voets, January 20, 2000
'         Due to roundings strange resolutions appeared every now
'         and then. Fixed that.
'         Many thanks to Slawek Szymanski for pointing me to it.
'       Dirk Voets, July 14, 2000
'         X and Y may be separated by a space in TAB. Didn't check
'         that, resulting in errors. Fixed that now. Thanks to Chris
'         Wayne [ESRI-Olympia] for mentioning this.
'       Thomas Balstrøm & Dirk Voets, July 26, 2000
'         Thomas changed the script so it would convert many TAB
'         files at once. Minor changes applied by DV.
'       Dirk Voets, July 27, 2000
'         Fixed a sub-pixel shift problem caused by a difference in
'         definition between MapInfo and ArcView.
'       Dirk Voets, February 3, 2003
'         Leading and trailing spaces in the TAB file introduced some
'         problems. Native MapInfo doesn't write those spaces, but
'         other applications apparently do. Fixed that. Thanks to
'         Chris Watson for bringing it to my attention.

'##asking for TAB files

fnToBeConvertedFiles = FileDialog.ReturnFiles({ *.tab },
{ MapInfo World files (*.tab) },
Select one or more MapInfo tab-files for conversion ,
0)

'##check for valid input
If (fnToBeConvertedFiles.Count = 0) then
'Canceled by user
msgbox.warning( Canceled , )
exit
end

for each tabFileName in fnToBeConvertedFiles
tabLF = LineFile.Make(tabFileName, #FILE_PERM_READ)

'## Deciding worldfile filename
tabLine =
while ((tabLF.IsAtEnd.Not) and (tabLine.Contains( File ).Not))
tabLine = tabLF.ReadELT
end

if (tabLF.IsAtEnd) then
'## wrong TAB format. File of origin not specified
msgbox.error( Unexpected TAB file format. +NL+
Is this the TAB file of an image? +NL+
Bailing out... , )
exit
end

FileExt = tabLine.Right(4).Left(3)
tfwFileExt = FileExt.Left(1)+FileExt.Right(1)+ w
tabLine = tabLF.ReadELT

if (tabLine.IndexOf( Type + RASTER .Quote) = -1) then
'##Wrong TAB
msgbox.error( Unexpected TAB file format. +NL+
Expected FileType, got +tabLine+NL+
Is this the TAB file of an image? +NL+
Bailing out... , )
exit
end

tfwFileName = tabFilename.GetName.Substitute( .TAB , . +tfwFileExt).AsFileName

'## Trying to create a valid filename object to write to
tfwLF = LineFile.Make(tfwFileName, #FILE_PERM_WRITE)
if (tfwLF = NIL) then
tfwLF = LineFile.Make(( /root/ +tfwFileName.GetBaseName).AsFileName, #FILE_PERM_WRITE)
msgbox.warning( tfw-file is being written to +tfwLF.GetFileName.GetFullName, Writing info... )
If (tfwLF = NIL) then
msgbox.error( Cannot write tfw file, not enough permissions or file in use. Bailing out... ,
Writing info... )
exit
end
end

WorldCoordLst = {}
PixelCoordLst = {}

'## Reading co-ordinates from TAB file
while (tabLF.IsAtEnd.Not)
tabLine = tabLF.ReadElt
If (tabLine.Contains( ) Label )) then
WorldCoordsString = TabLine.Left(TabLine.IndexOf( ) ))
WorldCoordsString = WorldCoordsString.Right(WorldCoordsString.Count - WorldCoordsString.IndexOf( ( ) - 1)
WorldCoordLst.Add(WorldCoordsString.AsTokens( , ))
TabLine = TabLine.Right(TabLine.Count - TabLine.IndexOf( ) ) - 1)
PixelCoordsString = TabLine.Left(TabLine.IndexOf( ) ))
PixelCoordsString = PixelCoordsString.Right(PixelCoordsString.Count - PixelCoordsString.IndexOf( ( ) - 1)
PixelCoordLst.Add(PixelCoordsString.AsTokens( , ))
end
end

if ((WorldCoordLst.Count < 2) OR (PixelCoordLst.Count < 2)) then
'## Less then two coordinates defined in TAB. No good...
msgbox.error( TAB file doesn't contain enough (or any?) coordinates +NL+
resolution calculations impossible +NL+
Bailing out.... , )
exit
end

'## Calculating resolution and upper left co-ordinate of image

RealXKwad = (WorldCoordLst.Get(1).Get(0).Trim.AsNumber - WorldCoordLst.Get(0).Get(0).Trim.AsNumber)^2
RealYKwad = (WorldCoordLst.Get(1).Get(1).Trim.AsNumber - WorldCoordLst.Get(0).Get(1).Trim.AsNumber)^2
numRealDist = (RealXKwad + RealYKwad).sqrt

PixelXKwad = (PixelCoordLst.Get(1).Get(0).Trim.AsNumber - PixelCoordLst.Get(0).Get(0).Trim.AsNumber)^2
PixelYKwad = (PixelCoordLst.Get(1).Get(1).Trim.AsNumber - PixelCoordLst.Get(0).Get(1).Trim.AsNumber)^2
numPixelDist = (PixelXKwad + PixelYKwad).sqrt

Resolution = (numRealDist/numPixelDist)

XShift = WorldCoordLst.Get(0).Get(0).Trim.AsNumber - (PixelCoordLst.Get(0).Get(0).Trim.AsNumber * Resolution)
YShift = WorldCoordLst.Get(0).Get(1).Trim.AsNumber + (PixelCoordLst.Get(0).Get(1).Trim.AsNumber * Resolution)

'## correcting sub-pixel definition difference between MapInfo and ArcView
XShift = XShift + (Resolution / 2)
YShift = YShift - (Resolution / 2)

'##Calculating output formats (10 significant digits)
strFTemplate = dddddddddddd
strResolutionFormat = strFTemplate.Left(Resolution.Log(10).Ceiling) + . +
strFTemplate.Left(10 - (Resolution.Log(10).Ceiling))
strXFormat = strFTemplate.Left(XShift.Log(10).Ceiling) + . +
strFTemplate.Left(10 - (XShift.Log(10).Ceiling))
strYFormat = strFTemplate.Left(YShift.Log(10).Ceiling) + . +
strFTemplate.Left(10 - (YShift.Log(10).Ceiling))

'## Time to write the TFW
tfwLF.WriteElt(Resolution.SetFormat(strResolutionFormat).AsString)
tfwLF.WriteELT( 0 )
tfwLF.WriteELT( 0 )
tfwLF.WriteELT( - + Resolution.AsString)
tfwLF.WriteElt(XShift.SetFormat(strXFormat).AsString)
tfwLF.WriteElt(YShift.SetFormat(strYFormat).AsString)

'## Cleaning up the mess
tfwLF.Flush
tfwLF.Close
tabLF.Close

end

msgbox.info(fnToBeConvertedFiles.Count.AsString++ file(s) converted. , Success! )
 

Pied de page des forums

Powered by FluxBB