MKMetersBetweenMapPoints incorrectly returning distance in meters - mkmapview

running this code:
NSLog(#"%f", MKMetersBetweenMapPoints(MKMapPointMake(33.6523, -118.507), MKMapPointMake(34.516, -117.628)));
returns this:
0.015819
When the expected output should be ~136900. What am I doing wrong?

It looks like you're giving a regular latitude and longitude to MKMapPointMake(). An MKMapPoint contains and x and y value, not latitude and longitude.
Use MKMapPointForCoordinate(myLocation) to convert your locations to map points, then give those to your MKMetersBetweenMapPoints() function.
Or easier still, use -distanceFromLocation: with two CLLocation objects. It gives you back a distance in meters, taking into account the curvature of the earth.

Related

Assign a timezone label to a list of geometries of a geodataframe

I have a geodataframe ("timezones") that contains the timezone labels of all the world (for example: "Europe/Zurich", or "Pacific/Galapagos") and its corresponding geometry:
On the other hand, I have a geodataframe ("regions") with ~80K rows, where each row represents a region in some country, defined by a certain geometry (a Polygon or Multipolygon):
I need to assign a timezone to each of the regions, so the final dataframe has "region", "province", "geometry" and "timezone" columns.
I don't know how to do it, maybe using a for loop over each row and check if geometry is inside the timezone using geopandas within or contains?
for i,row in regions.iterrows():
if regions.geometry.within(timezones.geometry)=="True":
region['timezone'] = timezones['timezone']
This example does not work, but it could be something similar to this? Or maybe there is a better way to do it?
Any suggestions would be highly appreciated.

code produces a 2d histogram but the results dont match with hist2d

I am trying to write a histogram builder to construct a 2d histogram for my assignment work. This is [my code][1]:
def Build2DHistogramClassifier(X1,X2,T,B,x1min,x1max,x2min,x2max):
HF=np.zeros((B,B),dtype='int');#initialising a empty array of integer type
HM=np.zeros((B,B),dtype='int');
bin_row_indices=(np.round(((B-1)*(X1-x1min)/(x1max-x1min)))).astype('int32');"""this logic decides which bin the value goes into"""
bin_column_indices=(np.round(((B-1)*(X2-x2min)/(x2max-x2min)))).astype('int32');"""np.round-->applies the formula to all the values in the array"""
for i,(r,c) in enumerate(zip(bin_row_indices, bin_column_indices)):
"""enumerate-->if we put array or list into it gives output with index/count i """
if T[i]=='Female':
HF[r,c]+=1;
else:
HM[r,c]+=1;
return [HF, HM]
but the problem is that the results( count in each bin) i am getting is not matching the what i get from using hist2d function in numpy( i passed the same bin size)
i am sorry if my code is not in the right format. Please click on the hyperlink to a gist i created with the same code.
what is the mistake in my code?
how do i correct it?
thanks
By rounding when assigning to bins you are treating the bins as bin centers. The numpy convention is to use them as bin edges.
Remove the two calls to round() from your code and change B-1 to B. You should now get the same results with your function and with np.histogram2d.

Foursquare "Invalid geo coordinates" error

I'm getting an error Invalid geo coordinates when using the following Foursquare API search URL:
https://api.foursquare.com/v2/venues/search?client_id=REMOVED&client_secret=REMOVED&ll=174.696603,-36.916037&query=sushi&v=20170310&m=foursquare
The coordinates 174.696603,-36.916037 are valid.
What am I doing wrong here?
You probably set the latitude and longitude in reverse. The latitude must be a number between -90 and 90 and the longitude between -180 and 180.
Use the following URL:
https://api.foursquare.com/v2/venues/search?client_id=REMOVED&client_secret=REMOVED&ll=-36.916037,174.696603&query=sushi&v=20170310&m=foursquare

Last vertex in vertex buffer not being set

I'm attempting to render a sphere in Direct11 using SharpDX. I have correctly read in the OBJ model, created the vertex buffers, and set the buffers on the context for rendering.
My problem is that everything rendering perfectly EXCEPT the very last vertex, which is rendered as if it were at 0, 0, 0. Below is a screen shot of this:
I have checked the vectors that get used when creating the buffers and there is no missing data in there, I even changed the last element in the array like this:
vertexBufferArray[vertexBufferArray.Length - 1].X = 1.0f;
and had no result. Whereas if I change the second to last element like this:
vertexBufferArray[vertexBufferArray.Length - 2].X = 1.0f;
I get this result:
The vertex count that I am passing to the render call is correct because if I pass it VertexCount - 1, I don't get the last triangle at all, and if I pass it VertexCount + 100, nothing changes at all.
Any ideas?
As usual I end up fixing the problem 10 mins after I make a big post about it.
The problem was my Input Assembler, my input elements for POSITION and NORMAL were of Format.R32G32B32A32_Float, when they should have been Format.R32G32B32_Float since I was giving my vertices in as Vector3s.

Why am I getting an array of NANs when trying to plot a map with D3.js?

I am tring to plot a map with d3.js using GeoJSON, but the paths generated look like this:
<path d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,‌​NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,N‌​aNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,Na‌​NLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaN‌​LNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNL‌​NaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLN‌​aN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ">
the code and data are in this Gist:
https://gist.github.com/4157853
I can load the data just fine on QGIS.
Does any one know what is causing this?
The way you have specified the offset in the Mercator projection doesn't seem right. The projection.translate method expects a two element array:
https://github.com/mbostock/d3/wiki/Geo-Projections#wiki-mercator_translate
So instead of:
proj.translate(-43.8,-23.2).scale(10);
you would need to say:
proj.translate([-43.8,-23.2]).scale(10);
-- edit --
See source of projection.translate: https://github.com/mbostock/d3/blob/3.0/src/geo/projection.js#L139
projection.translate = function(_) {
if (!arguments.length) return [x, y];
x = +_[0];
y = +_[1];
return reset();
};
If the argument _ is not an array then +_[0] will return a NaN and therefore the x and y will become NaNs. (This is because trying to get one element from a number (e.g. 213[0]) returns undefined and casting undefined to a number (e.g. +undefined) yields NaN.)
If the code you posted in the gist is everything you're trying to run, then the data you show in data.json is not being loaded anywhere. Anyway, your draw function is acting on the data defined by the variable map (line 16), which refers to a simulation variable which isn't set anywhere. And even if it did, line 34 then refers to a features property of the object passed in as json, which map does not have.
In summary, you need to pass the JSON you posted in the gist to your draw function. Then it might well work. If you don't pass in valid data to the d3 SVG helpers, you'll get a bunch of NaN out.

Resources