bilaldursun1 / nettopologysuite

Automatically exported from code.google.com/p/nettopologysuite
0 stars 0 forks source link

NetTopologySuite doesn't take into account SRID when calculating the distance between two points #182

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

    var reader = new NetTopologySuite.IO.WKTReader();
    var start = reader.Read("SRID=4326; POINT(-0.4246 38.4099)");
    var end = reader.Read("SRID=4326; POINT(-0.5199 38.39619)");
    var distance = start.Distance(end); 

    Console.WriteLine("Distance: {0}", distance);
    Console.ReadKey(true); 

What is the expected output? What do you see instead?
Expected: 8464.19172543766
Obtained: 0.096281120163820788

What version of the product are you using? On what operating system?
NTS 1.13.2
GeoAPI 1.7.2

Please provide any additional information below.

Original issue reported on code.google.com by ava...@jsvrfid.es on 5 May 2014 at 3:34

GoogleCodeExporter commented 9 years ago
why are you expecting 8464.19172543766 as a result?

Original comment by diegogu...@gmail.com on 5 May 2014 at 3:44

GoogleCodeExporter commented 9 years ago
Because I'm specifying SRID=4326 (WGS 84), the result should be the distance in 
meters.

For example, this query in Oracle returns the correct value:

select  sdo_geom.sdo_distance(
  sdo_geometry(2001, 4326, sdo_point_type(-0.4246, 38.4099, null), null, null),
  sdo_geometry(2001, 4326, sdo_point_type(-0.5199, 38.39619, null), null, null),
  0.005) as dist
from dual;

> 8462,38428929519

But, if you remove the SRID:
select  sdo_geom.sdo_distance(
  sdo_geometry(2001, null, sdo_point_type(-0.4246, 38.4099, null), null, null),
  sdo_geometry(2001, null, sdo_point_type(-0.5199, 38.39619, null), null, null),
  0.005) as dist
from dual;

> 0,0962811201638207

So, it seems that it's ignoring the 'SRID=4326' part of the Well-known text (or 
I am doing something wrong...)

Original comment by ava...@jsvrfid.es on 5 May 2014 at 3:53

GoogleCodeExporter commented 9 years ago
NTS will not perform any Great-Circle-Math. It assumes all coordinates to be in 
the cartesian space.
You will have to project the geometries to a planar coordinate system and then 
calculate distance or area.

Original comment by felix.ob...@netcologne.de on 5 May 2014 at 3:56

GoogleCodeExporter commented 9 years ago
Actually, I'm using a third-party data provider (dotConnect for Oracle) which 
uses this plugin, so there's nothing I can do to change how it is used.

Is there any way to get the desired result using NTS?  Maybe the type of this 
issue be changed to 'Enharcement' and proposed to further release?

Thank you for the fast response

Original comment by ava...@jsvrfid.es on 5 May 2014 at 4:29

GoogleCodeExporter commented 9 years ago
hope this can help: http://goo.gl/dC85wJ

Original comment by diegogu...@gmail.com on 5 May 2014 at 7:41

GoogleCodeExporter commented 9 years ago

Original comment by diegogu...@gmail.com on 5 May 2014 at 7:42

GoogleCodeExporter commented 9 years ago
You are getting the wkt from an oracle database, parse that to a NTS/GeoAPI 
geometry?
Not knowing oracle at all, but I would suppose that it should be able to 
provide you with a reprojected geometry.

Original comment by felix.ob...@netcologne.de on 6 May 2014 at 9:11