-6

I have a list of all intersections in a city with coordinates. I am trying for an end result of a list of all the intersections in the order they appear. For example, if I put in Alameda & 5th - I want to see all cross streets if I keep going down Alameda (ex Alameda & 6th, Alameda & 7th, etc. ) However, they aren't all numbered streets.

I need the final format to be text-based - no visual mapping. I'm quite stumped on how to start and hoping for some direction.

SimplePi
  • 95
  • 1
  • 4
  • 15

3 Answers3

0

Solution 1:

I would recommend using the longitude and latitude and ordering it by that. For instance, you can tell if a street is "below" another if the latitude of it is less than the other one. That'll probably get most of them in the right spot.

You can then manually double check them if there's not too much data.

Solution 2:

If there's not that much data, you might want to simply do it by hand. This isn't very efficient, but it could save your time (again, depending on the amount of data you have).

Timmy
  • 4,098
  • 2
  • 14
  • 34
Pratyush
  • 108
  • 8
0

It sounds like you need to just create a relational database. My suggestion would be to get familiar (if you are not already) with Microsoft access. I can't think of any other tool that would suite you better.

All you would have to do is paste the list of intersections you already have into a table, create another table for the cross streets then, just make them relational. After that create your queries to spit out whatever data you want.

You will also have the opportunity to create a sort order of the cross streets relative to each intersection.

If you haven't used Access before, there is a bit of a learning curve but it's not like coding. Just watch a few youtube videos or invest in a Udemy coarse. I created a very similar database within a couple of days myself.

Sceptersax
  • 83
  • 1
  • 9
0

I am trying a pseudo implementation based on the limited information you have given.

  1. Let's have Street and Intersection classes and some Database that can be queried for a list of objects with where filters (think of it as some SQL wrapper).

  2. Now, we need a sorting algorithm for the intersections. The problem here is, that we cannot know the physical order based on the given information. Roads may go in curves, tunnels and what not.
    So the next best thing we can do is guessing the order by evaluating the distance. Note that this will only work in a Manhattan type map layout without curves.
    We will arbitrarily assume the first intersection would be the one with the lowest coordinate value.
    From there, we search all our streets remaining intersections for the closest to the previous.

Again, please be aware, that this algorithm is a guess based on the given information. However, the general implementation pattern should still be usable for more sophisticated algorithms or the incorporation of additional information.

Please see my implementation in pseudo-code:

Database {
   allIntersections {...}
   allStreets {...}
}


Street {
  id: String
  name: String

  intersections() -> [Intersection] {
    return Database.allIntersections.where(street1 == self || street2 == self)
  }

  lowestIntersection() -> Intersection {
    lowestIntersection: Intersections().first
    for intersection in Intersections() {
      currentDistance = intersection.distanceTo(Coordinate(0,0))
      if (currentDistance < lowestIntersection.distanceTo(Coordinate(0,0)) {
        lowestIntersection = intersection
      }
    }
    return lowestIntersection
  }


  // the sort algorithm based on proximity
  sortedIntersections() -> [Intersection] {
    sorted = [lowestIntersection()]
    remaining = intersections() - sorted
    while remaining.count > 0 {
      closest = sorted.last.closestIntersection(remaining)
      remaining.remove(closest)
      sorted.add(closest)
    }
    return sorted
  }
}

Coordinate {
  lat: Float
  long: Float
}

Intersection {
  street1: Street
  street2: Street
  coordinate: Coordinate

  distanceTo(other: Coordinate) -> Float {
    return sqrt(pow2(coordinate.lat - other.lat) + pow2(coordinate.long - other.long))
  }

  closesIntersection(others: Intersection) -> Intersection {
    closesIntersection: others.first
    for intersection in others {
      currentDistance = intersection.distanceTo(self.coordinate)
      if (currentDistance < closesIntersection.distanceTo(self.coordinate) {
        closesIntersection = intersection
      }
    }
    return closesIntersection
  }
}

I hope this helps. For a more detailed answer, please provide more information like example data.

de.
  • 7,068
  • 3
  • 40
  • 69