Geography Data Type - Divide Circle (Buffered Point) into 8 pieces like a pie

  • I have a point that I am buffering by 1 mile to create a circle. I want to divide this circle (polygon) into 8 polygons each representing an equal portion of the circle like pieces of a pie.

    I then want to use those polygons to perform spatial queries.

    Here is what I have so far. If I could locate 8 points on the outer bounds of the circle, I could create a polyline from the centroid to each of the eight points and then do a difference on the two geography types. I cannot figure out how to locate the points on the bounding circle with each having a 45 degree angle.

    DECLARE @g geography;

    declare @h geography;

    SET @g = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326);

    set @g = @g.STBuffer(1609)

    SELECT @g.ToString();

    select @g.STBuffer(1609).EnvelopeCenter() as Centroid, @g.STBuffer(1609) as BufferedPoint

    Any help is greatly appreciated.

    Keith

  • I figured this out. I created another polygon from lines that extend from the centroid outward in 8 directions for 3 degrees. I then create a multipolygon as a difference between my circle and the lines. Finally, I just created new polygons by indexing into the multipolygon.

    Here is my code.

    declare @g geography

    declare @line1 geography

    declare @line2 geography

    declare @line3 geography

    declare @line4 geography

    declare @line5 geography

    declare @line6 geography

    declare @line7 geography

    declare @line8 geography

    declare @poly1 geography

    declare @poly2 geography

    declare @poly3 geography

    declare @poly4 geography

    declare @poly5 geography

    declare @poly6 geography

    declare @poly7 geography

    declare @poly8 geography

    declare @Bandwidth float

    declare @Latitude float

    declare @Longitude float

    set @g = geography::Point(@Latitude, @Longitude, 4269)

    set @g = @g.STBuffer(@Bandwidth)

    set @line1 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude+0 AS VARCHAR(20)) + ' ' + CAST(@Latitude+3 AS VARCHAR(20))+')', 4269)

    set @line2 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude+3 AS VARCHAR(20)) + ' ' + CAST(@Latitude+3 AS VARCHAR(20))+')', 4269)

    set @line3 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude+3 AS VARCHAR(20)) + ' ' + CAST(@Latitude+0 AS VARCHAR(20))+')', 4269)

    set @line4 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude+3 AS VARCHAR(20)) + ' ' + CAST(@Latitude-3 AS VARCHAR(20))+')', 4269)

    set @line5 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude-0 AS VARCHAR(20)) + ' ' + CAST(@Latitude-3 AS VARCHAR(20))+')', 4269)

    set @line6 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude-3 AS VARCHAR(20)) + ' ' + CAST(@Latitude-3 AS VARCHAR(20))+')', 4269)

    set @line7 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude-3 AS VARCHAR(20)) + ' ' + CAST(@Latitude-0 AS VARCHAR(20))+')', 4269)

    set @line8 = geography::STLineFromText('LINESTRING(' + CAST(@Longitude AS VARCHAR(20)) + ' ' + CAST(@Latitude AS VARCHAR(20)) + ', ' + CAST(@Longitude-3 AS VARCHAR(20)) + ' ' + CAST(@Latitude+3 AS VARCHAR(20))+')', 4269)

    set @h = @line1.STUnion(@line2)

    set @h = @h.STUnion(@line3)

    set @h = @h.STUnion(@line4)

    set @h = @h.STUnion(@line5)

    set @h = @h.STUnion(@line6)

    set @h = @h.STUnion(@line7)

    set @h = @h.STUnion(@line8)

    set @multipoly = @g.STDifference(@h.STBuffer(.1))

    set @poly1 = @multipoly.STGeometryN(1)

    set @poly2 = @multipoly.STGeometryN(2)

    set @poly3 = @multipoly.STGeometryN(3)

    set @poly4 = @multipoly.STGeometryN(4)

    set @poly5 = @multipoly.STGeometryN(5)

    set @poly6 = @multipoly.STGeometryN(6)

    set @poly7 = @multipoly.STGeometryN(7)

    set @poly8 = @multipoly.STGeometryN(8)

    That created my 8 portion pie for my circle.

    Regards,

    Keith

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply