1.Spatial index does not work(Query cost 10s)
SELECT geomFROM cj_pl_l WHERE geom.MakeValid ( ).STWithin (geometry :: STGeomFromText
('POLYGON ((……))', 4547 ).MakeValid ()) =1
2.Spatial index work(Query cost 2s,I save above-mentioned polygon to temp table[testGeom])
select b.* from testGeom a,cj_pl_l b where b.geom.STWithin(a.geom)=1
If I want Condition1 the Spatial Index to work, how should I solve?
Thanks!
MakeVald()call on the table side of the query is the culprit. Why is that necessary? Do you have invalid data in your table?System.ArgumentException: at Microsoft.SqlServer.Types.SqlGeometry.ThrowIfInvalid() at Microsoft.SqlServer.Types.SqlGeometry.STWithin(SqlGeometry other)When I use other table and don't useMakeVald()method,the sql not thorw error,but the Spatial Index also don't work.MakeValid()against the data in your table, you have invalid data. If suggest fixing the data (something likeupdate yourTable set yourColumn = yourColumn MakeValid().