How do I efficiently search for all the landmarks within a range of a certain landmark
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am trying to start with a geo search project that will find all landmarks in the 10 km/miles (not important for this story) of a particular landmark.
So for example, lets say I have a DB of a 1,000,000 landmarks. In order to find all landmarks in 10 miles range of a landmark with certain coordinates, I would have to calculate a distance between a landmark from my search and 1,000,000 landmarks.
Is there a better way to do that?
Alternative I was thinking is to categorize landmarks such as country, region, city, neighborhood, business, historical etc in such a way that business can be part of a neighborhood or city. City is a part of a region or a country etc. This can narrow a list of calculations, but is still looks like a lot of work do to in order for search to be fast and accurate.
Could google maps API help in anyway?
c# application-design geolocation google-maps
add a comment |Â
up vote
1
down vote
favorite
I am trying to start with a geo search project that will find all landmarks in the 10 km/miles (not important for this story) of a particular landmark.
So for example, lets say I have a DB of a 1,000,000 landmarks. In order to find all landmarks in 10 miles range of a landmark with certain coordinates, I would have to calculate a distance between a landmark from my search and 1,000,000 landmarks.
Is there a better way to do that?
Alternative I was thinking is to categorize landmarks such as country, region, city, neighborhood, business, historical etc in such a way that business can be part of a neighborhood or city. City is a part of a region or a country etc. This can narrow a list of calculations, but is still looks like a lot of work do to in order for search to be fast and accurate.
Could google maps API help in anyway?
c# application-design geolocation google-maps
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to start with a geo search project that will find all landmarks in the 10 km/miles (not important for this story) of a particular landmark.
So for example, lets say I have a DB of a 1,000,000 landmarks. In order to find all landmarks in 10 miles range of a landmark with certain coordinates, I would have to calculate a distance between a landmark from my search and 1,000,000 landmarks.
Is there a better way to do that?
Alternative I was thinking is to categorize landmarks such as country, region, city, neighborhood, business, historical etc in such a way that business can be part of a neighborhood or city. City is a part of a region or a country etc. This can narrow a list of calculations, but is still looks like a lot of work do to in order for search to be fast and accurate.
Could google maps API help in anyway?
c# application-design geolocation google-maps
I am trying to start with a geo search project that will find all landmarks in the 10 km/miles (not important for this story) of a particular landmark.
So for example, lets say I have a DB of a 1,000,000 landmarks. In order to find all landmarks in 10 miles range of a landmark with certain coordinates, I would have to calculate a distance between a landmark from my search and 1,000,000 landmarks.
Is there a better way to do that?
Alternative I was thinking is to categorize landmarks such as country, region, city, neighborhood, business, historical etc in such a way that business can be part of a neighborhood or city. City is a part of a region or a country etc. This can narrow a list of calculations, but is still looks like a lot of work do to in order for search to be fast and accurate.
Could google maps API help in anyway?
c# application-design geolocation google-maps
c# application-design geolocation google-maps
asked 2 hours ago
Dario Granich
19018
19018
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago
add a comment |Â
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
Since SQL Server 2008, there is a geography data type which stores locations (lat/lon pairs) and makes it easy for you to write location-related queries.
There is an existing StackOverflow answer that discusses this in-depth.
A basic query to find the nearest 7 items:
USE AdventureWorks2012
GO
DECLARE @g geography = 'POINT(-121.626 47.8315)';
SELECT TOP(7) SpatialLocation.ToString(), City FROM Person.Address
WHERE SpatialLocation.STDistance(@g) IS NOT NULL
ORDER BY SpatialLocation.STDistance(@g);
A basic query to find everything within 100m (second answer to the question)
-- Get the center point
DECLARE @g geography
SELECT @g = geo FROM yourTable WHERE PointId = something
-- Get the results, radius 100m
SELECT * FROM yourTable WHERE @g.STDistance(geo) <= 100
add a comment |Â
up vote
2
down vote
Use a database with support for GIS (geographic information systems) queries. Most databases support this outright or have extensions, but the details will be database-specific (in their answer, Flater shows the syntax for SQL server).
If you need to implement such queries within your application, you can implement a data structure that allows spatial queries, e.g. a k-d Tree. This is like a binary search tree, except that each level of the tree partitions on a different coordinate dimension. This allows you to restrict the search to a smaller set of feasible candidates. Effectively, you translate your search “10km radius†into bounds for each coordinate dimension, and tighten the bounds as you recurse into the tree.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Since SQL Server 2008, there is a geography data type which stores locations (lat/lon pairs) and makes it easy for you to write location-related queries.
There is an existing StackOverflow answer that discusses this in-depth.
A basic query to find the nearest 7 items:
USE AdventureWorks2012
GO
DECLARE @g geography = 'POINT(-121.626 47.8315)';
SELECT TOP(7) SpatialLocation.ToString(), City FROM Person.Address
WHERE SpatialLocation.STDistance(@g) IS NOT NULL
ORDER BY SpatialLocation.STDistance(@g);
A basic query to find everything within 100m (second answer to the question)
-- Get the center point
DECLARE @g geography
SELECT @g = geo FROM yourTable WHERE PointId = something
-- Get the results, radius 100m
SELECT * FROM yourTable WHERE @g.STDistance(geo) <= 100
add a comment |Â
up vote
4
down vote
Since SQL Server 2008, there is a geography data type which stores locations (lat/lon pairs) and makes it easy for you to write location-related queries.
There is an existing StackOverflow answer that discusses this in-depth.
A basic query to find the nearest 7 items:
USE AdventureWorks2012
GO
DECLARE @g geography = 'POINT(-121.626 47.8315)';
SELECT TOP(7) SpatialLocation.ToString(), City FROM Person.Address
WHERE SpatialLocation.STDistance(@g) IS NOT NULL
ORDER BY SpatialLocation.STDistance(@g);
A basic query to find everything within 100m (second answer to the question)
-- Get the center point
DECLARE @g geography
SELECT @g = geo FROM yourTable WHERE PointId = something
-- Get the results, radius 100m
SELECT * FROM yourTable WHERE @g.STDistance(geo) <= 100
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Since SQL Server 2008, there is a geography data type which stores locations (lat/lon pairs) and makes it easy for you to write location-related queries.
There is an existing StackOverflow answer that discusses this in-depth.
A basic query to find the nearest 7 items:
USE AdventureWorks2012
GO
DECLARE @g geography = 'POINT(-121.626 47.8315)';
SELECT TOP(7) SpatialLocation.ToString(), City FROM Person.Address
WHERE SpatialLocation.STDistance(@g) IS NOT NULL
ORDER BY SpatialLocation.STDistance(@g);
A basic query to find everything within 100m (second answer to the question)
-- Get the center point
DECLARE @g geography
SELECT @g = geo FROM yourTable WHERE PointId = something
-- Get the results, radius 100m
SELECT * FROM yourTable WHERE @g.STDistance(geo) <= 100
Since SQL Server 2008, there is a geography data type which stores locations (lat/lon pairs) and makes it easy for you to write location-related queries.
There is an existing StackOverflow answer that discusses this in-depth.
A basic query to find the nearest 7 items:
USE AdventureWorks2012
GO
DECLARE @g geography = 'POINT(-121.626 47.8315)';
SELECT TOP(7) SpatialLocation.ToString(), City FROM Person.Address
WHERE SpatialLocation.STDistance(@g) IS NOT NULL
ORDER BY SpatialLocation.STDistance(@g);
A basic query to find everything within 100m (second answer to the question)
-- Get the center point
DECLARE @g geography
SELECT @g = geo FROM yourTable WHERE PointId = something
-- Get the results, radius 100m
SELECT * FROM yourTable WHERE @g.STDistance(geo) <= 100
answered 2 hours ago
Flater
4,265716
4,265716
add a comment |Â
add a comment |Â
up vote
2
down vote
Use a database with support for GIS (geographic information systems) queries. Most databases support this outright or have extensions, but the details will be database-specific (in their answer, Flater shows the syntax for SQL server).
If you need to implement such queries within your application, you can implement a data structure that allows spatial queries, e.g. a k-d Tree. This is like a binary search tree, except that each level of the tree partitions on a different coordinate dimension. This allows you to restrict the search to a smaller set of feasible candidates. Effectively, you translate your search “10km radius†into bounds for each coordinate dimension, and tighten the bounds as you recurse into the tree.
add a comment |Â
up vote
2
down vote
Use a database with support for GIS (geographic information systems) queries. Most databases support this outright or have extensions, but the details will be database-specific (in their answer, Flater shows the syntax for SQL server).
If you need to implement such queries within your application, you can implement a data structure that allows spatial queries, e.g. a k-d Tree. This is like a binary search tree, except that each level of the tree partitions on a different coordinate dimension. This allows you to restrict the search to a smaller set of feasible candidates. Effectively, you translate your search “10km radius†into bounds for each coordinate dimension, and tighten the bounds as you recurse into the tree.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Use a database with support for GIS (geographic information systems) queries. Most databases support this outright or have extensions, but the details will be database-specific (in their answer, Flater shows the syntax for SQL server).
If you need to implement such queries within your application, you can implement a data structure that allows spatial queries, e.g. a k-d Tree. This is like a binary search tree, except that each level of the tree partitions on a different coordinate dimension. This allows you to restrict the search to a smaller set of feasible candidates. Effectively, you translate your search “10km radius†into bounds for each coordinate dimension, and tighten the bounds as you recurse into the tree.
Use a database with support for GIS (geographic information systems) queries. Most databases support this outright or have extensions, but the details will be database-specific (in their answer, Flater shows the syntax for SQL server).
If you need to implement such queries within your application, you can implement a data structure that allows spatial queries, e.g. a k-d Tree. This is like a binary search tree, except that each level of the tree partitions on a different coordinate dimension. This allows you to restrict the search to a smaller set of feasible candidates. Effectively, you translate your search “10km radius†into bounds for each coordinate dimension, and tighten the bounds as you recurse into the tree.
answered 1 hour ago


amon
80.5k20152238
80.5k20152238
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f381001%2fhow-do-i-efficiently-search-for-all-the-landmarks-within-a-range-of-a-certain-la%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You could probably eliminate a good many simply by performing a quick Manhattan distance calculation and then performing a second filter afterwards to exclude landmarks which are within a 10km square but are outside the 10km radius.
– Neil
1 hour ago