我正在尝试读取二进制文件并解析字节我有关于 Shapefiles 的白皮书规范以了解如何解析文件,但是我似乎无法在 ColdFusion 中找到正确的函数来处理读取字节并决定如何处理它们.
<cffile action="READBINARY"
file="mypath/www/_Dev/tl_2009_25_place.shp"
variable="infile" >
带有规范的 PDF 文件:http: //www.esri.com/library/whitepapers/pdfs/shapefile.pdf
例如我有规范:
位置 字段 值 类型 订单
字节 0 文件代码 9994 整数大
字节 4 未使用 0 整数大
字节 8 未使用 0 整数大
字节 12 未使用 0 整数大
字节 16 未使用 0 整数大
字节 20 未使用 0 整数大
字节 24 文件长度 文件长度 整数大
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
字节 92* 边界框 Mmax Double Little
如果这只是一个平面文本文件,我会使用 mid 函数来读取我的位置。这可以在 ColdFusion 中完成吗?哪些功能可以实现我的目标?
我在 FarStream.as 中找到了这个函数,在http://code.google.com/p/vanrijkom-flashlibs/wiki/SHP这是一个 Actionscript3 文件,但它代表了我需要做的那种任务。
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;
}
这是最终的解决方案
<cfset shapeFile = createObject("java","com.bbn.openmap.layer.shape.ShapeFile").init('/www/_Dev/tl_2009_25_place.shp')>
<cfdump var="#shapeFile.getFileLength()#">