views:

40

answers:

1

I am trying to read a binary file and parse the bytes I have the white paper spec on Shapefiles to know how to parse the file, however I cannot seem to find the correct functions in ColdFusion to handle reading bytes and deciding what to do with them.

<cffile action="READBINARY"
   file="mypath/www/_Dev/tl_2009_25_place.shp"   
   variable="infile" >

PDF file with spec:http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

For example I have the spec:

Position Field Value Type Order
Byte 0 File Code 9994 Integer Big
Byte 4 Unused 0 Integer Big
Byte 8 Unused 0 Integer Big
Byte 12 Unused 0 Integer Big
Byte 16 Unused 0 Integer Big
Byte 20 Unused 0 Integer Big
Byte 24 File Length File Length Integer Big
Byte 28 Version 1000 Integer Little
Byte 32 Shape Type Shape Type Integer Little
Byte 36 Bounding Box Xmin Double Little
Byte 44 Bounding Box Ymin Double Little
Byte 52 Bounding Box Xmax Double Little
Byte 60 Bounding Box Ymax Double Little
Byte 68* Bounding Box Zmin Double Little
Byte 76* Bounding Box Zmax Double Little
Byte 84* Bounding Box Mmin Double Little
Byte 92* Bounding Box Mmax Double Little

If this was just a flat text file i would use mid function to read my positions. Can this be done in ColdFusion and Which functions can achieve my goal?

I found this function inside of FarStream.as found at http://code.google.com/p/vanrijkom-flashlibs/wiki/SHP which is an Actionscript3 file, but it represents the kind of task i need to do.

private function readHeader(e: ProgressEvent): void {
    // check header:
    if  (!  (   readByte()==0x46
            &&  readByte()==0x41
            &&  readByte()==0x52
            ))  
    {
        dispatchEvent(new IOErrorEvent
            ( IOErrorEvent.IO_ERROR
            , false,false
            , "File is not FAR formatted")
        );
        close();
        return;
    }
    // version:
    vMajor = readByte();
    vMinor = readByte();
    if (vMajor>VMAJOR) {
        dispatchEvent(new IOErrorEvent
            ( IOErrorEvent.IO_ERROR
            , false,false
            , "Unsupported archive version  (v."+vMajor+"."+vMinor+")")                 
        );
        close();
        return;
    }                   
    // table size:
    tableSize = readUnsignedInt();      
    // done processing header:          
    gotHeader= true;
}

And here is the final solution

<cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile").init('/www/_Dev/tl_2009_25_place.shp')>
<cfdump var="#shapeFile.getFileLength()#"> 
+4  A: 
<cffile action="READBINARY" file="mypath/www/_Dev/tl_2009_25_place.shp" variable="infile" >
<cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile").init(infile)>
<cfdump var="#shapeFile#">

Maybe something like this?

Henry
Thanks, I do not know how to install this on BlueDragon. I am getting Failed to load class, com.bbn.openmap.layer.shape.ShapeFile
cfEngineers
You'll have to download the Jar file and put it in the classpath.
Henry
http://openmap.bbn.com/
Henry
OK its installed but its on a shared server, is there a way to get around the classpath?
cfEngineers
Take a look at JavaLoader project http://www.compoundtheory.com/?action=javaloader.index
Sergii
Is this the file i should be putting on my server openmap.jar ?
cfEngineers
Yes, I think so.
Henry
Thanks for all your help, I am trying it now.
cfEngineers
A matching constructor could not be reliably determined. If possible, use 'javacast()' with the provided arguments to resolve this ambiguity
cfEngineers
OK Here it is and thank everyone for your help <cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile").init('/www/_Dev/tl_2009_25_place.shp')><cfdump var="#shapeFile.getFileLength()#">
cfEngineers