I use PrecisionModel in NTS(C#) to specify a fixed decimal place (i.e. 0.1, 0.01, 0.001 ... ) for Coordinates in a Geometry.
I tried three fixed decimal place : 0.1, 0.01, 0.001 for the same LineString. But the precision of 0.1 always got error when I do some union operations, while 0.01 and 0.001 works well.
The source code are as follows:
//Obviously, the precision of the line and the point is is 0.1
var lineStr = "LINESTRING (1667.8 1368.6, 1741.1 4274.5, 1902.5 578, 1902.5 578.1, 1867.6 1377.3, 1667.8 1368.6)";
var ptStr = "POINT (1741.1 4274.5)";
//scale is 1000d, which means 0.001 precision
var f3 = new GeometryFactory(new PrecisionModel(1000d));
var wktReader3 = new WKTReader(f3);
//scale is 100d, which means 0.01
var f2 = new GeometryFactory(new PrecisionModel(100d));
var wktReader2 = new WKTReader(f2);
//scale is 10d, which means 0.1
var f1 = new GeometryFactory(new PrecisionModel(10d));
var wktReader1 = new WKTReader(f1);
//wkt strings to geometry objects
var line3 = wktReader3.Read(lineStr);
var pt3 = wktReader3.Read(ptStr);
var line2 = wktReader2.Read(lineStr);
var pt2 = wktReader2.Read(ptStr);
var line1 = wktReader1.Read(lineStr);
var pt1 = wktReader1.Read(ptStr);
var lines3 = line3.Union(pt3);
//result: MULTILINESTRING ((1667.8 1368.6, 1741.1 4274.5, 1869.307 1338.211),
//(1869.307 1338.211, 1902.5 578, 1902.5 578.1, 1869.307 1338.211),
//(1869.307 1338.211, 1867.6 1377.3, 1667.8 1368.6))
var lines2 = line2.Union(pt2);
//result: MULTILINESTRING ((1667.8 1368.6, 1741.1 4274.5, 1869.31 1338.21),
//(1869.31 1338.21, 1902.5 578, 1902.5 578.1, 1869.31 1338.21),
//(1869.31 1338.21, 1867.6 1377.3, 1667.8 1368.6))
var lines1 = line1.Union(pt1);
//result: NetTopologySuite.Geometries.TopologyException:
//“found non-noded intersection between LINESTRING(1741.1 4274.5, 1869.3 1338.2)
//and LINESTRING(1867.6 1377.3, 1667.8 1368.6) [ (1867.59289230568, 1377.2996905058, NaN) ]”
Obviously, the decimal place of the initial lineStr is 0.1, so I think specifying 0.1 for the PrecisionModel is enough, and I really hope the accuracy of the result is also in 0.1, otherwise I have to do some rounding operations.
Is it a correct way to use PrecisionModel? Thanks for your help.