parameters: (self, filepath=None)
docstring: Exports shape data into given file.
          If no file is given, the the default file path will be selected.
docstring_summary: Exports shape data into given file.
          If no file is given, the the default file path will be selected.
docstring_tokens: Exports shape data into given file . If no file is given the the default file path will be selected .
function: def export_shapefile(self, filepath=None):
          """
          Exports shape data into given file.
          If no file is given, the the default file path will be selected.
          """
          # https://code.google.com/p/pyshp/
          print '\nexport_shapefile', filepath
          #proj_target, offset_target = self.parent.get_proj_offset()
          if len(self) == 0:
              return False
  
          if filepath is None:
              filepath = self.filepath.get_value()
          else:
              self.filepath.set_value(filepath)
  
          basefilepath = self.get_basefilepath(filepath)
          shapetype = self.shapetype.get_value()
          w = shapefile.Writer()
          w.shapeType = shapetype
          w.autoBalance = 1
          shapes = []
          # print '  shapeattrs:',self.get_group('shapeattrs')
          attrnames = []
          for attrconf in self.get_group('shapeattrs'):
              # print '    ',attrconf.field
              w.field(*attrconf.field)
              attrnames.append(attrconf)
  
          # for key in self.get_keys():
          ids_shape = self.get_ids()
          offset = self._offset.get_value()
  
          # print '  offset',offset
          if shapetype == 1:  # 'Point':1,
              # single points need a scpecial treatment
              for id_shape, coord in zip(ids_shape, self.coords[ids_shape]):
                  # print '  id_shape',id_shape,coord
                  # shapes.append(self.shapes.get(key).tolist())
                  # print '    shape',(np.array(shape, dtype = np.float32)[:,:2] - offset).tolist()
                  w.poly(shapeType=shapetype, parts=[[coord[:2] - offset], ])
                  #id = self.get_id_from_key(key)
                  attrs = {}
                  for attrconf in self.get_group('shapeattrs'):
                      val = attrconf[id_shape]
                      if attrconf.field[1] == 'N':
                          if val == np.nan:
                              val = 'NONE'
                      attrs[attrconf.attrname] = val
                  # print '  record',key,' attrs=', attrs
                  w.record(**attrs)
          else:
  
              for id_shape, shape in zip(ids_shape, self.shapes[ids_shape]):
                  # print '  id_shape',id_shape, np.array(shape, dtype = np.float32)
                  # shapes.append(self.shapes.get(key).tolist())
                  # print '    shape',(np.array(shape, dtype = np.float32)[:,:2] - offset).tolist()
                  w.poly(shapeType=shapetype, parts=[(np.array(shape, dtype=np.float32)[:, :2] - offset).tolist(), ])
                  #id = self.get_id_from_key(key)
                  attrs = {}
                  for attrconf in self.get_group('shapeattrs'):
                      val = attrconf[id_shape]
                      if attrconf.field[1] == 'N':
                          if val == np.nan:
                              val = 'NONE'
                      attrs[attrconf.attrname] = val
                  # print '  record',key,' attrs=', attrs
                  w.record(**attrs)
          # a null shape: w.null()
  
          #w.poly(shapeType=3, parts=shapes)
          # try:
          w.save(filepath)
          # except:
          #    print 'WARNING in export_shapefile:\n no shapefile written. Probably fields are not large enough.'
          #    return
  
          try:
              shapeproj = get_shapeproj(self._projparams.get_value())
              # create the PRJ file
              prjfile = open("%s.prj" % basefilepath, "w")
              prjfile.write(shapeproj)
              prjfile.close()
              return True
          except:
              print 'WARNING in export_shapefile:\n no projection file written (probably no Internet connection).'
              print 'Open shapefile with projection: %s.' % self._projparams.get_value()
              # raise
              return False
function_tokens: def export_shapefile ( self , filepath = None ) : # https://code.google.com/p/pyshp/ print '\nexport_shapefile' , filepath #proj_target, offset_target = self.parent.get_proj_offset() if len ( self ) == 0 : return False if filepath is None : filepath = self . filepath . get_value ( ) else : self . filepath . set_value ( filepath ) basefilepath = self . get_basefilepath ( filepath ) shapetype = self . shapetype . get_value ( ) w = shapefile . Writer ( ) w . shapeType = shapetype w . autoBalance = 1 shapes = [ ] # print '  shapeattrs:',self.get_group('shapeattrs') attrnames = [ ] for attrconf in self . get_group ( 'shapeattrs' ) : # print '    ',attrconf.field w . field ( * attrconf . field ) attrnames . append ( attrconf ) # for key in self.get_keys(): ids_shape = self . get_ids ( ) offset = self . _offset . get_value ( ) # print '  offset',offset if shapetype == 1 : # 'Point':1, # single points need a scpecial treatment for id_shape , coord in zip ( ids_shape , self . coords [ ids_shape ] ) : # print '  id_shape',id_shape,coord # shapes.append(self.shapes.get(key).tolist()) # print '    shape',(np.array(shape, dtype = np.float32)[:,:2] - offset).tolist() w . poly ( shapeType = shapetype , parts = [ [ coord [ : 2 ] - offset ] , ] ) #id = self.get_id_from_key(key) attrs = { } for attrconf in self . get_group ( 'shapeattrs' ) : val = attrconf [ id_shape ] if attrconf . field [ 1 ] == 'N' : if val == np . nan : val = 'NONE' attrs [ attrconf . attrname ] = val # print '  record',key,' attrs=', attrs w . record ( * * attrs ) else : for id_shape , shape in zip ( ids_shape , self . shapes [ ids_shape ] ) : # print '  id_shape',id_shape, np.array(shape, dtype = np.float32) # shapes.append(self.shapes.get(key).tolist()) # print '    shape',(np.array(shape, dtype = np.float32)[:,:2] - offset).tolist() w . poly ( shapeType = shapetype , parts = [ ( np . array ( shape , dtype = np . float32 ) [ : , : 2 ] - offset ) . tolist ( ) , ] ) #id = self.get_id_from_key(key) attrs = { } for attrconf in self . get_group ( 'shapeattrs' ) : val = attrconf [ id_shape ] if attrconf . field [ 1 ] == 'N' : if val == np . nan : val = 'NONE' attrs [ attrconf . attrname ] = val # print '  record',key,' attrs=', attrs w . record ( * * attrs ) # a null shape: w.null() #w.poly(shapeType=3, parts=shapes) # try: w . save ( filepath ) # except: #    print 'WARNING in export_shapefile:\n no shapefile written. Probably fields are not large enough.' #    return try : shapeproj = get_shapeproj ( self . _projparams . get_value ( ) ) # create the PRJ file prjfile = open ( "%s.prj" % basefilepath , "w" ) prjfile . write ( shapeproj ) prjfile . close ( ) return True except : print 'WARNING in export_shapefile:\n no projection file written (probably no Internet connection).' print 'Open shapefile with projection: %s.' % self . _projparams . get_value ( ) # raise return False