0

Is it possible to change/define precision on/for geometry operations like STEquals, STUnion, ...? More concrete... let say we have to geometries in Web Mercator coordinate system (3857) where I want to have precision, let's say, on 1 decimal number.

DECLARE @g1 geometry = geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 3857); 
DECLARE @g2 geometry = geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180.0001)', 3857); 

Select @g1.STEquals(@g2)
-- returns 0/false

It there a way to manipulate those functions so STEquals would return 1/true ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rok
  • 451
  • 3
  • 21
  • Probably not, but maybe something functionally equivalent (no pun intended). What about `Select @g1.STBuffer(0.05).STContains(@g2)`? – Ben Thul Sep 28 '20 at 16:44
  • I think index won't work in this case if @g1 is a value in the table... – Rok Sep 29 '20 at 06:59
  • Nothing in your question says one or the other of the values is in a table. That said, you're right. But! You should be able to flip the comparison and still have it work. – Ben Thul Sep 29 '20 at 12:54
  • I agree with you, I should mention it. But still, I would like to hear like some "global", database-wise or table-wise solution, because it there would exist something like that, than I could sistematically prevent creating geometry like `LINESTRING (100 100, 100 100.0001)` which is topologically incorrect because of precision model. I have a feeling I will not get it and I will need to implement something by myself. – Rok Sep 29 '20 at 13:49
  • Sure. What I'm saying is that if `@g1` is in reality the table side of your comparison and `@g2` is a value you are considering inserting, change the comparison that I suggested to `@g2.STBuffer(0.05).STContains(@g1)`. That's a classic SARG-ability trick, which is to do any calculations on the scalar side of the comparison. In this case, that comparison should be able to use the spatial index on the table. – Ben Thul Sep 29 '20 at 15:10

0 Answers0