0

I have a simple geometry polygon shape. I can get the bounding box using STEnvelope(). I want to expand the points proportionally to basically zoom out similar to the screenshot.

Does mssql server have the ability to do that?

         DECLARE    @g GEOMETRY;
         SET @g = GEOMETRY::STPolyFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
         SELECT @g.STEnvelope()

screen

Update: I create a demo sql command to scale a polygon. Rather then centering the new polygon it's placed on the top right.

         DECLARE @zoom DECIMAL(22,22);
         SET @zoom = 0.00001;

         DECLARE    @g GEOMETRY;
         SET @g = geometry::STGeomFromText('POLYGON ((-12934935.9561 5405312.0569999963, -12934925.8363 5405305.5031, -12934930.8382 5405297.7252999991, -12934940.957899999 5405304.2792000026, -12934935.9561 5405312.0569999963))', 3857)

         SELECT @g.STPointN(1)
         UNION ALL
         SELECT @g.STPointN(2)
         UNION ALL
         SELECT @g.STPointN(3)
         UNION ALL
         SELECT @g.STPointN(4)
         UNION ALL
         SELECT Geometry::Point(@g.STPointN(1).STX + (@g.STPointN(1).STX * ( CASE WHEN @g.STPointN(1).STX > 0 THEN @zoom ELSE -@zoom END )), @g.STPointN(1).STY + (@g.STPointN(1).STY * ( CASE WHEN @g.STPointN(1).STY > 0 THEN @zoom ELSE -@zoom END )), 3857)
         UNION ALL
         SELECT Geometry::Point(@g.STPointN(2).STX + (@g.STPointN(2).STX * ( CASE WHEN @g.STPointN(2).STX > 0 THEN @zoom ELSE -@zoom END )), @g.STPointN(2).STY + (@g.STPointN(2).STY * ( CASE WHEN @g.STPointN(2).STY > 0 THEN @zoom ELSE -@zoom END )), 3857)
         UNION ALL
         SELECT Geometry::Point(@g.STPointN(3).STX + (@g.STPointN(3).STX * ( CASE WHEN @g.STPointN(3).STX > 0 THEN @zoom ELSE -@zoom END )), @g.STPointN(3).STY + (@g.STPointN(3).STY * ( CASE WHEN @g.STPointN(3).STY > 0 THEN @zoom ELSE -@zoom END )), 3857)
         UNION ALL
         SELECT Geometry::Point(@g.STPointN(4).STX + (@g.STPointN(4).STX * ( CASE WHEN @g.STPointN(4).STX > 0 THEN @zoom ELSE -@zoom END )), @g.STPointN(4).STY + (@g.STPointN(4).STY * ( CASE WHEN @g.STPointN(4).STY > 0 THEN @zoom ELSE -@zoom END )), 3857)

enter image description here

What am I doing wrong?

Kathy Judd
  • 715
  • 3
  • 9
  • 21
  • in short, no, MS SQL Server doesn't have a built-in Geometry method for _scaling_ (zooming as you call it) geometry objects. The `STBuffer` method will put a buffer of a certain size around a geometry object (you can liken it to _padding_ in CSS) but I doubt that is the solution you are looking for. A custom function would have to be written. – Jonathon Ogden Mar 31 '16 at 22:45
  • Here's some pointers on creating a custom function and the accepted answer mentions a C# library you might be able to wrap in a CLR stored proc http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons – Liesel Apr 04 '16 at 02:33
  • Kathy, are you looking for squares each time, or have you just used squares in your example but in reality this could be any rectangular shape? – Jon Bellamy Apr 06 '16 at 09:40

1 Answers1

0

I've ended up ditching the ms sql version and use Clipper http://www.angusj.com/delphi/clipper.php with c# version.

Kathy Judd
  • 715
  • 3
  • 9
  • 21