Does anyone know algorithm of MKMapPointForCoordinate function in ObjectiveC MapKit - objective-c

MapKit has function MKMapPointForCoordinate, It accept lat lng as argument and return point x,y.
https://developer.apple.com/library/prerelease/ios/documentation/MapKit/Reference/MapKitFunctionsReference/index.html
lat = 59.90738808515509
lng = 10.724523067474365
if we pass above lat, lng then function return
x = 142214284, y = 78089986
I check with lag lng wot UTM but it gives different result
http://www.latlong.net/lat-long-utm.html

MKMapPointForCoordinate doesn't return UTM Coordinates.
Coordinates refer to a position on the earth (a pseudo-sphere), but sometimes you need to do calculation refering to a 2D map (much simpler) and then convert again to coordinates. This is the goal of the conversion.
So, the MKMapPoint struct returned by MKMapPointForCoordinate is a 2D representation of the coordinates, but it doesn't match any standard known.
At this link: https://developer.apple.com/library/prerelease/ios/documentation/MapKit/Reference/MapKitDataTypesReference/index.html#//apple_ref/doc/c_ref/MKMapPoint
in the MKMapPoint documentation, you can read:
The actual units of a map point are tied to the underlying units used
to draw the contents of an MKMapView, but you should never need to
worry about these units directly. You use map points primarily to
simplify computations that would be complex to do using coordinate
values on a curved surface.
EDIT
for Coordinates-UTM Conversion in a previous project I used this Open Source Code

Related

How to fill a line in 2D image along a given radius with the data in a given line image?

I want to fill a 2D image along its polar radius, the data are stored in a image where each row or column corresponds to the radius in target image. How can I fill the target image efficiently? Such as with iradius or some functions? I do not prefer a pix-pix operation.
Are you looking for something like this?
number maxR = 100
image rValues := realimage("I(r)",4,maxR)
rValues = 10 + trunc(100*random())
image plot :=realimage("Ring",4,2*maxR,2*maxR)
rValues.ShowImage()
plot.ShowImage()
plot = rValues.warp(iradius,0)
You might also want to check out the relevant example code from the F1 help documentation of GMS itself:
Explaining warp a bit:
plot = rValues.warp(iradius,0)
Assigns values to plot based on a value-lookup in rValues.
For each pixel in plot a coordinate position in rValues is computed, and the value is simply looked up. If the computed coordinate is non-integer, bilinear interpolation between the 4 closest points is used.
In the example, the two 'formulas' for the coordinate calculation are simple x' = iradius and y' = 0 where iradius is an expression computed from the coordinate in plot, for convenience.
You can feed any expression into the parameters for warp( ) and the command is closely related to just using the square bracket notation of addressing values. In fact, the only difference is that warp performs the bilinear interpolation of values instead of truncating the coordinates to integer values.

Difficulties understanding MapKit Coordinate System

I read the apple docs
"A map point is an x and y value on the Mercator map projection"
A point is a graphical unit associated with the coordinate system of a UIView
What is the difference logically between a Point and a MKPoint?
I obviously need CGPoint to display something on the screen.
So why does MapKit need MKMapPoint?
The fact that both the CGPoint and MKMapPoint structs happen to store two floating-point values named x and y is irrelevant.
They are given different names because they logically deal with different coordinate systems, transformations, ranges and scales.
A 2D world map needs a large, fixed coordinate system that allows a latitude and longitude to be converted to a fixed point on the map regardless of what portion is currently being displayed on the screen.
The range of MKMapPoint values are large since they need to represent the world's coordinates at a high-enough resolution (well beyond screen sizes).
However, you don't exactly need to care about the actual values of an MKMapPoint. Occasionally, you may need to convert a CLLocationCoordinate2D to an MKMapPoint (or the other way around) but you don't need to worry about those values nor should you store them (the docs recommend not doing this since the internal projection calculations to convert a latitude and longitude to a 2D projection may change between iOS releases).
Your usage of an MKMapPoint is only on the basis that you are dealing with the map's 2D projection independent of the device's screen size or what portion of the map is currently displaying.
I obviously need CGPoint to display something on the screen.
Yes but when adding annotations or overlays, you generally deal with CLLocationCoordinate2D values and let the map view do the conversion as needed.
MKMapPoint is a geographical point - projectively converted latitude and longitude. On the screen you have some bounded view containing your mapView. And you need to convert your geographical position (coord) to the CGPoint on your mapView
CLLocationCoordinate2D coord;
coord.latitude = location.latitude.doubleValue;
coord.longitude = location.longitude.doubleValue;
MKMapPoint point = MKMapPointForCoordinate(coord);
CGPoint cgpoint = [mapView convertCoordinate:coord toPointToView:mapView];

Latitude and longitude

Actually I have the decimal values of latitude and longitude.
In a 2d referential, are those values the x an y coordenates?
example :
in a position P
latitude = 41.15 longitude = -8.64
So, in a 2d dimension P is defined by (41.15,-8.64) ?
Thanks
No, its exactly opposite:
The coordinate (lat, lon) corresponds to the pair (y,x)
So when passinge lat, lon to mathematical routines, like point in polygon calculations
pass in order (lon, lat).
longitude raises parallell to the aequator, which corresponds to our x achsis direction we normally use in cartesian (x,y) systems.
Unfortunatley for historical reasons, the latitude is often written before longitude. (The cause might be that the latitude was easier to determine than the longitude.)
This all leads for us SW developpers to the bad situation, that sometimes functions use (lat,lon) order, sometimes when working with transformations from (lon,lat) to (x,y) or mathematical routines, the order lon, lat must be used. Be careful, every person I know someday has accidentally exchanged that.
In your example:
P is related to (-8.64), 41.15).
But lat,lon are spherical coordinates, for most application you must convert them to cartesian (x,y) .
But this is another question.
Be careful with units. In systems like Google Maps, those numbers are usually in degrees. Usually.
They might also be in radians, though, so at least make sure of what unit the API is using.

GEOS C API - calculating areas with WGS84 coords (SRID=4326)

I create a polygon where each x/y point is WGS84 format
lat/long values.
The polygons are good approximations to circles and sectors of
radius R (each circumference/arc point is a projected lat/long
value of distance R from a centre/apex coordinate - which I have
verified is correct by computing the Haversine distance between
the edge and reference points and getting a value of R back) .
I use GEOSSetSRID(4326) to indicate the coords are WGS84 format.
GEOSGetSRID() confirms the SRID is set.
Use of GEOSArea then gives a value not even remotely close to
the expected value.
I do not see what else I can programmatically do.
If I set the points in cartesian format, and then set the SRID to
4326, will GEOS implicitly convert the polygon points to WGS84 ??
Is the basic GEOS C API incapable of doing the above ??
Dos SRID have no meaning to the API at all ??
Any info/pointers to correct usage/solutions would be much appreciated.
TIA.
The distance that is given is something like degrees between the two points. In actuality, the GEOS API (at least the C++ interface) is units agnostic; the units it gives the distance in is based on whatever you passed in.
In general, multiplying the result you get by 111000 gives you a fairly accurate measurement in meters. For area, you have to do 111000^2.

Is there a way to convert actual street map coordinates to a set of GPS coordinates?

I wonder is there a way to convert actual street map coordinates to a set of GPS coordinates. I was thinking if I have a set of GPS coordinates on the corners of a rectangular street map, I could virtually put a GPS coordinate to any point in that area. It is logical but I am not sure how to do it.
The Geotools Java project has all the tools you need to transform from one coordinate system to another. I'm not aware of anything similar in C++ though I'm afraid.
There are an absolute wealth of coordinate systems out there (see: http://en.wikipedia.org/wiki/Geographic_coordinate_system), so you'd need to be more specific about the format in which you have your street map coordinates for me to give any more detail.
I think I get the concept. You need two ingredients for that:
1. Scale and..
2. Corner sample.
It's easy to make a program to offset your marked points on the map
but these requires the "Scale" (ex. 1-inch : 121001-meters) and the
sample of "coordinate" in at least one of any of the four corners
(top-left,top-right,bottom-left,bottom-right) for use to offset and
get.
Out of these variables needed, we could easily extract to get the
coords marked on your map.
MAJOR EDIT:
(Note: Disregard what I've written earlier above)
Variables:
mw = 2d mapwidth
mh = 2d mapheight
x = your 2d x coordinate
y = your 2d y coordinate
lat = latitude (our N or ?)
lon = longitude (our N or ?)
Formula:
lat = 180 + ( (x / mw) * 360) )
long = 90 + ( (y / mh) * 360) )
Explanation:
Following the formulas which are used:
x = (mw) * (180 + latitude) / 360
y = (mh) * (90 + longitude) / 180
I've personally transposed the formula above to find our latitude and longitude.
I hope this solves your problem and this is the appropriate answer for your question.
Don't forget to up my answer to save my honor from the humiliation earlier. jk. :)