代码名称:如何用MapBasic动态配准栅格图

作者/收集者:James.Liu/刘毅

开发环境:MapBasic

代码:

说明:
        当用户自己的系统中新得到栅格图片后,需要动态在系统中和其他矢量地图叠加显示,这时候我们对栅格图进行动态的配置。
必要条件:
        假设你的系统可以得到准确的配准信息!
环境:MapBasic


Include ”mapbasic.def”
Declare Sub Main
Declare Function register_nonmap_image(ByVal filename As String,ByVal tablename As String) As Logical

Sub Main
Dim fname, tname As String
fname = ”c:\data\raster\photo.gif”  ’name of an existing image
tname = PathToDirectory$(fname)+ PathToTableName$(fname) + ”.tab” ’name of table to create

If FileExists(tname) Then
Note ”The image file is already registered; stopping.”
Else
If register_nonmap_image(fname, tname) Then
Note ”Table file created for the image file: ”+ fname + ”.”
Else
Note ”Could not create table file.”
End If
End If
End Sub

Function register_nonmap_image( ByVal filename As String,ByVal tablename As String) As Logical
register_nonmap_image = FALSE
onError GoTo handler
Open File tablename For Output As #1 FileType ”MIta”
Print #1, ”!Table”
Print #1, ”!Version 300”
Print #1, ”!charset Neutral”
Print #1
Print #1, ”Definition Table”
Print #1, ” File ””” + filename + ””””
Print #1, ” Type ””RASTER”” ”
Print #1, ” (1,1) (1,1) Label ””Pt 1””, ”
Print #1, ” (5,1) (5,1) Label ””Pt 2””, ”
Print #1, ” (5,5) (5,5) Label ””Pt 3”” ”
Print #1, ” CoordSys NonEarth Units ””mm”” ”
Print #1, ” Units ””mm”” ”
Print #1, ” RasterStyle 1 45” ’ Brightness; default is 50
Print #1, ” RasterStyle 2 60” ’ Contrast; default is 50
Close File #1
register_nonmap_image = TRUE ’ set function return value
last_exit:
Exit Function
handler:
Close File #1
Resume last_exit
End Function