How do I efficiently search for all the landmarks within a range of a certain landmark

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question





















  • 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














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?










share|improve this question





















  • 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












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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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





share|improve this answer



























    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.






    share|improve this answer




















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "131"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      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






























      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





      share|improve this answer
























        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





        share|improve this answer






















          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





          share|improve this answer












          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          Flater

          4,265716




          4,265716






















              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.






              share|improve this answer
























                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.






                share|improve this answer






















                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  amon

                  80.5k20152238




                  80.5k20152238



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      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













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery