G'day Everyone!
A few days ago one of my clients approached me with the following problem: He
had oodles of MapInfo layer information all in one directory. All he wanted
to know was whether the MBR (minimum bounding rectangle that contains the
data) could be fetched directly out of each layer's "map" file. This would
allow him to write a program - external to MapInfo - that could distribute
the layers to separate directories according to the extent of each layer's
data.
The answer is, yes, the MBR can be extracted from a "map" file directly - the
listing below shows how to do it. Although the technique is shown in
MapBasic (this is a MapInfo list, after all!), the client's program was
actually written in Delphi. Note that the snippet also displays some of the
layer's coordinate system parameters.
Robert Edwards
The MapTools Company
-----------------------------------------------------------
Dim MapName as string
MapName= FileOpenDlg("","","map","Name of the MapFile?")
if MapName="" then exit sub end if
Print chr$(12) Print "Map parameters from: "+MapName
Open File MapName for Binary as #1
Dim Codes,CodeB as smallint
Get 1,353,Codes
CodeB=Codes/256
if CodeB=2 then print "Lat/Lon definition"
else print "Not a Lat/Lon definition" end if
' note: results are in the units of the layer's coordinate system
Dim DelX,DelY,X0,Y0 as float
Get #1,369,DelX Get #1,,DelY Get #1,,X0 Get #1,,Y0
Print "DelX,DelY,X0,Y0: "
+Str$(DelX)+" "+Str$(DelY)+" "+Str$(X0)+" "+Str$(Y0)
Print "Bounds - LeftX,RightX,LowY,UpperY:"
if CodeB=1 then
Print Str$((-1000000000.0-X0)/DelX)+" "
+Str$(( 1000000000.0-X0)/DelX)
else
Print Str$(-(1000000000.0-X0)/DelX)+" "
+Str$(-(-1000000000.0-X0)/DelX)
end if
Print Str$((-1000000000.0-Y0)/DelY)+" "
+Str$(( 1000000000.0-Y0)/DelY)
' note: these results are in the units of the layer's coordinate system
Dim MBRMinX,MBRMaxX,MBRMinY,MBRMaxY as integer
Get #1,273,MBRMinX Get #1,,MBRMinY
Get #1,,MBRMaxX Get #1,,MBRMaxY
print "MBR MinX,MaxX,Miny,MaxY:"
if CodeB=1 then
Print Str$((MBRMinX-X0)/DelX)+" "
+Str$((MBRMaxX-X0)/DelX)
else
Print Str$(-(MBRMaxX-X0)/DelX)+" "
+Str$(-(MBRMinX-X0)/DelX)
end if
Print Str$((MBRMinY-Y0)/DelY)+" "
+Str$((MBRMaxY-Y0)/DelY)
close file #1
----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]