locked
Geometry STBuffer() ends up just a circle - What could I be doing wrong? RRS feed

  • Question

  • All,

    I am working towards generating a dynamic buffer of a polygon object. I have no issue creating the polygon (GEOMETRY & GEOGRAPHY) from the points collected.  I seem to be running into an issue however when I go to buffer this by 150 ft. I am using projection latitude/longitude NAD83, so my SRID = 4269. 

    Can anyone help me understand why the GEOMETRY is unable to generate the correct buffer? (see below)

    DECLARE @SRID int = 4269; DECLARE @geog_DigBox GEOGRAPHY; DECLARE @geom_DigBox GEOMETRY;
    DECLARE @geom_DigBox_Buffer GEOMETRY; DECLARE @geog_DigBox_Buffer GEOGRAPHY;
    DECLARE @BufferSize int = 150; DECLARE @meter_per_foot FLOAT = 0.3048;
    SET @geog_DigBox = geography::STGeomFromText('POLYGON ((-79.927544 40.363386, -79.927122 40.362364, -79.926077 40.363064, -79.925094 40.362344, -79.924993 40.363698, -79.925995 40.362282, -79.927544 40.363386))', @SRID);
    SET @geom_DigBox = geometry::STGeomFromText('POLYGON ((-79.927544 40.363386, -79.927122 40.362364, -79.926077 40.363064, -79.925094 40.362344, -79.924993 40.363698, -79.925995 40.362282, -79.927544 40.363386))', @SRID);

    IF (@geog_DigBox.STIsValid() = 0)
     begin
      SET @geog_DigBox = @geog_DigBox.MakeValid();
      print 'had to make GEOGRAPHY valid'
     end
    ELSE
     print 'OK GEOGRAPHY - moving along...  ' + @geog_DigBox.ToString();

    IF (@geom_DigBox.STIsValid() = 0)
     begin    
      SET @geom_DigBox = @geom_DigBox.MakeValid();
      print 'had to make GEOMETRY valid'
     end
    ELSE
     print 'OK GEOMETRY - moving along...  ' + @geom_DigBox.ToString();

    -- 0.3048 meter per foot
    SET @geog_DigBox_Buffer = @geog_DigBox.STBuffer(@BufferSize * @meter_per_foot);
    SET @geom_DigBox_Buffer = @geom_DigBox.STBuffer(@BufferSize * @meter_per_foot);

    IF (@geog_DigBox_Buffer.STIsValid() = 0)
     begin
      SET @geog_DigBox_Buffer = @geog_DigBox_Buffer.MakeValid();
      print 'had to make BUFFER GEOGRAPHY valid'
     end
    ELSE
     print 'OK BUFFER GEOGRAPHY - finishing up...  ' + @geog_DigBox.ToString();

    IF (@geom_DigBox_Buffer.STIsValid() = 0)
     begin
      SET @geom_DigBox_Buffer = @geom_DigBox_Buffer.MakeValid();
      print 'had to make BUFFER GEOMETRY valid'
     end
    ELSE
     print 'OK BUFFER GEOMETRY - finishing up...  ' + @geog_DigBox.ToString();

    --The Buffer's GEOGRAPHY is accurate (seen below)

    However, the Buffer's GEOMETRY looks like this:

    Is it perhaps a limitation of the GEOMETRY versus the GEOGRAPHY? Any help would be greatly appreciated. 

    Nick


    Thanks! Nick

    Tuesday, February 2, 2016 4:17 PM

Answers

  • By using

    SET @geom_DigBox_Buffer = @geom_DigBox.STBuffer(.0004);

    I was able to get a geometry buffer that looked close to the geography buffer.

    Tuesday, February 2, 2016 10:35 PM

All replies

  • This happens because geometry data type doesn't use meters as a unit of measure, regardless of the SRID (it's using planar coordinates). Try using a different (smaller) value for distance in your STBuffer call.
    • Proposed as answer by Bob Beauchemin Wednesday, February 3, 2016 6:05 PM
    Tuesday, February 2, 2016 5:24 PM
  • Bob,

    Thanks for the reply; however, even if I made the call to STBuffer be a value of "1" it still showed the GEOMETRY as a circle (same as picture above).  In the end, I think all I need is the GEOGRAPHY object to do the work I need done to do spatial searching (comparing other existing GEOGRAPHY in the database) with this dynamically generated polygon drawn within the user interface.

    I was able to get my results without needing anything to do with the GEOMETRY field in the end.  I am still pretty new to using the spatial querying/world in general, so sorry if I asked an entry level question.  My end result I can use the 150 ft. buffer of the GEOGRAPHY field to display any intersecting polygons (stored already in the database).

    I am not sure if you have any other solutions to try; however, I was able to progressively move on at this point.  Have a good day and thanks for your insight.


    Thanks! Nick

    Tuesday, February 2, 2016 9:52 PM
  • By using

    SET @geom_DigBox_Buffer = @geom_DigBox.STBuffer(.0004);

    I was able to get a geometry buffer that looked close to the geography buffer.

    Tuesday, February 2, 2016 10:35 PM