Eccovi lo script :
Set nocount On Declare @i smallint = 1 Declare @l smallint = 10 Declare @Offset smallint = 10 Declare @x1 smallint = 100 Declare @y1 smallint = 100 Declare @x2 smallint = 150 Declare @y2 smallint = 100 Declare @x3 smallint = 125 Declare @y3 smallint = 115 Declare @x4 smallint = 100 Declare @y4 smallint = 100 Declare @Albero Table ( Id Tinyint IDENTITY (1,1), Triangolo geometry ); Declare @Palline Table ( Id Tinyint IDENTITY (1,1), Pallina geometry ); /***********************************************************/ /* Crea l'albero */ /***********************************************************/ While @i<=@l Begin Insert into @Albero (Triangolo) values (geometry::STGeomFromText ('POLYGON ((' +cast(@x1 as varchar(5))+' '+cast(@y1 as varchar(5))+',' +cast(@x2 as varchar(5))+' '+cast(@y2 as varchar(5))+',' +cast(@x3 as varchar(5))+' '+cast(@y3 as varchar(5))+',' +cast(@x4 as varchar(5))+' '+cast(@y4 as varchar(5))+'))', 0) ) Insert into @Palline (Pallina) values (geometry::STGeomFromText('POINT(' + cast(@x1 as varchar(5)) + ' ' +cast(@y1 as varchar(5)) +')',0)) Insert into @Palline (Pallina) values (geometry::STGeomFromText('POINT(' + cast(@x2 as varchar(5)) + ' ' +cast(@y2 as varchar(5)) +')',0)) Insert into @Palline (Pallina) values (geometry::STGeomFromText('POINT(' + cast(@x3 as varchar(5)) + ' ' +cast(@y3 as varchar(5)) +')',0)) Set @x1 -= @Offset Set @x2 += @Offset Set @x4 -= @Offset Set @y1 -= @Offset Set @y2 -= @Offset Set @y3 -= @Offset Set @y4 -= @Offset Set @i += 1 end /***********************************************************/ /* Crea il tronco */ /***********************************************************/ Set @x1 = @x3-@Offset Set @x2 = @x3+@Offset Set @x3 = @x3+@Offset Set @x4 = @x2 Insert into @Albero (Triangolo) values (geometry::STGeomFromText ('POLYGON ((' +cast(@x1 as varchar(5))+' '+cast(@y1 as varchar(5))+',' +cast(@x2 as varchar(5))+' '+cast(@y2 as varchar(5))+',' +cast(@x2 as varchar(5))+' '+cast(@y3 as varchar(5))+',' +cast(@x1 as varchar(5))+' '+cast(@y3 as varchar(5))+',' +cast(@x1 as varchar(5))+' '+cast(@y1 as varchar(5))+'))', 0)) Select 'Happy SQL Christmass !!!' Select Triangolo from @Albero union all Select Pallina.STBuffer(3) from @Palline
Ed ecco il risultato che troverete nel tab Spatial data :
Nessun commento:
Posta un commento