Show
Ignore:
Timestamp:
11/27/07 20:09:45 (12 months ago)
Author:
gyuque
Message:

lang/ruby/RubyESRIShape: polyline support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/RubyESRIShape/IndexedPointList.cpp

    r2054 r2062  
    5757        mMRange[1] = aSrc.mMRange[1]; 
    5858} 
     59 
     60es_error_t IndexedPointList::readFromMainFile(FILE* fp, ShpReadContext& rctx, int option) 
     61{ 
     62        es_error_t rv = ESHP_OK; 
     63 
     64        mBounds[0] = Shape::freadLittleDouble(fp); 
     65        mBounds[1] = Shape::freadLittleDouble(fp); 
     66        mBounds[2] = Shape::freadLittleDouble(fp); 
     67        mBounds[3] = Shape::freadLittleDouble(fp); 
     68        rctx.readSize              += 32; 
     69        rctx.readRecordContentSize += 32; 
     70 
     71        mNParts  = Shape::freadLittle32(fp); 
     72        mNPoints = Shape::freadLittle32(fp); 
     73        rctx.readSize              += 8; 
     74        rctx.readRecordContentSize += 8; 
     75 
     76        allocBuffers(); 
     77 
     78        ESInt32 i; 
     79        for (i = 0;i < mNParts;i++) 
     80        { 
     81                mPartIndexes[i] = Shape::freadLittle32(fp); 
     82                rctx.readSize              += 4; 
     83                rctx.readRecordContentSize += 4; 
     84        } 
     85 
     86        for (i = 0;i < mNPoints;i++) 
     87        { 
     88                mPoints[i].x = Shape::freadLittleDouble(fp); 
     89                mPoints[i].y = Shape::freadLittleDouble(fp); 
     90                rctx.readSize              += 16; 
     91                rctx.readRecordContentSize += 16; 
     92        } 
     93 
     94        if (option & SHPRECORD_WITH_Z) 
     95        { 
     96                // Z 
     97                mZRange[0] = Shape::freadLittleDouble(fp); 
     98                mZRange[1] = Shape::freadLittleDouble(fp); 
     99                rctx.readSize              += 16; 
     100                rctx.readRecordContentSize += 16; 
     101 
     102                for (i = 0;i < mNPoints;i++) 
     103                { 
     104                        mPoints[i].z = Shape::freadLittleDouble(fp); 
     105                        rctx.readSize              += 8; 
     106                        rctx.readRecordContentSize += 8; 
     107                } 
     108 
     109                // Measure 
     110                mMRange[0] = Shape::freadLittleDouble(fp); 
     111                mMRange[1] = Shape::freadLittleDouble(fp); 
     112                rctx.readSize              += 16; 
     113                rctx.readRecordContentSize += 16; 
     114 
     115                for (i = 0;i < mNPoints;i++) 
     116                { 
     117                        mPoints[i].m = Shape::freadLittleDouble(fp); 
     118                        rctx.readSize              += 8; 
     119                        rctx.readRecordContentSize += 8; 
     120                } 
     121        } 
     122 
     123        return rv; 
     124} 
     125 
     126VALUE IndexedPointList::getPartAsRubyObj(int index) 
     127{ 
     128        if (index < 0 || index >= mNParts) 
     129                return Qnil; 
     130 
     131        int len = (index == (mNParts-1)) ? mNPoints : mPartIndexes[index+1]; 
     132        len -= mPartIndexes[index]; 
     133 
     134        int start = mPartIndexes[index]; 
     135 
     136        VALUE arr = rb_ary_new2(len); 
     137        for (int i = 0;i < len;i++) 
     138        { 
     139                ESPointEx& p = mPoints[start+i]; 
     140                ShpPoint* shp = new ShpPoint(p.x, p.y, p.z, p.m); 
     141                rb_ary_push(arr, shp->toRubyObject()); 
     142        } 
     143 
     144        return arr; 
     145}