<s> from vectorformats . Formats . Format import Format <EOL> import StringIO <EOL> from dxfwrite import DXFEngine as dxf <EOL> class DXF ( Format ) : <EOL> _drawing = None <EOL> def encode ( self , features , ** kwargs ) : <EOL> tmpFile = kwargs [ "<STR_LIT>" ] <EOL> if len ( features ) > <NUM_LIT:0> : <EOL> self . _drawing = dxf . drawing ( tmpFile ) <EOL> self . _drawing . add_layer ( "<STR_LIT>" ) <EOL> for feature in features : <EOL> self . encode_feature ( feature ) <EOL> self . _drawing . save ( ) <EOL> return self . _drawing <EOL> def encode_feature ( self , feature ) : <EOL> if feature [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> self . _drawing . add ( dxf . point ( point = ( feature [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , feature [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ <NUM_LIT:1> ] ) ) ) <EOL> elif feature [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> polyline = dxf . polyline ( ) <EOL> coords = feature [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> for coord in coords : <EOL> polyline . add_vertex ( ( coord [ <NUM_LIT:0> ] , coord [ <NUM_LIT:1> ] ) ) <EOL> self . _drawing . add ( polyline ) <EOL> elif feature [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> polygon = dxf . polyline ( ) <EOL> coords = feature [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> for coord in coords : <EOL> for point in coord : <EOL> polygon . add_vertex ( ( point [ <NUM_LIT:0> ] , point [ <NUM_LIT:1> ] ) ) <EOL> polygon . close ( ) <EOL> self . _drawing . add ( polygon ) </s>
