Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. distance between points

distance between points

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabaseperformancequestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    suzyb
    wrote on last edited by
    #1

    I am reading a list of x and y pairs from a database, creating points from them and adding them to a collection. Before I add these points to the collection however I would like to be able to check if there already is a point in the collection that is within a certain distance from the point I am about to add. Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? Thanks If I had a better memory I would remember more.

    J C R 3 Replies Last reply
    0
    • S suzyb

      I am reading a list of x and y pairs from a database, creating points from them and adding them to a collection. Before I add these points to the collection however I would like to be able to check if there already is a point in the collection that is within a certain distance from the point I am about to add. Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? Thanks If I had a better memory I would remember more.

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      I do not know of any functions that will accomplish this in asp.net But technically speaking, there isn't really any way to programatically check this without actually having to compare with all existing points. Jon G www.Gizmocoder.com

      1 Reply Last reply
      0
      • S suzyb

        I am reading a list of x and y pairs from a database, creating points from them and adding them to a collection. Before I add these points to the collection however I would like to be able to check if there already is a point in the collection that is within a certain distance from the point I am about to add. Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? Thanks If I had a better memory I would remember more.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Suzanne Boyle wrote: Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? The ASP.NET framework does not have this kind of support, neither does the "greater" .NET Framework. If you need to do this quickly and efficiently you will need to implement a Quadtree algorithm. See the link below for details. However, if your set of points is small then you may be just as well to implement a brute force, check all previous instances, method as you have already suggested. http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u37.html[^]


        "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

        S 1 Reply Last reply
        0
        • C Colin Angus Mackay

          Suzanne Boyle wrote: Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? The ASP.NET framework does not have this kind of support, neither does the "greater" .NET Framework. If you need to do this quickly and efficiently you will need to implement a Quadtree algorithm. See the link below for details. However, if your set of points is small then you may be just as well to implement a brute force, check all previous instances, method as you have already suggested. http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u37.html[^]


          "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

          S Offline
          S Offline
          suzyb
          wrote on last edited by
          #4

          Colin Angus Mackay wrote: if your set of points is small The points are actually the locations of stores on a map and there aren't too many at the moment. Colin Angus Mackay wrote: If you need to do this quickly and efficiently you will need to implement a Quadtree algorithm :eek: I hope they never open enough stores for it to come to this. If I had a better memory I would remember more.

          C 1 Reply Last reply
          0
          • S suzyb

            Colin Angus Mackay wrote: if your set of points is small The points are actually the locations of stores on a map and there aren't too many at the moment. Colin Angus Mackay wrote: If you need to do this quickly and efficiently you will need to implement a Quadtree algorithm :eek: I hope they never open enough stores for it to come to this. If I had a better memory I would remember more.

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            * dreamy look * GIS applications - Maps - point-in-polygon algorithms.... 'twas my staple development work between 1995 to 2002.


            "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

            1 Reply Last reply
            0
            • S suzyb

              I am reading a list of x and y pairs from a database, creating points from them and adding them to a collection. Before I add these points to the collection however I would like to be able to check if there already is a point in the collection that is within a certain distance from the point I am about to add. Is there a way to do this without having to loop through the existing collection and check all the points individually or, if not, if you have 2 points in asp.net can you find the distance between them without having to check the x and y individually? Thanks If I had a better memory I would remember more.

              R Offline
              R Offline
              Roger Wright
              wrote on last edited by
              #6

              Interesting question... There's no built-in function I know about to do this, and looping through all the records checking each distance is going to be dodgy. Finding the distance between points is simple enough: d=sqr((X2 - X1)^2 + (Y2 - Y1)^2) but using asp.net to calsulate this on the fly for every point in the database is awfully tedious. A possible improvement would be to maintain a table of precalculated distances between existing points. When considering a new point it would then only be necessary to calculate the distance once - from the origin to the target point - then query the table for any lesser value. If the new point is subsequently added, the distance table would have to be recalculated, but this can be done in a stored procedure on the database server. "My kid was Inmate of the Month at Adobe Mountain Juvenile Corrections Center" - Bumper Sticker in Bullhead City

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups