问题
I have the following query:
var nodes = DB.Nodes
.Where(x => x.Lon > 486400
&& x.Lon < 486600
&& x.Lat > 5025100
&& x.Lat < 5025300)
.Join(DB.RoadNodes, x => x.Id, y => y.NodeId, (x, y) => x);
This searches all the nodes in DB.Nodes
near a certain location, then it checks whether the node is a road junction by taking a join with DB.RoadNodes
; however, this takes several seconds which is slow.
It looks like I have to do two things here:
Optimize the
Where
part which takes~5
seconds on its own, I heard something about Spatial?Optimize the
Join
part which takes a remaining~15
seconds on its own, I need an index, right?
So I have two questions about this:
How can I do spatial storage and searching in SQL Server Compact Edition?
If this is unsupported, how do I work around this issue?
Which columns do I need to index for this query to work sufficiently?
It seems like indexing the NodeId of RoadNodes doesn't really improve the query.
Please note that I am restricted to SQL CE as I intend to run this on a Windows Phone 7.
Also node that I need to take an Unique()
from that, which makes the query slightly longer but I guess that shouldn't be an issue if the query itself runs fast. It's just that he join introduces double results, or should I do the Join in another way?
来源:https://stackoverflow.com/questions/9163533/how-do-i-efficiently-search-in-sql-ce-for-nearby-geographical-nodes-that-are-roa