Beispiel #1
0
 def _build_polygon(self):
     outline_pts = list(self.polyline_1.coords) + list(reversed(self.polyline_2.coords))
     self.polygon = geo.Polygon(outline_pts)
     if not self.polygon.is_simple:  # FIXME: it should be "if not self.polygon.is_valid"
         print("Distance ligne = %s" % self.polyline_1.distance(self.polyline_2))
         print("Distance début = %s" % self.polyline_1.interpolate(0, normalized=True).distance(
             self.polyline_2.interpolate(0, normalized=True)))
         print("Distance fin = %s" % self.polyline_1.interpolate(1, normalized=True).distance(
             self.polyline_2.interpolate(1, normalized=True)))
         with bk.Write('debug.i3s') as out_i3s:
             out_i3s.write_header()
             out_i3s.write_lines([Polyline(self.polygon.exterior.coords)], [0.0])
         sys.exit("ERROR: Zone is invalid. Check polyline direction consistancy!")
Beispiel #2
0
    def export_sections(self, path):
        """
        Export generated profiles in a shp, i3s or georefC file
        /!\ Not relevant if constant_long_disc is False
        TODO: Use class MascaretGeoFile
        """
        values = self.interp_values_from_geom()
        if path.endswith('.georefC'):
            with open(path, 'w') as out_geo:
                for dist in np.unique(self.points['Xl']):
                    pos = self.points['Xl'] == dist
                    points = self.points[pos]

                    # Compute Xt  (FIXME: rather keep from previous calculations...)
                    Xt = np.sqrt(
                        np.power(np.ediff1d(points['X'], to_begin=0.), 2) +
                        np.power(np.ediff1d(points['Y'], to_begin=0.), 2))
                    Xt = Xt.cumsum()
                    points = append_fields(points, 'Xt', Xt, usemask=False)

                    for i, row in enumerate(points):
                        if i == 0:
                            positions_str = ' %f %f %f %f' % (
                                row['X'], row['Y'], points[-1]['X'],
                                points[-1]['Y'])
                            positions_str += ' AXE %f %f' % (
                                row['X'], row['Y']
                            )  # FIXME: not the axis position...
                            out_geo.write(
                                'Profil Bief_0 %s %f%s\n' %
                                ('P' + str(dist), dist, positions_str))

                        layers_str = ' ' + ' '.join([
                            COURLIS_FLOAT_FMT % x for x in values[:, pos][:, i]
                        ])

                        out_geo.write(
                            '%f%s B %f %f\n' %
                            (row['Xt'], layers_str, row['X'], row['Y']))
            return

        lines = []
        for dist in np.unique(self.points['Xl']):
            pos = self.points['Xl'] == dist
            line = geometry.Polyline([
                (x, y, z)
                for (x,
                     y), z in zip(self.points[pos][['X', 'Y']], values[0, :])
            ])
            line.add_attribute(dist)
            lines.append(line)

        if path.endswith('.i3s'):
            with bk.Write(path) as out_i3s:
                out_i3s.write_header()
                out_i3s.write_lines(lines, [l.attributes()[0] for l in lines])

        elif path.endswith('.shp'):
            shp.write_shp_lines(path, shapefile.POLYLINEZ, lines, 'Z')

        else:
            raise NotImplementedError(
                "Only the shp (POLYLINEZ), i3s and georefC formats are supported for "
                "the generated cross-sections file")