Пример #1
0
 def to_i2s_i3s(self, new_shapes, to_file):
     attributes = []
     for line in new_shapes:
         attributes.append(line.attributes()[0])
     with bk.Write(to_file) as f:
         f.write_header(self.header)
         f.write_lines(new_shapes, attributes)
Пример #2
0
    def run(self):
        if self.state == Node.SUCCESS:
            return
        try:
            with open(self.filename) as f:
                pass
        except PermissionError:
            self.fail('Access denied.')
            return
        self.data = PolylineData()
        is_i2s = self.filename[-4:] == '.i2s'
        if is_i2s:
            with BlueKenue.Read(self.filename) as f:
                f.read_header()
                for poly in f.get_open_polylines():
                    self.data.add_line(poly)
            self.data.set_fields(['Value'])
        else:
            try:
                for poly in Shapefile.get_open_polylines(self.filename):
                    self.data.add_line(poly)
            except struct.error:
                self.fail('Inconsistent bytes.')
                return
            self.data.set_fields(Shapefile.get_all_fields(self.filename))

        if self.data.is_empty():
            self.fail('the file does not contain any 2D open polyline.')
            return

        self.success('The file contains {} open line{}.'.format(
            len(self.data), 's' if len(self.data) > 1 else ''))
Пример #3
0
 def from_i3s_to_i2s(self, new_shapes, to_file):
     attributes = []
     shapes = []
     for line in new_shapes:
         attributes.append(line.attributes()[0])
         coords = np.array(list(line.coords()))
         shapes.append(Polyline(coords[:, :2]))
     with bk.Write(to_file) as f:
         f.write_header(self.default_header)
         f.write_lines(shapes, attributes)
Пример #4
0
 def read(self):
     try:
         with bk.Read(self.from_file) as fin:
             fin.read_header()
             for point in fin.get_points():
                 self.shapes.append(point)
             self.header = fin.header
     except PermissionError:
         raise PermissionError
     if not self.shapes:
         raise ValueError
Пример #5
0
    def to_i3s(self, new_shapes, to_file, attribute_method):
        attributes = []
        for i, poly in enumerate(new_shapes):
            if attribute_method == '0':
                attributes.append(0)
            elif attribute_method == 'Iteration':
                attributes.append(i + 1)
            else:
                attribute_index = int(attribute_method.split(' - ')[0])
                attributes.append(poly.attributes()[attribute_index])

        with bk.Write(to_file) as f:
            f.write_header(self.i3s_header)
            f.write_lines(new_shapes, attributes)
Пример #6
0
 def read(self):
     try:
         with bk.Read(self.from_file) as fin:
             fin.read_header()
             for line in fin.get_lines():
                 self.shapes.append(line)
                 if line.is_closed():
                     self.nb_closed += 1
                 else:
                     self.nb_open += 1
             self.header = fin.header
     except PermissionError:
         raise PermissionError
     if not self.shapes:
         raise ValueError
Пример #7
0
 def to_xyz(self, new_shapes, to_file):
     with bk.Write(to_file) as f:
         f.write_points(new_shapes)
Пример #8
0
 def to_xyz(self, new_shapes, to_file):
     with bk.Write(to_file) as f:
         if WRITE_XYZ_HEADER:
             f.write_header(self.header)
         f.write_points(new_shapes)