Here are some previous mapinfo-l binary questions. Just go search the directionsmag.com To the MapInfo-Listers: Remember to cc a mail to <[EMAIL PROTECTED]>. There are a lot of interesting questions with no answer. Others wise give a sum of replies. ************************************************************************************************************* The program UltraEdit will allow you to read a binary file. Goto www.ultredit.com to download a shareware version. -----Original Message----- From: Ken Hickey [mailto:[EMAIL PROTECTED]] Sent: Friday, March 09, 2001 06:28 To: MapInfo-L Subject: MI-L binary vs ascii G'day all This is probably a basic question, but what is a binary file and how = does it differ from an ASCII file of the same data. For example a DEM = can be exported from ERMapper as an ASCII file or a binary file, I can = read the former in a text editor, but not the latter. Are all binary = files 16bit numbers and all ASCII files 8bit (the latter using standard = ASCII characters)? Aren't ASCII characters coded in binary numbers? Also what software is available to read/edit the numbers/text in a = binary file? Cheers Ken Hickey ************************************************************************************************************* Hi Martin, Yes it is possible to read and write binary code with MapBasic (at least by using Get And Put functions, but I don't know if that is appropriate for your purposes). Only thing you have to keep in mind when using Get And Put functions is that MapInfo reads binary value as a signed value and it needs to be converted back to unsigned original. Other thing that makes binary handling little tricky is related to MapInfo variables which omit a Byte (ie. 8 bit long) variable, but it can be worked around by reading the data into for example SmallInt variable and extracting the high and low byte values with <Mod> and <\> operators. Besides theese limitation, binary data handling seems to work fine. It actually works so good that I even made a fully functioning Binary Code Editor for Mapinfo. (In case someone else needs that kind of functioning for MI, just let me know and I will pass it to Bill Thoen) I added a bit of code so you get the idea, even though it operates with values smaller than 32768 so signed-unsigned conversion is not needed. (It is a tool to invert bilevel tiff images from within MI) Regards, Anssi ' ---------------------------------------------------------------------------- Include "mapbasic.def" Declare Sub Main Declare Sub Read_sub Global fname As String Sub Main Dim answer As Logical fname = FileOpenDlg("","","TIF","Invert Tiff Image") If fname = "" Then Exit Sub End If Call Read_sub End Sub ' ---------------------------------------------------------------------------- Sub Read_sub Dim a, b, nro As SmallInt Dim header, counter, ifd_offset, value_offset, invert, c, d As Integer Open File fname For Binary Access Read Write As #1 Get #1,,a Get #1,,b Get #1,,c ifd_offset = c + 1 If b <> 42 Then Note "Not a Tiff file" End Program Else Get #1, ifd_offset, nro End If counter = 1 Do While counter <= nro Get #1,,a Get #1,,b Get #1,,c Get #1,,d If a = 262 Then value_offset = ifd_offset + 12 * (counter -1) + 10 If d = 0 Then invert = 1 Put #1,value_offset, invert Close File #1 Note "Successfully inverted" Exit Sub ElseIf d = 1 Then invert = 0 Put #1,value_offset, invert Close File #1 Note "Successfully inverted" Exit Sub Else Note "Not a bilevel image" + Chr$(10) + "Cannot invert" Close File #1 Exit Sub End If value_offset = value_offset + 4 End If counter = counter + 1 Loop Close File #1 Note "Invalid Tiff file" End Sub ' ---------------------------------------------------------------------------- At 14:40 10.3.1999 +0100, you wrote: >Hi all, > >Is it possible to use binary data in MapBasic? >I'am trying to write a mapbasic application that can write (and read) >bitmaps (.BMP files) into an Oracle Database, but MapBasic does not have >appropriate datatypes for binding binary data (LONGROW in Oracle). > >According to the MapBasic User's Guide (appendix D) MapBasic supports a >various set of ODBC datatypes, but the user's guide does not explain >how. > >Does anyone know how to handle binary data in MapBasic? > >Thanks. > >Martin Vanmol >Cegeka Industrial Systems >[EMAIL PROTECTED] > > > > > > >---------------------------------------------------------------------- >To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put >"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED] > ---------------------------------------------------------------------- To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED] ************************************************************************************************************* Hello all, I have a problem which involves converting ASCII values into binary values in mapinfo and as I can't see the way ahead I thought I would page the mapinfo oracle! I have a column of numbers (imported from a txt file) in which one column has binary information encoded in the ASCII characters. ie ASCII value = 15 = binary 111100. ASCII value = 63 = binary 111111 ASCII value = 1 = binary 100000 I need to create 6 new columns and place bit 0 into column 1, bit 1 into column 2 etc Can anyone suggest how this can be done? I don't have mapbasic but if its the only way to do this I might have to splash out! TIA, Jim Jim Wilson, Hilton of Fern, By Brechin, Angus, Scotland ************************************************************************************************************* Special thanks to Jacques Paris for pointing me to the wonderful code that Dmitry Bogdanov shared with the list back in March '98. I should have saved this one! Here's the code for the function to call or include in your program: Steve Wallace Florida Farm Bureau Insurance Companies -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Function GetRasterInfo(ByVal FileName$ As String, Width As Integer, Height As Integer ) As Logical Dim Pos, RasterType As SmallInt, FileExt$ As String Dim siWidth, siHeight, Xmin, Xmax, Ymin, Ymax, Val, NumTags, i As SmallInt Dim Offset As Integer, iByteOrder As SmallInt RasterType = 0 FileExt$ = "" For Pos = Len(FileName$) To 1 Step -1 If Mid$(FileName$, Pos, 1) = "." Then FileExt$ = Right$(FileName$, Len(FileName$) - Pos) End If Next Do Case UCase$(FileExt$) Case "BMP", "" RasterType = R_BMP Case "GIF" RasterType = R_GIF Case "PCX" RasterType = R_PCX Case "TIF" RasterType = R_TIF Case "TGA" RasterType = R_TGA Case "JPG" RasterType = R_JPEG End Case Do Case RasterType Case 0 GetRasterInfo = FALSE Exit Function Case R_TGA Open File FileName$ For Binary Access Read As #1 Get #1, 13, siWidth Get #1, 15, siHeight Width = siWidth Height = siHeight Case R_GIF Open File FileName$ For Binary Access Read As #1 Get #1, 7, siWidth Get #1, 9, siHeight Width = siWidth Height = siHeight Case R_BMP Open File FileName$ For Binary Access Read As #1 Get #1, 19, Width Get #1, 23, Height Case R_PCX Open File FileName$ For Binary Access Read As #1 Get #1, 5, Xmin Get #1, 7, Ymin Get #1, 9, Xmax Get #1, 11, Ymax Width = Xmax - Xmin + 1 Height = Ymax - Ymin + 1 Case R_TIF Open File FileName$ For Binary Access Read As #1 Get #1, 1, iByteOrder If iByteOrder = 19789 Then ' MM Close File #1 Open File FileName$ For Binary Access Read As #1 ByteOrder HIGHLOW End If Get #1, 5, Offset Offset = Offset + 1 Get #1, Offset, NumTags For i = 0 To NumTags - 1 Get #1, 2 + Offset + i * 12, Val Do Case Val Case 256 Get #1, 10 + Offset + i * 12, siWidth Case 257 Get #1, 10 + Offset + i * 12, siHeight Exit For End Case Next Width = siWidth Height = siHeight Case R_JPEG Open File FileName$ For Binary Access Read As #1 ByteOrder HIGHLOW Offset = 21 Do Get #1, Offset, Val If Val = -64 Then Exit Do End If Get #1, Offset + 2, Val Offset = Offset + Val + 2 Loop While TRUE Get #1, Offset + 5, siHeight Get #1, Offset + 7, siWidth Width = siWidth Height = siHeight End Case Close File #1 GetRasterInfo = TRUE End Function ************************************************************************************************************* Try the following in the mapbasic window or a workspace: ------------ Update Test Set Bit6=Fix(ASCII/32) Update Test Set Bit5=Fix((ASCII - 32*Bit6)/16) Update Test Set Bit4=Fix((ASCII - 32*Bit6 - 16*Bit5)/8) Update Test Set Bit3=Fix((ASCII - 32*Bit6 - 16*Bit5 - 8*Bit4)/4) Update Test Set Bit2=Fix((ASCII - 32*Bit6 - 16*Bit5 - 8*Bit4 - 4*Bit3)/2) Update Test Set Bit1=Fix((ASCII - 32*Bit6 - 16*Bit5 - 8*Bit4 - 4*Bit3 - 2*Bit2)) ------------ where "Test" is the name of the table with the following column structure: ASCII - SmallInt Bit1 - SmallInt Bit2 - SmallInt Bit3 - SmallInt Bit4 - SmallInt Bit5 - SmallInt Bit6 - SmallInt Hope this helps. Peter. --------------------------------------------- Hello all, I have a problem which involves converting ASCII values into binary values in mapinfo and as I can't see the way ahead I thought I would page the mapinfo oracle! I have a column of numbers (imported from a txt file) in which one column has binary information encoded in the ASCII characters. ie ASCII value = 15 = binary 111100. ASCII value = 63 = binary 111111 ASCII value = 1 �= binary 100000 I need to create 6 new columns and place bit 0 into column 1, bit 1 into column 2 etc Can anyone suggest how this can be done? I don't have mapbasic but if its the only way to do this I might have to splash out! TIA, Jim Jim Wilson, Hilton of Fern, By Brechin, Angus, Scotland ************************************************************************************************************* First open MapBasic window in MI :) Then folow steps described below: 1. Append 6 field for BIT values, type number. By using Update fill all new columnes with 0. For exmples name of the fields B1,B2,B3,B4,B5,B6 Update YOU_TABLE Set B1=0,B2=0,B3=0,B4=0,B5=0,B6=0 2. Append temporary column by using table\upadte column. Value asc(CHARFIELDNAME). Where CHARFIELDNAME name of field with ASCII values. 3. In MapBasic window: 4. Select * from YOU_TABLE into temp where (NFIELDNAME-32)>=0 Where NFIELDNAME name of temporary filed created in step 2. In this step found values where bit 6 is 1. 2^(6-1)=32 Update TEMP Set B6 = 1 Update TEMP Set NFIELDNAME =NFIELDNAME - 32 5. Select * from YOU_TABLE into temp where (NFIELDNAME-16)>=0 Update TEMP Set B5 = 1 Update TEMP Set NFIELDNAME =NFIELDNAME - 16 6. Select * from YOU_TABLE into temp where (NFIELDNAME-8)>=0 Update TEMP Set B4 = 1 Update TEMP Set NFIELDNAME =NFIELDNAME - 8 7.Select * from YOU_TABLE into temp where (NFIELDNAME-4)>=0 Update TEMP Set B3 = 1 Update TEMP Set NFIELDNAME =NFIELDNAME - 4 8. Select * from YOU_TABLE into temp where (NFIELDNAME-2)>=0 Update TEMP Set B2 = 1 Update TEMP Set NFIELDNAME =NFIELDNAME - 2 9. Select * from YOU_TABLE into temp where (NFIELDNAME)>0 Update TEMP Set B1 = 1 P.S. Mi english is too bad to explain the program. Just try it, it must work. Michel Cherepahin SurgutNIPIneft,Surgut,Russia Mail-to: [EMAIL PROTECTED] > ---------- > ??: Jim Wilson[SMTP:[EMAIL PROTECTED]] > ??????????: 8 ???????? 1998 ?. 13:40 > ????: [EMAIL PROTECTED] > ????: MI Binary to ASCII in Mapinfo. > > Hello all, > > I have a problem which involves converting ASCII values into binary values > in mapinfo and as I can't see the way ahead I thought I would page the > mapinfo oracle! > > I have a column of numbers (imported from a txt file) in which one column > has binary information encoded in the ASCII characters. > > ie ASCII value = 15 = binary 111100. > ASCII value = 63 = binary 111111 > ASCII value = 1 = binary 100000 > > I need to create 6 new columns and place bit 0 into column 1, bit 1 into > column 2 etc > Can anyone suggest how this can be done? I don't have mapbasic but if its > the only way to do this I might have to splash out! > > TIA, > Jim > Jim Wilson, > Hilton of Fern, > By Brechin, > Angus, > Scotland > ************************************************************************************************************* You might be able to use the unix command dd with the argument conv=swab to byte-swap the file before copying to NT - it used to work with Landsat data off reel to reel tapes read by HP-UX about ten years ago! --------------------------------------------- David Booth Senior GIS Officer Merseyside Information Service > -----Original Message----- > From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]] > Sent: 13 September 2000 19:26 > To: [EMAIL PROTECTED] > Subject: MI MB reading binary data > > Mappers, > Using mb code, under NT, I'm trying to read binary data that was created > on a UNIX machine which writes the data most significant byte first. My > mb code wants to read binary data as least significant byte first. Anyone > know how to work around this short of writing a byte exchanger? Does > MapBasic have a patch or something available? > Thanks, > SI ************************************************************************************************************* In MB, when you read/write a input file, you can specify the byteorder by saying high or low. THis way you can control the oder of bytes while reading. -- Rajeev Saraf [EMAIL PROTECTED] wrote: > Mappers, > Using mb code, under NT, I'm trying to read binary data that was created on a UNIX machine which writes the data most significant byte first. My mb code wants to read binary data as least significant byte first. Anyone know how to work around this short of writing a byte exchanger? Does MapBasic have a patch or something available? > Thanks, > SI ************************************************************************************************************* > Anyone know how to import an arc/info grid file in e00 format into MI? I > know arclink translates e00files, but it doesn't seem to understand e00 grid > files. Alternatively, anyone know where the format might be documented? The Arc/Info grid file format is a proprietary binary format. You can import from and export to the following generic grid formats (and thence into Vertical Mapper for example) using either Arc/Info or ArcView Spatial Analyst. >From the documentation: Binary: The binary raster file format is a simple format that can be used to transfer raster data between various applications. It consists of two files, the IEEE floating-point file and a supporting ASCII header file. The header file must have the same name as the data file, but with a .hdr file extension. The header data includes the following keywords and values: ncols - number of columns in the data set. nrows - number of rows in the data set. xllcenter or xllcorner - x-coordinate of the center or lower-left corner of the lower-left cell. yllcenter or yllcorner - y-coordinate of the center or lower-left corner of the lower-left cell. cellsize - cell size for the data set. nodata_value - value in the file assigned to cells whose value in unknown. This keyword and value is optional. The nodata_value defaults to -9999. byteorder - the byte order of the binary cell values. You can choose between two keywords, msbfirst or lsbfirst. Msbfirst is used for cell values written with the most significant bit first. Lsbfirst is used for cell values written with the least significant bit first. For example, ncols 480 nrows 450 xllcorner 378923 yllcorner 4072345 cellsize 30 nodata_value -32768 byteorder msbfirst The data file will be a matrix of 32 bit signed IEEE floating-point values. The file will have a line of binary numbers for each row in the data set. The first line of data is the top row of the data set, moving from left to right. ASCII: The ASCII raster file format is a simple format that can be used to transfer raster data between various applications. It is basically a few lines of header data followed by lists of cell values. The header data includes the following keywords and values: ncols - number of columns in the data set. nrows - number of rows in the data set. xllcenter or xllcorner - x-coordinate of the center or lower-left corner of the lower-left cell. yllcenter or yllcorner - y-coordinate of the center or lower-left corner of the lower-left cell. cellsize - cell size for the data set. nodata_value - value in the file assigned to cells whose value is unknown. This keyword and value is optional. The nodata_value defaults to -9999. For example, ncols 480 nrows 450 xllcorner 378923 yllcorner 4072345 cellsize 30 nodata_value -32768 43 3 45 7 3 56 2 5 23 65 34 6 32 etc 35 45 65 34 2 6 78 4 38 44 89 3 2 7 etc etc The first row of data is at the top of the data set, moving from left to right. Cell values should be delimited by spaces. No carriage returns are necessary at the end of each row in the data set. The number of columns in the header is used to determine when a new row begins. The number of cell values must be equal to the number of rows times the number of columns. -------------------------------------------- Justin Hyland, Ph.D. ComputaMaps, PO Box 13190, Mowbray, 7705 Cape Town, South Africa tel: 27-021-423 1609, fax: 27-021-423 1603, cell: 083-763-8029 e-mail: [EMAIL PROTECTED] URL: http://maps.co.za -------------------------------------------- ************************************************************************************************************* Regards/Venlig hilsen, Jakob Lanstorp, GIS-Developer Kampsax GIS Software & Solutions, Rugaardsvej 55, 5000 Odense, DK tel: + 45 63 13 50 13, dir: + 45 63 13 50 11, fax: + 45 63 13 50 90 mailto:[EMAIL PROTECTED] , http://www.mapinfo.dk, http://www.kampsax.dk Authorized MapInfo Partner & Distributor in Denmark and Norway ---- "Steve" <[EMAIL PROTECTED]> Til: <[EMAIL PROTECTED]> Sendt af: cc: [EMAIL PROTECTED] Vedr.: MI-L Reading Binary files/Grid Interpolation files onsmag.com 17-09-01 13:11 Besvar venligst til "Steve" Hi all, Has anyone had experience reading in binary files into a MapBasic = application? What I want to do is read in a grid transformation file = into an MBX. I've managed to convert one grid transformation file into a = mapInfo table and use fetch statements extract node values, but it would be more practical to extract these values directly = from the original binary file. Thanks Steve _______________________________________________________________________ List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, send e-mail to [EMAIL PROTECTED] and put "unsubscribe MapInfo-L" in the message body. _______________________________________________________________________ List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, send e-mail to [EMAIL PROTECTED] and put "unsubscribe MapInfo-L" in the message body.
