Is calculating the distance between users a feature of Geocoding API? - geocoding

I'm sorry if this is not the right place to post this. I've never used this.
I am creating a mobile app. I'm not the developer. I hired one to develop my app.
We are using Google Cloud Platform, which it's free for one year. Next October will stop being free. And today we realized we would pay 156 dollars a month for just using Geocoding API (if it wasn't free). And only a very few people are using the app for testing.
We still didn't launch it. And honestly, it's too much money for us, because if too many people would start to use the app, that cost would be higher.
Now, Geocoding is the process of converting addresses into geographic coordinates, which we are using in the app. And we are also showing the distances between users, like Tinder does. We plan to remove Geocoding API, because it's not absolutely necessary to convert addresses into geographic coordinates. But we need to show the distances between users.
I want to ask: Is calculating the distance between users a feature of Geocoding API? Because if it is, we'll have to remove this feature too.
I hope I was clear with my question.
Thank you,
Juan

If you get the users coordinates from another API, you can use the latitude and longitude to calculate the distance between two points using the Haversine formula
Haversine formula: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c
where φ is latitude, λ is longitude, R is earth’s radius (mean radius
= 6,371km); note that angles need to be in radians to pass to trig functions!
JavaScript:
var R = 6371e3; // metres
var φ1 = lat1.toRadians();
var φ2 = lat2.toRadians();
var Δφ = (lat2-lat1).toRadians();
var Δλ = (lon2-lon1).toRadians();
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
In here you can find a full example of this

Related

Finding distance between 2 geospatial location in aws neptune with opencypher query language

I am working with amazon neptune and using openCypher query language and doing some stuff using notebook. I have latitude and longitude of 2 points and I want to calculate the distance between these 2 points. For the purpose I am using Haversine formula. However to do this it required trigonometric functions like sin and cos and seems that those are not supported yet with neptune and openCypher. I am stuck here as I will be heavily doing operations on location. Any alternate solution without using sin cos ?
Until the trigonometric functions are added to the openCypher support provided by Amazon Neptune (which hopefully will appear fairly soon), you could do this particular calculation using Gremlin. An example query is available here. In summary, it looks like this (assuming both the start and stop vertices have properties called lat and lon providing the coordinates in decimal form):
g.withSideEffect("rdeg", 0.017453293).
withSideEffect("gcmiles",3956).
V().has('code',start).as('src').
V().has('code',stop).as('dst').
select('src','dst').
by(project('lat','lon').
by('lat').
by('lon')).
as('grp').
project('ladiff','lgdiff','lat1','lon1','lat2','lon2').
by(project('la1','la2').
by(select('grp').select('src').select('lat')).
by(select('grp').select('dst').select('lat')).
math('(la2 - la1) * rdeg')).
by(project('lg1','lg2').
by(select('grp').select('src').select('lon')).
by(select('grp').select('dst').select('lon')).
math('(lg2 - lg1) * rdeg')).
by(select('grp').select('src').select('lat')).
by(select('grp').select('src').select('lon')).
by(select('grp').select('dst').select('lat')).
by(select('grp').select('dst').select('lon')).
math('(sin(ladiff/2))^2 + cos(lat1*rdeg) * cos(lat2*rdeg) * (sin(lgdiff/2))^2').
math('gcmiles * (2 * asin(sqrt(_)))')

Google-distancematrix-api not calculating distance for my country

I'm using google-distance_matrix in my web app to calculate distance and prices. The code seems to be working fine if I'm using counties other than my own country (Zimbabwe ). For example from Brooklyn Bridge to Madison Square Gardens the API is able to get the calculate distance, time, and price backend and provide results frontend resultbut for any locations within Zimbabwe, the API is unable to get distance, price nor the timeFrontendbackend.
What might be the problem?

How to prepare the multilevel multivalued training dataset in python

I am a beginner in machine learning. My academic project involves detecting human posture from acceleration and gyro data. I am stuck at the beginning itself. My accelerometer data has x,y,z values and gyro also has x,y,z values stored in file acc.csv and gyro.csv. I want to classify the 'standing', 'sitting', 'walking' and 'lying' position. The idea is to train the machine using some ML algorithm (supervised) and then throw a new acc + gyro data set to identify what this new dataset predict (what the subject is doing at present). I am facing the following problems--
Constructing a training dataset -- I think my activities will be dependent variable, and acc & gyro axis readings will be independent. So if I like to combine it in single matrix with each element of the matrix again has it's own set of acc and gyro value [Something like main and sub matrix], how can I do that? or is there any alternative idea to do the same?
How can I take the data of multiple activities with multiple readings in a single training matrix,
I mean 10 walking data each with it's own acc(xyz) and gyro (xyz) + 10 standing data each with it's own acc(xyz) and gyro (xyz) + 10 sitting data each with it's own acc(xyz) and gyro (xyz) and so on.
Each data file has different number of records and time stamp, how to bring them into a common platform.
I know I am asking very basic things but these are the confusion part nobody has clearly explained to me. I am feeling like standing in front of a big closed door, inside very interesting things are happening where I cannot participate at this moment with my limited knowledge. My mathematical background is high school level only. Please help.
I have gone through some projects on activity recognition in Github. But they are way too complicated for a beginner like me.
import pandas as pd
import os
import warnings
from sklearn.utils import shuffle
warnings.filterwarnings('ignore')
os.listdir('../input/testtraindata/')
base_train_dir = '../input/testtraindata/Train_Set/'
#Train Data
train_data = pd.DataFrame(columns = ['activity','ax','ay','az','gx','gy','gz'])
train_folders = os.listdir(base_train_dir)
for tf in train_folders:
files = os.listdir(base_train_dir+tf)
for f in files:
df = pd.read_csv(base_train_dir+tf+'/'+f)
train_data = pd.concat([train_data,df],axis = 0)
train_data = shuffle(train_data)
train_data.reset_index(drop = True,inplace = True)
train_data.head()
The Data Set
Problem in Train_set
Surprisingly if I remove the last 'gz' from
train_data = pd.DataFrame(columns =['activity','ax','ay','az','gx','gy','gz'])
Everything is working fine.
You have the data labeled? --> position of x,y,z... = positure?
I have no clue about the values (as I have not seen the dataset, and have no clue about positions, acc or gyro), but Im guessing you should have a dataset within a matrise with x, y, z as categories and a target category ;"positions".
If you need all 6 (3 from one csv and 3 from the other) to define the positions you can make 6 categories + positions.
Something like : x_1, y_1 z_1 , x_2, y_2, and z_2 + position label ("position" category).
You can also make each position an own category with 0/1 as true/false.
"sitting" , "walking" etc... and have 0 and 1 as the values in the columns.
Is the timestamp of any importance towards the position? If it is not a feature of importance I would just drop it. If it is important in some way, you might want to bin them.
Here is a beginners guide from Medium in which you can see a bit how to preprocess your data. It also shows one hot encoding :)
https://medium.com/hugo-ferreiras-blog/dealing-with-categorical-features-in-machine-learning-1bb70f07262d
Also try googling Preprocessing your data, then you will probably find the right recipe

Linear programming of taxation cost on fossil fuel and green energy

I am currently working on a project where I am modelling a set of combined heat and power production units (CHP).
I am using linear programming to do this for now.
The main idea is to minimize the overall production cost. In order to that one must consider the taxation on the fuel type used. The general idea is that heat produced with fossil fuels will have a tax on it and power produced with green energy will have a subsidy on it.
In order to calculate this I could do the following:
FossilShare = FossilFuel / TotalFuel
FossilHeat = FossilShare * Q
GreenPower = (1-FossilShare) * P
Where P and Q are the heat and power produced. Then my taxation cost function would be as following:
Cost = FossilHeat * Tax - GreenPower * subsidy
The problem, however, is that this is not linear. I cannot think of a way to linearise this and I cannot think of another way of doing it, because I need to calculate the portion of heat produced with fossil fuel and the portion of power produced with green energy.
Any help or suggestions would be much appreciated.
Thanks in advance
M. Frank

Implementation of Great Circle Destination formula?

I am writing a Python program to generate some maps in Google Earth, I am using a colleague's script written in Perl and I came to a point where there is this Great Circle call:
#r = great_circle_destination($long, $lat, $bearing, $dist);
What is the equivalent for Python? Is there a module like this:
use Math::Trig ':great_cricle';
I'm pretty sure there's no such thing in the standard library. I'm pretty sure there'd be a python GIS library that have similar functions, but there are many different ways to do this calculation depending on which model of the earth you uses (e.g. spherical earth or ellipsoid earth or something more complex), so you probably would want to check out the source code of the Perl module and translate that to python.
If you want to implement it yourself, you might want to look in this page for a formula for Destination point given distance and bearing from start point: http://www.movable-type.co.uk/scripts/latlong.html
It shouldn't be too difficult to translate that formula to python:
R = ... Radius of earth ...
def great_circle_destination(lon1, lat1, bearing, dist):
lat2 = math.asin( math.sin(lat1)*math.cos(dist/R) +
math.cos(lat1)*math.sin(dist/R)*math.cos(bearing) )
lon2 = lon1 + math.atan2(math.sin(bearing)*math.sin(dist/R)*math.cos(lat1),
math.cos(dist/R)-math.sin(lat1)*math.sin(lat2)
return lon2, lat2