Calculate distance in openstreetmap with josm? - java

I'm new to openstreetmap. I want to use openstreetmap in a java application to get distance between two points. And also to find more information about a particular road, etc.
I discovered JOSM, but all I need is to calculate distance between two points in a road, also get some more information about that road, when necessary. Anybody knows which class/methods in JSOM will help me do that? Or is there any other simpler method/api to do that with OpenStreetMap?

Related

Convert lat/long to US State

I have access to a list of lat/long coordinates, and I want to know (roughly) the US State these coordinates are located in. I can do with loss of precision, but I can't rely on external libraries or API. I can also add a database of locations in my code.
What is a reasonable way to do this?
I thought about 3 possibilities:
Represent each state by a single point at its center, then do a nearest-neighbour search
Represent each state by points located at cities in the state, then do a nearest-neighbour search (with much more points)
Represent each state by a simple bounding box, then use some algorithm to query which bounding box my point belongs to
What do you think is best? I would tend to think about solution 3, but I can't find a list of coarse "bounding boxes" for US states
I made a little search and find out a proper solution for what you are looking for with a dataset of bounding box.
Answer on StackOverflow: LINK
Dataset: LINK
Algorithm to use(implement): LINK
So yes, the proper way to implement it's using the solution 3 with the given dataset.
Hope it helps :)
Will not work, consider
Has a high likelihood to not work for at least some states. Consider states with towns/cities more clustered to the middle, against states with towns/cities clustered to the edge.
Will not work (these were supposed to be 90 degree angles, perfect squares, but drawing with a mouse is hard :) )
If you want to do this even vaguely accurately you will need some shape data which defines the boundaries between states. You will then need an algorithm which can determine whether a point is within an irregular polygon
See List of the United States (US) state boundaries / borders as latitude/longitude pairs for geofence?

Trilateration example in java

I am currently working on a program that utilizes RSSI to determine location based on signal strength. Does anybody know where a working java example is of trilateration? I couldn't find any online.
The program will basically need to take in 3 distances, which are the distances derived from the RSSI's and then the latitude and longitude of the three points and then determine the user's location using 2 dimensional trilateration (I'm ignoring the height of each beacon for now).
I saw a Python one on here, but I don't know Python well enough to understand it.
For future reference for anybody with the same problem.
I just used the link Girish provided.
http://code.google.com/p/talking-points-3/source/browse/trunk/WifiPosition/src/TalkingPoint/thejoo/Trilateration.java?r=109
but be aware you have to account for when coordinates are coplanar as this isn't accounted for in the code.

how to calculate all points(longitude,latitude) within a given radius from given point (longitude,latitude)?

I have a given point (longitude,latitude) and I want to get all the points ranges that comes lets say 5 miles radius in given point?
I'm just guessing here, but I think you'll need to find a different approach. If you're trying to do something like Foursquare, Google Maps, etc where it finds places within a 5-mile radius of your current location, I think you'll find that these services don't calculate all the points in that radius and then match them up to places at those points.
There would probably be some smarts behind the code that do something like this...
Get the users current location
Find the suburb (or failing that, find the city) that the current location exists in. Also find all the surrounding suburbs adjacent to this one.
Find all the places within those suburbs, and calculate how far they are away from the current user location
This kind of process is one potential method that could be employed by these services. This deals with small subset of place comparisons, which is relatively quick to perform. Also, places on a map usually have a suburb/city associated with them anyway, so database lookups for places would be rather quick, as there would be an index that involves the suburb.
If you're aim is to do something like this, I would try to figure out a different way to compare points rather than simply trying to calculate everything in your radius.
And of course, there would also be plenty of specific algorithms for calculating this better, but that's not my area of expertise, and would be better suited to another forum. I'm not trying to say that this is the best way to do it, but there's plenty of other ways to do it that rely on known location data which would be quicker and smarter than your suggested requirement.

Coding a simulation model

I have to do this simulation model but I don't know how to start it and where to start it. i asked my supervisor about this , he also not have a clue about this. so I'm asking your opinion.
Here is what I have to do.
I have to simulate GSM signal strength from area to area in a simple map model.
I have to show the user location and when changing the user location from one place to another which tower gives the mobile client the GSM signals it require
I'm not asking to code this or something guys, I'm just asking to show me the way to do this?
Any tutorials regarding this, your knowledge to sort out the things would be very helpful.
I have a knowledge in Java also.
Regards,
Rangana
If it's just a simulation, it can be faked quite easily (unless I'm misunderstanding what's required).
Create your map model in whichever format you need to. This might be using Google/Bing maps API, or a custom map.
Create a list of GPS coordinates and traverse through them to simulate the user moving around the map.
Calculate the distance between the user and each tower (could use the Euclidean distance) and determine the strength of the the GSM at an given point. I'm not going to explain how you could calculate such a value, but it should be pretty easy.
Without more specific information, it's pretty difficult to give any more detail. Is this part of a university project?

Convert a list java.awt.geom.Point2D to a java.awt.geom.Area

I have a set of points that i want to turn into a closed polygon in Java. I'm currently trying to use java.awt.geom.Point2D and java.awt.geom.Area but can't figure out how to turn a group of the points into an Area.
I think I can define a set of Line2Ds based on the points and then add those to the Areas, but that's a lot of work and I'm lazy. So is there an easier way to go.
The problem is I have a list of lat/lon coordinates and want to build up an area that I can use for hit testing.
Non-core Java libraries are a possibility as well.
Update, I looked at using java.awt.Polygon but it only supports ints and I'm operating with doubles for the coordinates.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4077518
Hear that, "customer"? You should be using GeneralPath, even though the absence of Polygon2D since the late 1990s is an obvious monster-truck-sized hole in the API.
If you are actually working with Geodetic lat/lon values, you can actually use OpenMap to do some of this work. I just spent some time using the Geo class in that API to bounce an object around an area defined by a polygon of lat/lon points. There are intersection calls and everything and all of the math is done spherically so that the points are more correct as far as projections go.
The simplest (and laziest) thing to do is to create a bounding box for the points from the maximum and minimum of the X, Y ordinate values.
If you need a closer fit then rather than devise your own algorithm, this might be a good place to start:

Categories