Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Background: I have a list of human readable addresses and want to create a (driving) distance matrix between these locations using some julia package. OpenStreetMapX.jl can create the distance matrix but needs nodes or coordinates as inputs instead of addresses.
Question: I did not find a julia package that geocodes addresses to coordinates (like geopy for python). Is there something around (or is there a functionality of OpenStreetMapX to do such a search that I missed)?
Have a look at GoogleMaps.jl - I used this succesfully a few weeks ago.
I have now written a function that uses nominatim to determine the coordinates for a list of addresses.
using HTTP
using JSON
addressList = ["Mühlenstraße 21, 50321 Brühl","Joseph-Stelzmann Straße, 50931 Köln", "Bonner Straße 84, 50389 Wesseling" ]
#nominatim requires as user agent and will block you otherwise
HTTP.setuseragent!("Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0")
function getCoordinates(addressList)
"""
getCoordinates(addressList::Array{String,1})
returns a Vector of coordinates in (lat,lon) format as well as a data Array that contains all the data returned by nominatim
"""
coordinatesList = Array{Tuple{Float64,Float64},1}(undef, length(addressList)) # will contain (lat,lon) of addresses in addressList
data = Array{Any,1}(undef,length(addressList)) # will contain all data nominatim gives for each request
for (i,address) in enumerate(addressList)
addressFormatted = join(split(address),"+")
rawdata = HTTP.get(string("https://nominatim.openstreetmap.org/search?q=",addressFormatted,"&format=json&limit=1"))
data[i]=JSON.parse(String(rawdata.body))[1]
coordinatesList[i] = parse(Float64,data[i]["lat"]),parse(Float64,data[i]["lon"])
sleep(1) #nominatim will block you if you have more than 1 request per second
end
return coordinatesList , data
end
coordinates = getCoordinates(addressList)[1]
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Expression: z=a+b * b-(36/(b * b)/(1+(25/(b * b)))
I have no idea what data directives I should use and in what order I should write the code.
C = A + B for Z80 CPU:
ld a,A
ld b,B
add a,b ; a = C
C = A * B for 68000 CPU:
MOVE.W D0,A
MOVE.W D1,B
MULS.W D1,D0 ; D0 = C
et cetera ... check your target CPU instruction guide to see what arithmetic operations it does implement directly, and what operand types can be used for them, which registers you have available, and their data type...
Looks like you don't have to write universal math expression parser (this gets tricky quite quickly, once at high-school we had on programming competition the task to write exactly that, and at first we were like "what, a single task for 5h time, I will be done in 30min" ... then after 5h nobody's code passed the full test suite, best were around 80% correct).
So if only this particular expression should be calculated, you can "parse" it by hand, simplifying it down into particular steps involving only single operation and one of intermediate sub-results. Then just write that with your instructions, step by step, like you would calculate that by hand (also make sure you conform to the math expression calculation rules, you know which operations have priority over others? Parentheses override anything, then mul/div first, add/sub later, from left to right, but this is base school math stuff, so unless you are 10y.o., you shouldn't ask this).
If your CPU does not have instruction for division or multiplication, simply implement it by subtraction/addition in loop. It's very lame performance wise, but if you have to ask this question, then one can not expect you would even comprehend more advanced algorithm for these.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In the book 'Clean Code' by Robert C. Martin, he recommends making use of:
Circle makeCircle(Point center, double radius);
over
Circle makeCircle(double x, double y, double radius);
He basically argues that making a class to avoid using multiple method arguments is preferred.
What is your opinions on this? Please explain to me the benefits, or disadvantages of either.
There are a few reasons for this.
First, it helps to group parameters meaningfully. In this trivial example, it's immediately obvious that x and y go together, but it might not be as immediately obvious when dealing with a more obscure example.
Perhaps more importantly, it cuts down on having too many parameters to keep track of meaningfully; once you have a method that takes more than 3 or 4 parameters, it gets more and more cumbersome to keep track of which parameter is which. Binding parameters together in a class or struct helps avoid that.
Consider this example:
int HowManyMinutesToAirport(int AirportIdentifier, string AirportName, int PlainIdentifier, string PlainName, int PlaneSpeed, string PlaneCompassDirection);
vs.
int HowManyMinutesToAirport(Airport airport, Plane plane);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am starting to use the RProvider. For starters, I have just tried to evaluate functions in different ways. It seems I have already run into problems (perhaps a problem with my understanding of how the RProvider works). I have run the same function in four different ways, which I thought to be equivalent. However, the four example provides me with two different results.
R.sapply(R.c(1,2,3,4,5), R.eval(R.parse(text="mean"))).GetValue<float[]>()
// val it : float [] = [|1.0; 2.0; 3.0; 4.0; 5.0|]
R.sapply(R.c(1,2,3,4,5),"mean").GetValue<float[]>()
// val it : float [] = [|1.0; 2.0; 3.0; 4.0; 5.0|]
R.mean(R.c(1,2,3,4,5)).GetValue<float[]>()
// val it : float [] = [|3.0|]
R.eval(R.parse(text="mean(c(1,2,3,4,5))")).GetValue<float[]>()
// val it : float [] = [|3.0|]
Can anyone tell me why this is? My own guess is that R.sapply applies the given function element-wise. But how do I get around this?
do.call() is the function in R for "applying" a function to a list of parameters (a slightly different meaning from applying or mapping a function over a vector or list of values, which is what the *apply family does).
The R function for what you want would be
do.call("mean",list(c(1,2,3,4,5)))
According to the comments (I don't speak F# myself), the F# analogue would be:
R.do_call("mean", R.list(R.c(1,2,3,4,5)))
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Forgive me for the newb question and potentially incorrect terminology.
Clojure vector functions produce values that do not include the stop value. For example:
=> (subvec [:peanut :butter :and :jelly] 1 3)
[:butter :and]
=> (range 1 5)
(1 2 3 4)
The doc for range explicitly states this but doesn't give a rational: "...Returns a lazy seq of nums from start (inclusive) to end (exclusive)...".
In Ruby these operations are inclusive:
(1..5).to_a
=> [1, 2, 3, 4, 5]
[:peanut, :butter, :and, :jelly][1,3]
=> [:butter, :and, :jelly]
Obviously these are very different languages, but I'm wondering if there was some underlying reason, beyond a personal preference by the language designers?
Making the end exclusive allows you to do things like specify (count collection) as the endpoint without getting an NPE. That's about the biggest difference between the two approaches.
It might be that the indexing was chosen in order to be consistent with Java libraries. java.lang.String.substring and java.util.List.subList both have exclusive-end indexes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
The problem:
An undirected graph is unicyclic if it contains exactly one cycle. Describe an O( |V| + |E| ) algorithm for determining whether or not a given graph, G is unicyclic.
My solution:
int i = 0
Run a modified DFS on G, where we increment i everytime we decide not to visit a vertex because it has already been visited.
After DFS is done, if i==1, graph is unicyclic.
I thought this solution would work but am wondering if there is a counter example that would prove it false. If anyone could clarify that would be great, Thanks.
Does your graph consists of a single connected component?
In this case just count vertices and edges and check |V| - |E| = 0
Otherwise count the number of connected components O(|V| + |E|),
and check |V| - |E| = number of connected components - 1.
Remark: having more than one connected component is a counterexample to your algorithm.
"Increment i everytime we decide not to visit a vertex because
it has already been visited."
I am quite unclear about what you are trying to do here.
Rather then this, how about this:
Perform DFS and count number of back edges.
A back edge is an edge that is from a node to itself (selfloop) or one of its
ancestor in the tree produced by DFS.
If number of back edges ==1 then unicycle else not.
To count number of back edges, follow this algorithm.
To detect a back edge, we can keep track of vertices currently in recursion stack of
function for DFS traversal. If we reach a vertex that is already in the recursion stack,
then there is a cycle in the tree. The edge that connects current vertex to the
vertex in the recursion stack is back edge