I have an app that displays maps. I would like to add a feature where the user can tap a location and have it it display information about the nearest landmark.
By landmark, I mean I have a set of predefined objects related to the app with latitude/longitude coordinates.
The app is able to convert X/Y screen coordinates to latitude/longitude.
The app already calculates the distance between two latitude/longitude coordinates.
Therefore, I could, through brute force, run through the list of landmarks and find the closest.
However, knowing this is a problem many applications have to face, I ask if there is a better technique to find the closest "landmark" to a latitude/longitude than brute force? Some kind of transform?
Related
I am trying to create an application similar in UI to Sketchup. As a first step, I need to display the ground surface stretching out in all directions. What is the best way to do this?
Options:
Create a sufficiently large regular polygon stretching out in all directions from the origin. Here there is a possibility of the user hitting the edges and falling off the surface of the earth.
Model the surface of the earth as a sphere/spheroid. Here I will be limiting my vertex co-ordinates to very large values prone to rounding off errors. (Radius of earth is 6371000000 millimeter).
Same as 1 but dynamically extend the ends of the earth as the user gets close to them.
What is the usual practice?
I guess you would do neither of these, but instead use a virtual ground.
So you just find out, what portion of the ground is visible in the viewport and then create a plane large enough to fill that. With some reasonable maxiumum, which simulates the end of the line of sight aka horizon as we know it.
If I want to find all restaurants within a zip code, I can do a string search on the address, if I want to find all restaurants with 10 miles of a zip code, I need to do a location search. I have a database full of addresses and Geocodes should be no problem. But how do I compute the bounding box of an irregular shaped area, like a zip code, or city, or state or Metro Area?
Is there a tool around that does this? is this information for sale somewhere?
My initial solution is to create an estimate of the areas by searching for all addresses within them and deriving the simplest polygon that surrounds them and using that as a bounding box. However this seems a really brute force way to do this. Do I do this calculation for every city, state, and zip in my database and store it? How have other people solved this problem?
Companies such as Maponics have polygon data on neighborhoods, counties, cities, states, provinces, townships, etc. There may be other providers.
Many of these polygons have huge numbers of points, so you should either:
compute bounding boxes, or
precompute the zip, neighborhood, city, etc. identifier for each address, and index a search collection by these regions.
But why build your application by storing a database of places and computing geographic data on your own? You can partner with providers such as CityGrid; they provide APIs for places that can be searched by neighborhood, zip, etc.; you can use their data for free in your own local application.
If you happen to be using PostgreSQL for your database, you can use box(geometry) or a variation thereof to compute the bounding box for a geometry. You can also implicitly use the bounding box for a geometry in your SQL. For example (from Using PostGIS: Data Management and Queries):
SELECT road_id, road_name FROM roads WHERE roads_geom && ST_GeomFromText('POLYGON((...))',-1);
where && "tells whether the bounding box of one geometry intersects the bounding box of another".
To get the bounding box for a collection of geometries, you can first use Collect or Union to aggregate or combine all the geometries together.
Of course, if you are not using PostGIS, the functionality really comes from GEOS, which is the underlying library that PostGIS actually uses. The basic geometry functions can be used directly (from python for example) to do what you want.
I got my country lat/long boundaries from koordinates.com. Now I want to fill in the interior with dots.
Since the file I have is KML, I was thinking of converting the coordinates to cartesian using the NetTopologySuite.
I do not want a polygon overlay. I want to generate dots/coordinates for the polygons interior - ideally at a density of my choosing.
I have seen algorithms like this one, http://alienryderflex.com/polygon_fill/. Is there a library that will do this for me? Alternatively, can someone share code?
Ultimately, I will convert the dot coordinates back to lat/long and populate a globe like this one
http://code.google.com/p/webgl-globe/
I'm affraid GIS isn't my area of expertise, but I've got two ideas:
Generate a set of random points. You can use a Point-In-Polygon function to determine if you're points are in the right place.
You can use a rectangle grid of points and use a 'resolution' to determine how many points there will be and how close. You can offset the grid positions to make them look more random if you need to. You'll check if the point inside the bounding rectangle of your polygon is inside the polygon or not.
Notice that the webgl-globe example uses a grid of points(similar to point(2)) converted to spherical coordinates.
Both ideas is kind of similar, only the points distribution differs.
You can find a roughly related implementation I did using actionscript here,
but I would also suggest asking on the GIS site.
I have given the coordinates of 1000 triangles on a plane (triangle number (T0001-T1000) and its coordinates (x1,y1) (x2,y2),(x3,y3)). Now, for a given point P(x,y), I need to find a triangle which contains the point P.
One option might be to check all the triangles and find the triangle that contain P. But, I am looking for efficient solution for this problem.
You are going to have to check every triangle at some point during the execution of your program. That's obvious right? If you want to maximize the efficiency of this calculation then you are going to create some kind of cache data structure. The details of the data structure depend on your application. For example: How often do the triangles change? How often do you need to calculate where a point is?
One way to make the cache would be this: Divide your plane in to a finite grid of boxes. For each box in the grid, store a list of the triangles that might intersect with the box.
Then when you need to find out which triangles your point is inside of, you would first figure out which box it is in (this would be O(1) time because you just look at the coordinates) and then look at the triangles in the triangle list for that box.
Several different ways you could search through your triangles. I would start by eliminating impossibilities.
Find a lowest left corner for each triangle and eliminate any that lie above and/or to the right of your point. continue search with the other triangles and you should eliminate the vast majority of the original triangles.
Take what you have left and use the polar coordinate system to gather the rest of the needed information based on angles between the corners and the point (java does have some tools for this, I do not know about other languages).
Some things to look at would be convex hull (different but somewhat helpful), Bernoullies triangles, and some methods for sorting would probably be helpful.
I have a java applet that allows users to import a jpeg and world file from the local system. The user can then "click" draw lines on the image that was imported. Each endpoint of each line contains a set of X/Y and Lat/Long values. The XY is standard java coordinate space, the applet uses an affine transform calculation with the world file to determine the lat/long for every point on the canvas.
I have a requirement that allows a user to type a distance into a text field and use the arrow key to draw a line in a certain direction (Up, Down, Left, Right) from a single selected point on the screen. I know how to determine the lat/long of a point given a source lat/long, distance, and bearing.
So a user types "100" in the text field and presses the Right arrow key a line should be drawn 100 feet to the right from the currently selected point.
My issue is I don't know how to convert the distance( which is in feet ) into the distance in pixels. This would then tell my where to plot the point.
tcarobruce,
You are correct. The inverse transform algorithm is what I needed. Since I use java I was able to replace my "home made" transform algorithm with the java.awt.AffineTransform object which has an inverse transform function.
This seems to have solved my issue.
Thanks.
I guess you are certain your users are always uploading a raster image that is in the lat/lon wgs84 projection? Because in that case you can set a fixed coordinate transformation.
If you consider ever digitizing images from other sources with other projections, you might want to take a look at the open source geotools library: http://www.geotools.org/