<s> from ctypes import byref , c_int <EOL> from datetime import date , datetime , time <EOL> from django . contrib . gis . gdal . base import GDALBase <EOL> from django . contrib . gis . gdal . error import OGRException <EOL> from django . contrib . gis . gdal . prototypes import ds as capi <EOL> class Field ( GDALBase ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , feat , index ) : <EOL> """<STR_LIT>""" <EOL> self . _feat = feat <EOL> self . _index = index <EOL> fld_ptr = capi . get_feat_field_defn ( feat , index ) <EOL> if not fld_ptr : <EOL> raise OGRException ( '<STR_LIT>' ) <EOL> self . ptr = fld_ptr <EOL> self . __class__ = OGRFieldTypes [ self . type ] <EOL> if isinstance ( self , OFTReal ) and self . precision == <NUM_LIT:0> : <EOL> self . __class__ = OFTInteger <EOL> def __str__ ( self ) : <EOL> "<STR_LIT>" <EOL> return str ( self . value ) . strip ( ) <EOL> def as_double ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_as_double ( self . _feat , self . _index ) <EOL> def as_int ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_as_integer ( self . _feat , self . _index ) <EOL> def as_string ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_as_string ( self . _feat , self . _index ) <EOL> def as_datetime ( self ) : <EOL> "<STR_LIT>" <EOL> yy , mm , dd , hh , mn , ss , tz = [ c_int ( ) for i in range ( <NUM_LIT:7> ) ] <EOL> status = capi . get_field_as_datetime ( self . _feat , self . _index , byref ( yy ) , byref ( mm ) , byref ( dd ) , <EOL> byref ( hh ) , byref ( mn ) , byref ( ss ) , byref ( tz ) ) <EOL> if status : <EOL> return ( yy , mm , dd , hh , mn , ss , tz ) <EOL> else : <EOL> raise OGRException ( '<STR_LIT>' ) <EOL> @ property <EOL> def name ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_name ( self . ptr ) <EOL> @ property <EOL> def precision ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_precision ( self . ptr ) <EOL> @ property <EOL> def type ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_type ( self . ptr ) <EOL> @ property <EOL> def type_name ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_type_name ( self . type ) <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> return self . as_string ( ) <EOL> @ property <EOL> def width ( self ) : <EOL> "<STR_LIT>" <EOL> return capi . get_field_width ( self . ptr ) <EOL> class OFTInteger ( Field ) : <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> return self . as_int ( ) <EOL> @ property <EOL> def type ( self ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:0> <EOL> class OFTReal ( Field ) : <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> return self . as_double ( ) <EOL> class OFTString ( Field ) : pass <EOL> class OFTWideString ( Field ) : pass <EOL> class OFTBinary ( Field ) : pass <EOL> class OFTDate ( Field ) : <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> yy , mm , dd , hh , mn , ss , tz = self . as_datetime ( ) <EOL> return date ( yy . value , mm . value , dd . value ) <EOL> except ( ValueError , OGRException ) : <EOL> return None <EOL> class OFTDateTime ( Field ) : <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> yy , mm , dd , hh , mn , ss , tz = self . as_datetime ( ) <EOL> return datetime ( yy . value , mm . value , dd . value , hh . value , mn . value , ss . value ) <EOL> except ( ValueError , OGRException ) : <EOL> return None <EOL> class OFTTime ( Field ) : <EOL> @ property <EOL> def value ( self ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> yy , mm , dd , hh , mn , ss , tz = self . as_datetime ( ) <EOL> return time ( hh . value , mn . value , ss . value ) <EOL> except ( ValueError , OGRException ) : <EOL> return None <EOL> class OFTIntegerList ( Field ) : pass <EOL> class OFTRealList ( Field ) : pass <EOL> class OFTStringList ( Field ) : pass <EOL> class OFTWideStringList ( Field ) : pass <EOL> OGRFieldTypes = { <NUM_LIT:0> : OFTInteger , <EOL> <NUM_LIT:1> : OFTIntegerList , <EOL> <NUM_LIT:2> : OFTReal , <EOL> <NUM_LIT:3> : OFTRealList , <EOL> <NUM_LIT:4> : OFTString , <EOL> <NUM_LIT:5> : OFTStringList , <EOL> <NUM_LIT:6> : OFTWideString , <EOL> <NUM_LIT:7> : OFTWideStringList , <EOL> <NUM_LIT:8> : OFTBinary , <EOL> <NUM_LIT:9> : OFTDate , <EOL> <NUM_LIT:10> : OFTTime , <EOL> <NUM_LIT:11> : OFTDateTime , <EOL> } <EOL> ROGRFieldTypes = dict ( [ ( cls , num ) for num , cls in OGRFieldTypes . items ( ) ] ) </s>
