Changeset 1205

Show
Ignore:
Timestamp:
07/03/09 09:29:50 (14 months ago)
Author:
artem
Message:

+ move byte order depended I/O to global.hpp

this should fix shape.input PPC issues

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/mapnik/global.hpp

    r805 r1205  
    2626#define GLOBAL_HPP 
    2727 
     28// boost 
    2829#include <boost/cstdint.hpp> 
    29  
     30#include <boost/detail/endian.hpp> 
     31// stl 
     32#include <cstring> 
    3033 
    3134namespace mapnik 
     
    3538                               (((boost::uint16_t) ((boost::uint8_t) (A)[0])) << 8)) 
    3639 
    37 #define int4net(A)  (int32_t) (((boost::uint32_t) ((boost::uint8_t) (A)[3]))      | \ 
     40#define int4net(A)  (int32_t)  (((boost::uint32_t) ((boost::uint8_t) (A)[3]))        | \ 
    3841                               (((boost::uint32_t) ((boost::uint8_t) (A)[2])) << 8)  | \ 
    3942                               (((boost::uint32_t) ((boost::uint8_t) (A)[1])) << 16) | \ 
     
    5861    ((byte*) &def_temp)[3]=(M)[0];              \ 
    5962    (V)=def_temp; } while(0) 
     63 
     64     
     65    // read int NDR (little endian) 
     66    inline int& read_int_ndr(const char* data, int & val) 
     67    { 
     68#ifndef BOOST_BIG_ENDIAN 
     69        memcpy(&val,data,4); 
     70#else 
     71        val = (data[3]&0xff)     |  
     72            ((data[2]&0xff)<<8)  |  
     73            ((data[1]&0xff)<<16) |  
     74            ((data[0]&0xff)<<24); 
     75#endif 
     76        return val; 
     77    } 
     78     
     79    // read double NDR (little endian) 
     80    inline double& read_double_ndr(const char* data, double & val) 
     81    { 
     82#ifndef BOOST_BIG_ENDIAN 
     83        std::memcpy(&val,&data[0],8); 
     84#else 
     85        boost::int64_t bits = ((boost::int64_t)data[0] & 0xff) |  
     86            ((boost::int64_t)data[1] & 0xff) << 8   | 
     87            ((boost::int64_t)data[2] & 0xff) << 16  | 
     88            ((boost::int64_t)data[3] & 0xff) << 24  | 
     89            ((boost::int64_t)data[4] & 0xff) << 32  | 
     90            ((boost::int64_t)data[5] & 0xff) << 40  | 
     91            ((boost::int64_t)data[6] & 0xff) << 48  | 
     92            ((boost::int64_t)data[7] & 0xff) << 56  ; 
     93        std::memcpy(&val,&bits,8); 
     94#endif 
     95        return val; 
     96    }  
     97     
     98    // read int XDR (big endian) 
     99    inline int& read_int_xdr(const char* data, int & val) 
     100    { 
     101#ifndef BOOST_BIG_ENDIAN 
     102        val = (data[3]&0xff) | ((data[2]&0xff)<<8) | ((data[1]&0xff)<<16) | ((data[0]&0xff)<<24); 
     103#else 
     104        memcpy(&val,data,4); 
     105#endif 
     106        return val; 
     107    } 
     108     
     109    // read double XDR (big endian) 
     110    inline double& read_double_xdr(const char* data, double & val) 
     111    { 
     112#ifndef BOOST_BIG_ENDIAN 
     113        boost::int64_t bits = ((boost::int64_t)data[0] & 0xff) |  
     114            ((boost::int64_t)data[1] & 0xff) << 8   | 
     115            ((boost::int64_t)data[2] & 0xff) << 16  | 
     116            ((boost::int64_t)data[3] & 0xff) << 24  | 
     117            ((boost::int64_t)data[4] & 0xff) << 32  | 
     118            ((boost::int64_t)data[5] & 0xff) << 40  | 
     119            ((boost::int64_t)data[6] & 0xff) << 48  | 
     120            ((boost::int64_t)data[7] & 0xff) << 56  ; 
     121        std::memcpy(&val,&bits,8); 
     122#else 
     123        std::memcpy(&val,&data[0],8); 
     124#endif 
     125        return val; 
     126    } 
    60127} 
    61128 
  • trunk/plugins/input/shape/shapefile.hpp

    r1171 r1205  
    2626#define SHAPEFILE_HPP 
    2727 
     28#include <mapnik/global.hpp> 
    2829#include <mapnik/envelope.hpp> 
    2930// boost 
    3031#include <boost/utility.hpp> 
    31 #include <boost/detail/endian.hpp> 
     32#include <boost/cstdint.hpp> 
    3233#include <boost/iostreams/stream.hpp> 
     34 
    3335#include <boost/iostreams/device/file.hpp> 
    3436#include <boost/iostreams/device/mapped_file.hpp> 
     37//#include <boost/iostreams/device/file_descriptor.hpp> 
    3538 
    3639#include <cstring> 
    3740 
    3841using mapnik::Envelope; 
     42using mapnik::read_int_ndr; 
     43using mapnik::read_int_xdr; 
     44using mapnik::read_double_ndr; 
     45using mapnik::read_double_xdr; 
    3946 
    4047struct shape_record 
    4148{ 
    42       const char* data; 
    43       size_t size; 
    44       mutable size_t pos; 
    45       explicit shape_record(size_t size) 
    46          : size(size), 
    47            pos(0) {}  
     49    const char* data; 
     50    size_t size; 
     51    mutable size_t pos; 
     52    explicit shape_record(size_t size) 
     53        : //data(static_cast<char*>(::operator new(sizeof(char)*size))), 
     54        size(size), 
     55        pos(0) {}  
    4856       
    49       void set_data(const char * data_) 
    50       { 
    51          data = data_; 
    52       } 
     57    void set_data(const char * data_) 
     58    { 
     59        data = data_; 
     60    } 
     61   
     62    void skip(unsigned n) 
     63    { 
     64        pos+=n; 
     65    } 
    5366       
    54       void skip(unsigned n) 
    55       { 
    56          pos+=n; 
    57       } 
     67    int read_ndr_integer() 
     68    { 
     69        int val; 
     70        read_int_ndr(&data[pos],val); 
     71        pos+=4; 
     72        return val; 
     73    } 
    5874       
    59       int read_ndr_integer() 
    60       { 
    61          int val=(data[pos] & 0xff)     |  
    62             (data[pos+1] & 0xff) << 8  | 
    63             (data[pos+2] & 0xff) << 16 | 
    64             (data[pos+3] & 0xff) << 24; 
    65          pos+=4; 
    66          return val; 
    67       } 
     75    int read_xdr_integer() 
     76    { 
     77        int val; 
     78        read_int_xdr(&data[pos],val); 
     79        pos+=4; 
     80        return val; 
     81    } 
    6882       
    69       int read_xdr_integer() 
    70       { 
    71          int val=(data[pos] & 0xff) << 24 |  
    72             (data[pos+1] & 0xff)   << 16   | 
    73             (data[pos+2] & 0xff)   << 8    | 
    74             (data[pos+3] & 0xff); 
    75          pos+=4; 
    76          return val; 
    77       } 
    78        
    79       double read_double() 
    80       { 
    81          double val;             
    82 #ifndef BOOST_BIG_ENDIAN 
    83          std::memcpy(&val,&data[pos],8);         
    84 #else 
    85          long long bits = ((long long)data[pos] & 0xff) |  
    86             ((long long)data[pos+1] & 0xff) << 8   | 
    87             ((long long)data[pos+2] & 0xff) << 16  | 
    88             ((long long)data[pos+3] & 0xff) << 24  | 
    89             ((long long)data[pos+4] & 0xff) << 32  | 
    90             ((long long)data[pos+5] & 0xff) << 40  | 
    91             ((long long)data[pos+6] & 0xff) << 48  | 
    92             ((long long)data[pos+7] & 0xff) << 56  ; 
    93          std::memcpy(&val,&bits,8); 
    94 #endif  
    95          pos+=8; 
    96          return val; 
    97       } 
    98       long remains()  
    99       { 
    100          return (size-pos); 
    101       } 
    102       ~shape_record() {} 
     83    double read_double() 
     84    { 
     85        double val;              
     86        read_double_ndr(&data[pos],val); 
     87        pos+=8; 
     88        return val; 
     89    } 
     90    long remains()  
     91    { 
     92        return (size-pos); 
     93    } 
     94   
     95    ~shape_record()  
     96    { 
     97        //::operator delete(data); 
     98    } 
    10399  
    104100}; 
     
    108104class shape_file : boost::noncopyable 
    109105 
    110       stream<mapped_file_source> file_; 
    111    public: 
    112       shape_file(); 
    113       shape_file(const std::string& file_name); 
    114       ~shape_file(); 
    115       bool is_open(); 
    116       void close(); 
     106    stream<mapped_file_source> file_; 
     107    //stream<file_source> file_; 
     108public: 
     109    shape_file(); 
     110    shape_file(std::string const& file_name); 
     111    ~shape_file(); 
     112    bool is_open(); 
     113    void close(); 
    117114       
    118       inline void read_record(shape_record& rec) 
    119       { 
    120          rec.set_data(file_->data() + file_.tellg()); 
    121          file_.seekg(rec.size,std::ios::cur); 
    122       } 
     115    inline void read_record(shape_record& rec) 
     116    { 
     117        rec.set_data(file_->data() + file_.tellg()); 
     118        file_.seekg(rec.size,std::ios::cur); 
     119    } 
     120     
     121    inline int read_xdr_integer() 
     122    { 
     123        char b[4]; 
     124        file_.read(b, 4); 
     125        int val; 
     126        read_int_xdr(b,val); 
     127        return val; 
     128    } 
    123129       
    124       inline int read_xdr_integer() 
    125       { 
    126          char b[4]; 
    127          file_.read(b, 4); 
    128          return (b[3] & 0xffu) | ((b[2] & 0xffu) << 8) | 
    129             ((b[1] & 0xffu) << 16) | ((b[0] & 0xffu) << 24); 
    130       } 
     130    inline int read_ndr_integer() 
     131    { 
     132        char b[4]; 
     133        file_.read(b,4); 
     134        int val; 
     135        read_int_ndr(b,val); 
     136        return val; 
     137    } 
    131138       
    132       inline int read_ndr_integer() 
    133       { 
    134          char b[4]; 
    135          file_.read(b,4); 
    136          return (b[0]&0xffu) | ((b[1]&0xffu) << 8) |  
    137             ((b[2]&0xffu) << 16) | ((b[3]&0xffu) << 24); 
    138       } 
     139    inline double read_double() 
     140    { 
     141        double val; 
     142#ifndef WORDS_BIGENDIAN 
     143        file_.read(reinterpret_cast<char*>(&val),8); 
     144#else 
     145        char b[8]; 
     146        file_.read(b,8); 
     147        read_double_ndr(b,val); 
     148#endif 
     149        return val; 
     150    } 
     151     
     152    inline void read_envelope(Envelope<double>& envelope) 
     153    { 
     154#ifndef WORDS_BIGENDIAN 
     155        file_.read(reinterpret_cast<char*>(&envelope),sizeof(envelope)); 
     156#else 
     157        char data[4*8]; 
     158        file_.read(data,4*8); 
     159        double minx,miny,maxx,maxy; 
     160        read_double_ndr(data,minx); 
     161        read_double_ndr(data,miny); 
     162        read_double_ndr(data,maxx); 
     163        read_double_ndr(data,maxy); 
     164        envelope.init(minx,miny,maxx,maxy); 
     165#endif   
     166    } 
    139167       
    140       inline double read_double() 
    141       { 
    142          double val; 
    143 #ifndef WORDS_BIGENDIAN 
    144          file_.read(reinterpret_cast<char*>(&val),8); 
    145 #else 
    146          char b[8]; 
    147          file_.read(b,8); 
    148          long long bits = ((long long)b[0] & 0xff) |  
    149             ((long long)b[1] & 0xff) << 8   | 
    150             ((long long)b[2] & 0xff) << 16  | 
    151             ((long long)b[3] & 0xff) << 24  | 
    152             ((long long)b[4] & 0xff) << 32  | 
    153             ((long long)b[5] & 0xff) << 40  | 
    154             ((long long)b[6] & 0xff) << 48  | 
    155             ((long long)b[7] & 0xff) << 56  ; 
    156          memcpy(&val,&bits,8); 
    157 #endif 
    158          return val; 
    159       } 
     168    inline void skip(std::streampos bytes) 
     169    { 
     170        file_.seekg(bytes,std::ios::cur); 
     171    } 
    160172       
    161       inline void read_envelope(Envelope<double>& envelope) 
    162       { 
    163 #ifndef WORDS_BIGENDIAN 
    164          file_.read(reinterpret_cast<char*>(&envelope),sizeof(envelope)); 
    165 #else 
    166          double minx=read_double(); 
    167          double miny=read_double(); 
    168          double maxx=read_double(); 
    169          double maxy=read_double(); 
    170          envelope.init(minx,miny,maxx,maxy); 
    171 #endif   
    172       } 
     173    inline void rewind() 
     174    { 
     175        seek(100); 
     176    } 
    173177       
    174       inline void skip(std::streampos bytes) 
    175       { 
    176          file_.seekg(bytes,std::ios::cur); 
    177       } 
     178    inline void seek(std::streampos pos) 
     179    { 
     180        file_.seekg(pos,std::ios::beg); 
     181    } 
    178182       
    179       inline void rewind() 
    180       { 
    181          seek(100); 
    182       } 
     183    inline std::streampos pos() 
     184    { 
     185        return file_.tellg(); 
     186    } 
    183187       
    184       inline void seek(std::streampos pos) 
    185       { 
    186          file_.seekg(pos,std::ios::beg); 
    187       } 
    188        
    189       inline std::streampos pos() 
    190       { 
    191          return file_.tellg(); 
    192       } 
    193        
    194       inline bool is_eof() 
    195       { 
    196          return file_.eof(); 
    197       } 
     188    inline bool is_eof() 
     189    { 
     190        return file_.eof(); 
     191    } 
    198192}; 
    199193 
  • trunk/src/wkb.cpp

    r1188 r1205  
    2323//$Id: wkb.cpp 19 2005-03-22 13:53:27Z pavlenko $ 
    2424 
     25#include <mapnik/global.hpp> 
    2526#include <mapnik/wkb.hpp> 
    2627#include <mapnik/geom_util.hpp> 
    2728#include <mapnik/feature.hpp> 
     29 
    2830// boost 
    29 #include <boost/cstdint.hpp> 
     31#include <boost/utility.hpp> 
    3032#include <boost/detail/endian.hpp> 
    3133 
    3234namespace mapnik 
    3335{ 
    34    struct wkb_reader 
    35    { 
    36       private: 
    37          enum wkbByteOrder { 
     36    struct wkb_reader : boost::noncopyable 
     37    { 
     38    private: 
     39        enum wkbByteOrder { 
    3840            wkbXDR=0, 
    3941            wkbNDR=1 
    40          }; 
    41          const char* wkb_; 
    42          unsigned size_; 
    43          unsigned pos_; 
    44          wkbByteOrder byteOrder_; 
    45          bool needSwap_; 
    46          wkbFormat format_; 
    47  
    48       public: 
    49          
    50          enum wkbGeometryType { 
     42        }; 
     43        const char* wkb_; 
     44        unsigned size_; 
     45        unsigned pos_; 
     46        wkbByteOrder byteOrder_; 
     47        bool needSwap_; 
     48        wkbFormat format_; 
     49 
     50    public: 
     51         
     52        enum wkbGeometryType { 
    5153            wkbPoint=1, 
    5254            wkbLineString=2, 
     
    5658            wkbMultiPolygon=6, 
    5759            wkbGeometryCollection=7 
    58          }; 
    59          
    60          wkb_reader(const char* wkb,unsigned size,wkbFormat format) 
     60        }; 
     61         
     62        wkb_reader(const char* wkb,unsigned size,wkbFormat format) 
    6163            : wkb_(wkb), 
    6264              size_(size), 
    6365              pos_(0), 
    6466              format_(format) 
    65          { 
     67        { 
    6668            switch (format_) 
    6769            { 
    68                case wkbSpatiaLite: 
    69                   byteOrder_ = (wkbByteOrder) wkb_[1]; 
    70                   pos_ = 39; 
    71                   break; 
    72  
    73                case wkbGeneric: 
    74                default: 
    75                   byteOrder_ = (wkbByteOrder) wkb_[0]; 
    76                   pos_ = 1; 
    77                   break; 
     70            case wkbSpatiaLite: 
     71                byteOrder_ = (wkbByteOrder) wkb_[1]; 
     72                pos_ = 39; 
     73                break; 
     74 
     75            case wkbGeneric: 
     76            default: 
     77                byteOrder_ = (wkbByteOrder) wkb_[0]; 
     78                pos_ = 1; 
     79                break; 
    7880            } 
    7981 
     
    8385            needSwap_=byteOrder_?wkbNDR:wkbXDR;  
    8486#endif       
    85          } 
    86  
    87          ~wkb_reader() {} 
    88  
    89          void read_multi(Feature & feature)  
    90          { 
     87        } 
     88 
     89        ~wkb_reader() {} 
     90 
     91        void read_multi(Feature & feature)  
     92        { 
    9193            int type=read_integer(); 
    9294            switch (type) 
    9395            { 
    94                case wkbPoint: 
    95                   read_point(feature); 
    96                   break; 
    97                case wkbLineString: 
    98                   read_linestring(feature); 
    99                   break; 
    100                case wkbPolygon: 
    101                   read_polygon(feature); 
    102                   break; 
    103                case wkbMultiPoint: 
    104                   read_multipoint(feature); 
    105                   break; 
    106                case wkbMultiLineString: 
    107                   read_multilinestring(feature); 
    108                   break; 
    109                case wkbMultiPolygon: 
    110                   read_multipolygon(feature); 
    111                   break; 
    112                case wkbGeometryCollection: 
    113                   break; 
    114                default: 
    115                   break; 
    116             } 
    117          } 
    118           
    119          void read(Feature & feature)  
    120          { 
     96            case wkbPoint: 
     97                read_point(feature); 
     98                break; 
     99            case wkbLineString: 
     100                read_linestring(feature); 
     101                break; 
     102            case wkbPolygon: 
     103                read_polygon(feature); 
     104                break; 
     105            case wkbMultiPoint: 
     106                read_multipoint(feature); 
     107                break; 
     108            case wkbMultiLineString: 
     109                read_multilinestring(feature); 
     110                break; 
     111            case wkbMultiPolygon: 
     112                read_multipolygon(feature); 
     113                break; 
     114            case wkbGeometryCollection: 
     115                break; 
     116            default: 
     117                break; 
     118            } 
     119        } 
     120          
     121        void read(Feature & feature)  
     122        { 
    121123            int type=read_integer(); 
    122124            switch (type) 
    123125            { 
    124                case wkbPoint: 
    125                   read_point(feature); 
    126                   break; 
    127                case wkbLineString: 
    128                   read_linestring(feature); 
    129                   break; 
    130                case wkbPolygon: 
    131                   read_polygon(feature); 
    132                   break; 
    133                case wkbMultiPoint: 
    134                   read_multipoint_2(feature); 
    135                   break; 
    136                case wkbMultiLineString: 
    137                   read_multilinestring_2(feature); 
    138                   break; 
    139                case wkbMultiPolygon: 
    140                   read_multipolygon_2(feature); 
    141                   break; 
    142                case wkbGeometryCollection: 
    143                   break; 
    144                default: 
    145                   break; 
    146             } 
    147          } 
     126            case wkbPoint: 
     127                read_point(feature); 
     128                break; 
     129            case wkbLineString: 
     130                read_linestring(feature); 
     131                break; 
     132            case wkbPolygon: 
     133                read_polygon(feature); 
     134                break; 
     135            case wkbMultiPoint: 
     136                read_multipoint_2(feature); 
     137                break; 
     138            case wkbMultiLineString: 
     139                read_multilinestring_2(feature); 
     140                break; 
     141            case wkbMultiPolygon: 
     142                read_multipolygon_2(feature); 
     143                break; 
     144            case wkbGeometryCollection: 
     145                break; 
     146            default: 
     147                break; 
     148            } 
     149        } 
    148150           
    149       private: 
    150          wkb_reader(const wkb_reader&); 
    151          wkb_reader& operator=(const wkb_reader&); 
    152          
    153          int read_integer()  
    154          { 
     151    private: 
     152         
     153        int read_integer()  
     154        { 
    155155            int n; 
    156  
    157             if (!needSwap_) 
    158             { 
    159                memcpy(&n,wkb_+pos_,4); 
     156            if (needSwap_) 
     157            { 
     158                read_int_xdr(wkb_+pos_,n); 
    160159            }  
    161160            else  
    162161            { 
    163                const char* b=wkb_+pos_; 
    164                n = (b[3]&0xff) | ((b[2]&0xff)<<8) | ((b[1]&0xff)<<16) | ((b[0]&0xff)<<24); 
     162                read_int_ndr(wkb_+pos_,n); 
    165163            } 
    166164            pos_+=4; 
    167  
     165             
    168166            return n; 
    169          } 
    170          
    171          double read_double() 
    172          { 
     167        } 
     168         
     169        double read_double() 
     170        { 
    173171            double d; 
    174  
    175             if (!needSwap_) 
    176             { 
    177                memcpy(&d,wkb_+pos_,8); 
     172            if (needSwap_) 
     173            { 
     174                read_double_xdr(wkb_ + pos_, d); 
    178175            } 
    179176            else  
    180177            { 
    181                const char* b= wkb_+pos_; 
    182                boost::int64_t n = ((boost::int64_t)b[7]&0xff) |  
    183                              (((boost::int64_t)b[6]&0xff)<<8) |  
    184                              (((boost::int64_t)b[5]&0xff)<<16) |  
    185                              (((boost::int64_t)b[4]&0xff)<<24) | 
    186                              (((boost::int64_t)b[3]&0xff)<<32) | 
    187                              (((boost::int64_t)b[2]&0xff)<<40) | 
    188                              (((boost::int64_t)b[1]&0xff)<<48) | 
    189                              (((boost::int64_t)b[0]&0xff)<<56); 
    190                memcpy(&d,&n,8); 
     178                read_double_ndr(wkb_ + pos_, d); 
    191179            } 
    192180            pos_+=8; 
    193  
     181             
    194182            return d; 
    195          } 
    196          
    197          void read_coords(CoordinateArray& ar) 
    198          { 
     183        } 
     184         
     185        void read_coords(CoordinateArray& ar) 
     186        { 
    199187            int size=sizeof(coord<double,2>)*ar.size(); 
    200188            if (!needSwap_) 
    201189            { 
    202                std::memcpy(&ar[0],wkb_+pos_,size); 
    203                  
     190                std::memcpy(&ar[0],wkb_+pos_,size); 
     191                pos_+=size; 
    204192            } 
    205193            else  
    206194            { 
    207                for (unsigned i=0;i<ar.size();++i) 
    208                { 
    209                   ar[i].x=read_double(); 
    210                   ar[i].y=read_double(); 
    211                } 
    212             } 
    213             pos_+=size; 
    214          } 
    215          
    216          void read_point(Feature & feature) 
    217          { 
     195                for (unsigned i=0;i<ar.size();++i) 
     196                { 
     197                    read_double_ndr(wkb_ + pos_,ar[i].x); 
     198                    read_double_ndr(wkb_ + pos_ + 8,ar[i].y); 
     199                    pos_ += 16; 
     200                } 
     201            } 
     202             
     203        } 
     204         
     205        void read_point(Feature & feature) 
     206        { 
    218207            geometry2d * pt = new point<vertex2d>; 
    219208            double x = read_double(); 
     
    221210            pt->move_to(x,y); 
    222211            feature.add_geometry(pt); 
    223          } 
    224           
    225          void read_multipoint(Feature & feature) 
    226          { 
     212        } 
     213          
     214        void read_multipoint(Feature & feature) 
     215        { 
    227216            int num_points = read_integer(); 
    228217            for (int i=0;i<num_points;++i)  
    229218            { 
    230                pos_+=5; 
    231                read_point(feature); 
    232             } 
    233          } 
    234           
    235          void read_multipoint_2(Feature & feature) 
    236          { 
     219                pos_+=5; 
     220                read_point(feature); 
     221            } 
     222        } 
     223          
     224        void read_multipoint_2(Feature & feature) 
     225        { 
    237226            geometry2d * pt = new point<vertex2d>; 
    238227            int num_points = read_integer();  
    239228            for (int i=0;i<num_points;++i)  
    240229            { 
    241                pos_+=5; 
    242                double x = read_double(); 
    243                double y = read_double(); 
    244                pt->move_to(x,y); 
     230                pos_+=5; 
     231                double x = read_double(); 
     232                double y = read_double(); 
     233                pt->move_to(x,y); 
    245234            } 
    246235            feature.add_geometry(pt); 
    247          } 
    248           
    249          void read_linestring(Feature & feature) 
    250          { 
     236        } 
     237          
     238        void read_linestring(Feature & feature) 
     239        { 
    251240            geometry2d * line = new line_string<vertex2d>; 
    252241            int num_points=read_integer(); 
     
    257246            for (int i=1;i<num_points;++i) 
    258247            { 
    259                line->line_to(ar[i].x,ar[i].y); 
     248                line->line_to(ar[i].x,ar[i].y); 
    260249            } 
    261250            feature.add_geometry(line); 
    262          } 
    263           
    264          void read_multilinestring(Feature & feature) 
    265          { 
     251        } 
     252          
     253        void read_multilinestring(Feature & feature) 
     254        { 
    266255            int num_lines=read_integer(); 
    267256            for (int i=0;i<num_lines;++i) 
    268257            { 
    269                pos_+=5; 
    270                read_linestring(feature); 
    271             } 
    272          } 
    273  
    274          void read_multilinestring_2(Feature & feature) 
    275          { 
     258                pos_+=5; 
     259                read_linestring(feature); 
     260            } 
     261        } 
     262 
     263        void read_multilinestring_2(Feature & feature) 
     264        { 
    276265            geometry2d * line = new line_string<vertex2d>; 
    277266            int num_lines=read_integer(); 
     
    279268            for (int i=0;i<num_lines;++i) 
    280269            { 
    281                pos_+=5; 
    282                int num_points=read_integer(); 
    283                capacity+=num_points; 
    284                CoordinateArray ar(num_points);  
    285                read_coords(ar); 
    286                line->set_capacity(capacity); 
    287                line->move_to(ar[0].x,ar[0].y);  
    288                for (int i=1;i<num_points;++i)  
    289                {  
    290                   line->line_to(ar[i].x,ar[i].y);  
    291                }  
     270                pos_+=5; 
     271                int num_points=read_integer(); 
     272                capacity+=num_points; 
     273                CoordinateArray ar(num_points);  
     274                read_coords(ar); 
     275                line->set_capacity(capacity); 
     276                line->move_to(ar[0].x,ar[0].y);  
     277                for (int i=1;i<num_points;++i)  
     278                {  
     279                    line->line_to(ar[i].x,ar[i].y);  
     280                }  
    292281            } 
    293282            feature.add_geometry(line); 
    294          } 
    295           
    296          void read_polygon(Feature & feature)  
    297          { 
     283        } 
     284          
     285        void read_polygon(Feature & feature)  
     286        { 
    298287            geometry2d * poly = new polygon<vertex2d>; 
    299288            int num_rings=read_integer(); 
     
    301290            for (int i=0;i<num_rings;++i) 
    302291            { 
    303                int num_points=read_integer(); 
    304                capacity+=num_points; 
    305                CoordinateArray ar(num_points); 
    306                read_coords(ar); 
    307                poly->set_capacity(capacity); 
    308                poly->move_to(ar[0].x,ar[0].y); 
    309                for (int j=1;j<num_points;++j) 
    310                { 
    311                   poly->line_to(ar[j].x,ar[j].y); 
    312                } 
     292                int num_points=read_integer(); 
     293                capacity+=num_points; 
     294                CoordinateArray ar(num_points); 
     295                read_coords(ar); 
     296                poly->set_capacity(capacity); 
     297                poly->move_to(ar[0].x,ar[0].y); 
     298                for (int j=1;j<num_points;++j) 
     299                { 
     300                    poly->line_to(ar[j].x,ar[j].y); 
     301                } 
    313302            } 
    314303            feature.add_geometry(poly); 
    315          } 
    316          
    317          void read_multipolygon(Feature & feature) 
    318          { 
     304        } 
     305         
     306        void read_multipolygon(Feature & feature) 
     307        { 
    319308            int num_polys=read_integer(); 
    320309            for (int i=0;i<num_polys;++i) 
    321310            { 
    322                pos_+=5; 
    323                read_polygon(feature); 
    324             } 
    325          } 
    326  
    327          void read_multipolygon_2(Feature & feature) 
    328          { 
     311                pos_+=5; 
     312                read_polygon(feature); 
     313            } 
     314        } 
     315 
     316        void read_multipolygon_2(Feature & feature) 
     317        { 
    329318            geometry2d * poly = new polygon<vertex2d>; 
    330319            int num_polys=read_integer(); 
     
    332321            for (int i=0;i<num_polys;++i) 
    333322            { 
    334                pos_+=5; 
    335                int num_rings=read_integer(); 
    336                for (int i=0;i<num_rings;++i) 
    337                { 
    338                   int num_points=read_integer(); 
    339                   capacity += num_points; 
    340                   CoordinateArray ar(num_points); 
    341                   read_coords(ar); 
    342                   poly->set_capacity(capacity); 
    343                   poly->move_to(ar[0].x,ar[0].y); 
     323                pos_+=5; 
     324                int num_rings=read_integer(); 
     325                for (int i=0;i<num_rings;++i) 
     326                { 
     327                    int num_points=read_integer(); 
     328                    capacity += num_points; 
     329                    CoordinateArray ar(num_points); 
     330                    read_coords(ar); 
     331                    poly->set_capacity(capacity); 
     332                    poly->move_to(ar[0].x,ar[0].y); 
    344333                   
    345                   for (int j=1;j<num_points;++j) 
    346                   { 
    347                      poly->line_to(ar[j].x,ar[j].y); 
    348                   } 
    349                   poly->line_to(ar[0].x,ar[0].y); 
    350                } 
     334                    for (int j=1;j<num_points;++j) 
     335                    { 
     336                        poly->line_to(ar[j].x,ar[j].y); 
     337                    } 
     338                    poly->line_to(ar[0].x,ar[0].y); 
     339                } 
    351340            } 
    352341            feature.add_geometry(poly); 
    353          } 
    354    }; 
    355     
    356    void geometry_utils::from_wkb (Feature & feature, 
     342        } 
     343    }; 
     344     
     345    void geometry_utils::from_wkb (Feature & feature, 
    357346                                   const char* wkb, 
    358347                                   unsigned size, 
    359348                                   bool multiple_geometries, 
    360349                                   wkbFormat format)  
    361    { 
    362       wkb_reader reader(wkb,size,format); 
    363       if (multiple_geometries) 
    364          return reader.read_multi(feature); 
    365       else 
    366          return reader.read(feature); 
    367    }     
     350    { 
     351        wkb_reader reader(wkb,size,format); 
     352        if (multiple_geometries) 
     353            return reader.read_multi(feature); 
     354        else 
     355            return reader.read(feature); 
     356    }     
    368357}