javascript - Google Maps and SQL Server LINESTRING length inconsistent -


google maps , mssql seem disagree on how calculate distance/length of polyline/linestring using srid 4326.

mssql:

select geography::stgeomfromtext('linestring(-98.78 39.63,2.98 27.52)', 4326).stlength() 

result: 9030715.95721209

then google maps:

http://jsbin.com/niratiyojo/1/

result: 9022896.239500616

at first thought different radius of earth measure played around , turned out more.

i need javascript interface match mssql report remain consistent , accurate. or how can find how mssql calculates stlength() , can replicated in javascript?

update:

i realized if do

select geography::stgeomfromtext('linestring(-98.78 39.63,2.98 27.52)', 104001).stlength() * 6378137 

then mssql returns 9022896.23950062

the new srid in mssql :

new “unit sphere” spatial reference id default spatial reference id (srid) in sql server 2012 4326, uses metric system unit of measurement. srid represents true ellipsoidal sphere shape of earth. while representation accurate, it’s more complex calculate precise ellipsoidal mathematics. sql server 2012 offers compromise in speed , accuracy, adding new spatial reference id (srid), 104001, uses sphere of radius 1 represent round earth.

so problem google maps not use true ellipsoidal sphere in calculations. looking javascript function gets 9030715.95721209 witnessed.

i tried vincenty direct formula here: http://jsbin.com/noveqoqepa/1/edit?html,js,console , while it's closer still cannot match mssql

edit 2:

i able find measurements uses:

sridlist._sridlist.add(4326, new sridinfo(4326, "epsg", 4326, "geogcs[\"wgs 84\", datum[\"world geodetic system 1984\", ellipsoid[\"wgs 84\", 6378137, 298.257223563]], primem[\"greenwich\", 0], unit[\"degree\", 0.0174532925199433]]", "metre", 1.0, 6378137.0, 6356752.314)); 

but seemingly plugging vincenty yield no luck.

after going through different options best option seems to use same literal function on both server , client. can achieved in 2 ways:

approach 1: use sql function on client

in case trigger ajax query on client server, in turn queries database specific calculation want , return client.

approach 2: use javascript function in sql

this might sound quite impossible, using xp_cmdshell it's possible execute command line commands sql, , can run javascript terminal using node.js, you're left implementing vincenty function called command line.

the big question here how performance be. starting , stopping node instance every few seconds seems relatively bad idea, far more optimal code service in node work, not know best way sql interact such service. simplest approach have http request localhost:8888/?lat1=&lng1=&etc., that's starting complex approach 1.

conclusion

approach 1 still seems reasonable one, although approach 2 gives lot more flexibility want. private project or perfectionist project think go approach 2, 'we need finish , not have time surprises or optimalization'-kinda project think advise approach number 1.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -