<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample(self, nsamples=1, weighted=True):
 """ Sample n points from the provided raster mask. The number of points belonging to each class is proportional to the area this class covers in the raster mask, if weighted is set to True. TODO: If polygon has holes the number of sampled points will be less than nsamples :param nsamples: number of sampled samples :type nsamples: integer :param weighted: flag to apply weights proportional to total area of each class/polygon when sampling :type weighted: bool, default is True """

        weights = self.areas / np.sum(self.areas) if weighted else None
        index = np.random.choice(a=len(self.geometries), size=nsamples, p=weights)

        labels = []
        rows = []
        cols = []
        for idx in index:
            polygon = self.geometries[idx]['polygon']
            label = self.geometries[idx]['label']
            point = PointSampler.random_point(polygon.envelope.bounds)
            if PointSampler.contains(polygon, point):
                labels.append(label)
                rows.append(int(point.y))
                cols.append(int(point.x))
                # samples.append({'label':label, 'row':point.y, 'col':point.x})

        return labels, rows, cols