How to implement measure functionality on map - ruby-on-rails

I'd like to implement Measure functionality on openstreet map. Measure is adding two points on a map and find the distance between those points.
For that I referred https://github.com/danstowell/openstreetmap-website/commits/jsrouting-contextmenu
It will work fine except water area/region on openstreet map. In my case I am rendering my own maps on my project, so this is not work for me.
I am using below Environment:
Environment : Rails 4 and Ruby 2
Anyone know about it?
How do I implement measure functionality on my map?
Is there any other ways to implement this?

Not sure on the specifics relating to OSM, however assuming that you can convert the points to geodetic points then you can use the haversine or vincenty formulas to get the great circle distance:
http://www.movable-type.co.uk/scripts/latlong.html
OSM uses a spherical Mercator projection. If all you have are 2d Cartesian (projected) coordinates then you will need to convert these to geodetic coordinates.
If you also need to take into account terrain then this gets more complex but maybe OSM provides something for this that gives heights along a transect line.

Related

How do I use a web mercator projection map for SCNMaterial on an SCNShere geometry?

I have a simple globe view in my app. Previously we were using WhirlyGlobe, but have opted to use SceneKit instead. Everything works great and we are happy with it EXCEPT we used map tiles in Whirly Globe and the do not work (as far as I can tell) in SceneKit. We want to use that map (tiled, split or as one file) on an SCNSphere geometry.
I copied the satellite map that Apple uses in their documentation and it looks right, but is not the map we need. Our map is in web/sphere mercator projection and it looks bad in SceneKit on my sphere.
I do not* know what the 2x1 projection Apple is using is called, so JUST that information might be enough for me to find the solution.
I do now:
Equirectangular - RIGHT after I posted of course.
Also known as Platte Carre (per Hal Mueller's comment)
An export of our map in the web mercator projection is 1x1. Just squishing it in the vertical axis does not work (SceneKit does this automatically anyway).
I can convert the file programmatically, using a tool or some hybrid if needed.
If needed, I can provide thumbs of the map skins.
If you already have images and need to reproject them (say from Mercator to Plate Carree/Equirectangular), take a look at GDAL (http://www.gdal.org). In addition to the format conversions, it contains a reprojection library. GDAL runs on most systems, and can be used from the command line or bundled into other programs.

Can I draw great circle segment (geodesic) lines in Openlayers 3?

I want to plot lines between (distant) points on an Openlayers 3 map (which uses Open Street Map tiles). I want the lines to be seen as curves, as with flight paths, since they should take the shortest real world surface path: a geodesic (a great circle segment).
Is this possible?
Would I need to interpolate the points along the geodesic (how?) and plot a bunch of line segments, or is there an easier way? Is there something built in I can't find, or a library for it?
Looking at OL3's Flight Animation Example, it appears to be possible using the arc.js plugin: “A great circle arc between two airports is calculated using arc.js and then the flight paths are animated with postcompose. The flight data is provided by OpenFlights (a simplified data set from the Mapbox.js documentation is used).”

"cache" cvWarpPerspective map

I'm using the same matrix in cvWarpPerspective for several frames. Now I noticed that a lot of time seems to be spent creating maps for cvRemap. I would love to
cache the Maps that are created for cvRemap
maybe even combine that map with an undistortion map
I can't figure out how to create the maps from my 3x3 matrix myself quickly.
Thanks!
There is no OpenCV function to create the maps for you, but I did the same by copying the code from warpPerspective (the map creation part)
It's easy because warpPerspective creates the maps, then calls remap() with them.
In order to optimize memory usage, warpPerspective calculates the maps for small blocks - you have to modify it to create the full map.
As for combining it with distortion, you have to write your custom map generator - you'll need some math there.

Refining Disparity maps?

Can anyone tell me of a method to refine disparity maps? I am trying to generate the disparity map of a face but the features like eyes, nose ,lips etc are not clear.How can I refine it to make it look better?
Take a look at
https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/stereo_match.cpp
there are some bm.state parameters (about line 197 - 207) that can be tweaked, we connected those values to some sliders so we could look at the result at the same time as we tweaked the values. you can also try with some different values for "blocksize". you can also try with some different distances between your cameras, if the cameras are too far apart, you will get poor / no results on close distances.
I assume that your code is similar to the example above.
Use stereoSGBM I am using it and you can use trackbars to tweak the parameters study the refernece of opencv and then manipulate each parameter based on the effect it has on your image eg:P1 P2 make it smoother etc

Will treating MKCoordinateRegion like a rectangle come back to haunt me?

Background: I'm build a series of location-based apps that make heavy use of maps. These maps are annotated with locations fetched from a server, to which I pass regions of the map I need data for (defined as a lat/long and a latDelta/longDelta, much like MKCoordinateRegion, but with a different location of the reference coordinate). I'm writing a bunch of helper methods/classes to use when managing these regions. Compatibility with iOS 3.x is required (meaning MKMapRect is out).
Question: Am I setting myself up for failure by treating MKCoordinateRegions like rectangles? Specifically, I'm treating their geometry as if it was that of a rectangle, assuming they have basically the same properties as rectangles. I've implemented several methods that mirror CGRect's helper methods, such as MKCoordinateRegionUnion/Inset/Outset, etc, and they all pass my unit tests, but I'm starting to question if my underlying assumptions are correct. I know in fact that MKCoordinateRegion does not represent a geometric rectangle, but rather a region of a spherical surface bound by two sets of parallel planes, perpendicular to each other (bonus points if somebody can clue me in on a better term for that).
I'm not experiencing any anomalies yet, but since many apps will be reliant on my understanding of the geometry, I'd rather figure out now if I'm going down the wrong path. The fact that I slept through most of the classes in school dealing with 3d radial geometry doesn't give me much confidence that my intuition is correct.
If you are taking into account the equator, prime meridian and dateline edge cases, I think you will be ok.
Alternatively, you could develop your own MKMapRect like rects. Troy Brant has a great blog post about the how the rects are formed:
http://troybrant.net/blog/2010/01/mkmapview-and-zoom-levels-a-visual-guide/
While the blog post is mainly about zoom levels, all the information there can be used to build up your own map rect library.
As for areas bounded by great circles on the surface of a sphere, they are called spherical polygons. So I guess you could just call them spherical rectangles.

Resources