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")
import os.path import shapefile from pyteltools.geom import conversion, geometry, Shapefile # Write polylines shapefile lines = [ geometry.Polyline([(0, 0, 0), (10, 20, 30)], attributes=[0], m_array=[[0], [100]]) ] Shapefile.write_shp_lines('from_scratch/polyline.shp', shapefile.POLYLINE, lines, 'LineID') Shapefile.write_shp_lines('from_scratch/polylinez.shp', shapefile.POLYLINEZ, lines, 'LineID') Shapefile.write_shp_lines('from_scratch/polylinem.shp', shapefile.POLYLINEM, lines, 'LineID') # Write polygons shapefile lines = [ geometry.Polyline([(0, 0, 0), (10, 20, 30), (10, 40, 30), (0, 0, 0)], attributes=[0], m_array=[[0], [100], [200], [300]]) ] Shapefile.write_shp_lines('from_scratch/polygon.shp', shapefile.POLYGON, lines, 'PolyID') Shapefile.write_shp_lines('from_scratch/polygonz.shp', shapefile.POLYGONZ, lines, 'PolyID') Shapefile.write_shp_lines('from_scratch/polygonm.shp', shapefile.POLYGONM, lines, 'PolyID')