<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self, outfile, format='ESRI Shapefile', overwrite=True):
 """ write the Vector object to a file Parameters outfile: the name of the file to write format: str the output file format overwrite: bool overwrite an already existing file? Returns ------- """

        (outfilepath, outfilename) = os.path.split(outfile)
        basename = os.path.splitext(outfilename)[0]
        
        driver = ogr.GetDriverByName(format)
        
        if os.path.exists(outfile):
            if overwrite:
                driver.DeleteDataSource(outfile)
            else:
                raise RuntimeError('target file already exists')
        
        outdataset = driver.CreateDataSource(outfile)
        outlayer = outdataset.CreateLayer(self.layername, geom_type=self.geomType)
        outlayerdef = outlayer.GetLayerDefn()
        
        for fieldDef in self.fieldDefs:
            outlayer.CreateField(fieldDef)
        
        self.layer.ResetReading()
        for feature in self.layer:
            outFeature = ogr.Feature(outlayerdef)
            outFeature.SetGeometry(feature.GetGeometryRef())
            for name in self.fieldnames:
                outFeature.SetField(name, feature.GetField(name))
            # add the feature to the shapefile
            outlayer.CreateFeature(outFeature)
            outFeature = None
        self.layer.ResetReading()
        
        if format == 'ESRI Shapefile':
            srs_out = self.srs.Clone()
            srs_out.MorphToESRI()
            with open(os.path.join(outfilepath, basename + '.prj'), 'w') as prj:
                prj.write(srs_out.ExportToWkt())
        
        outdataset = None