|
Given this information How can I plot the point that is half way between each of the user groups? I can use
(comments are locked)
|
|
OK, many thanks to @Ken Johnson and @Scot Hauder. Their suggestions have got me to the solution as: This is what I wanted to achieve but am not sure that it's the best way, if anyone has any other ideas please add your answers below. Wow! That's horrible! You had to convert data out of spatial to text, to back to spatial to get a point in space between 2 other points. I'm amazed there's not better Spatial 'operators'.
Mar 21 '12 at 01:18 PM
Kev Riley ♦♦
Why can't you do that calculation 'in-line'? Do you have to do it in 2 steps : build up the string, then convert it to geography?
Mar 21 '12 at 01:27 PM
Kev Riley ♦♦
Its not horrible, it's simply a guy who doesnt know what he's doing making something work. "If it doesnt work hit it with a hammer. If it still doesnt work hit it harder"
Mar 21 '12 at 03:11 PM
Fatherjack ♦♦
(comments are locked)
|
|
Sorry, I have not worked hard to come up with my own answer, but carrying on with Kev Riley's answer, following looks much cleaner (hope so :)) The difference is use of STAsBinary and STUnion functions. With their help the strings concatenation etc. are not needed. Thanks for keeping going on this @Usman, it is indeed easier to read and more elegant that other solutions.
Mar 22 '12 at 11:34 AM
Fatherjack ♦♦
@Fatherjack You are always welcome :) May be I am not good at understanding your question, but it seems some detail like what is the full purpose etc. is missing in the question (May be hidden in the hyperlinks provided but could be elevated to the question)?? That addition could be helpful for the future reference. Thanks.
Mar 22 '12 at 12:39 PM
Usman Butt
much better without the strings
Mar 22 '12 at 01:57 PM
KenJ
Interesting approach, I don't I've ever mixed geography and geometry. I will definitely have to explore this further--this is why I love this site!
Mar 22 '12 at 06:13 PM
Scot Hauder
I do not remember the exact, but such conversion from geography to geometry or vice versa may not behave well for edge cases. So this made me think of a solution without the conversion. Then re-grabbing from the start yields that it is soooo much simpler :) I have edited my response and added the second solution.
Mar 26 '12 at 11:51 AM
Usman Butt
(comments are locked)
|
|
I'm sure there's a way to do it using great circles and trig, but I took the averaging the points approach which puts the midpoint between Bristol and Cardiff right here: Just for fun, here's the version that builds them as URLs... Hmmm, I can see in the future a question about how to clip the data so we dont get any drowned DBAs!!
Mar 21 '12 at 10:27 AM
Fatherjack ♦♦
OK, I got the fact that I can divide the Lat and Long by 2 before I posed the question, the trouble I ran in to is trying to then turn those values into a geography type again and get it onto a map ... Its close but not a final solution.
Mar 21 '12 at 11:04 AM
Fatherjack ♦♦
I was thinking you were just after the lat/long. Here is the midpoint as geography (updated in the answer, too)
Mar 21 '12 at 03:20 PM
KenJ
(comments are locked)
|
|
In geometry I might do something like this: Since there are no equivalent methods for geography, as an alternative, you could transpose the lat/lon values and take the intersection. Thanks for the answer Scott. If I have dozens of groups how would I transpose the values 'programatically' (ie in TSQL). I want eventually to find half way points between each pair of UGs that are closest together.
Mar 21 '12 at 11:01 AM
Fatherjack ♦♦
(comments are locked)
|
|
OK A bit of a combination of all the answers here. This solution does everything in-line , so no need for updating temporary table/variables. It builds a LINESTRING (geometry data type) between each location, then gets the halfway point by taking the STCentroid value of the STEnvelope - however this results in a geometry data type and cannot be combined with the geography data type to display on the spatial tab, so there is an extra step that converts the geometry back to geography. It's still not very clean, but at least avoids the conversion out of spatial data types. Great question Jonathan, I'd never played with spatial data before and this presented a real-world problem to solve! Still amazed that something as simple as a halfway point is soooo difficult to calculate. the halfway point is actually just that, its halfway through the problem I start out to solve - I wanted to draw a line between two points, at 90deg to the shortest line between them. Thus representing the border between them. Check out http://en.wikipedia.org/wiki/Voronoi_diagram
Mar 21 '12 at 03:13 PM
Fatherjack ♦♦
I take it you've seen this http://alastaira.wordpress.com/2011/04/25/nearest-neighbours-voronoi-diagrams-and-finding-your-nearest-sql-server-usergroup/
Mar 21 '12 at 03:19 PM
Kev Riley ♦♦
yes, that's where all this mapping activity started!
Mar 21 '12 at 03:57 PM
Fatherjack ♦♦
Of course, these halfway points land in the sea sometimes....
Mar 21 '12 at 03:57 PM
Fatherjack ♦♦
(comments are locked)
|

