开发者

Reading a Shapefile with ColdFusion

开发者 https://www.devze.com 2023-01-16 13:06 出处:网络
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 hand

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/whitepa开发者_Go百科pers/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()#"> 


<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?

0

精彩评论

暂无评论...
验证码 换一张
取 消