我正在尝试将 processing.org 应用程序移植到 python 并遇到一些困难。
我需要用python写这个:
int[][] elevation; // elevations in meters
float[][] felevation; // scaled to range [0,1] where 1=max
int maxheight;
void setup(){
size(600,600,P2D);
// read srtm binary file
elevation=new int[1201][1201];
felevation=new float[1201][1201];
byte b[] = loadBytes("N30W091.hgt"); // THIS IS A BINARY FILE
int ix=0;
maxheight=0;
for (int row=0;row<1201;row++) {
for (int col=0;col<1201;col++) {
// bytes are signed, from -128 to 127, converts to unsigned...
int hi = b[ix] & 0xff;
int lo = b[ix+1] & 0xff;
int el=(int)((hi<<8)|lo); // big endian!
elevation[row][col]=el;
if (el>maxheight && el<32000) maxheight=el;
ix+=2;
}
}
... 等等
到目前为止我所做的是:
elevation = [[],[]]
maxheight=0
b = open("C:\\Users\\CNA\\sketchbook\\_SRTM\\data\\N59E010.hgt","rb")
fin = b.read(1)
print(len(fin))
ix = 0
for row in range(0,1201):
for col in range(0,1201):
hi = (fin[ix] + 0xff)
lo = (fin[ix+1] + 0xff)
我总是得到
Traceback (most recent call last):
File "C:\Users\CNA\workspace\Revitter\PatternAsignment.py", line 16, in <module>
TypeError: unsupported operand type(s) for +: 'str' and 'int'
有任何想法吗?..我是python新手,我没有使用字节的经验...