SqlGeometry.STGeomFromText and ToString

Mar 2, 2010 at 2:27 PM

 

Problem: I get 24141: A number is expected at position 18 of the input. The input has ,1854
when using SqlGeometry.STGeomFromText
--------------------------------------------------------
In the code a POLYGON is constructed using ToString with out a Formatter ==> if you run this on a machine where you have , as decimal the 
counstructed expression will be  
POLYGON((-101,1854 -0,1386318, -57,89985 -0,1386318, -57,89985 43,14695, -101,1854 43,14695, -101,1854 -0,1386318 ))
instead of 
POLYGON((-101.1854 -0.1386318, -57.89985 -0.1386318, -57.89985 43.14695, -101.1854 43.14695, -101.1854 -0.1386318 ))
Solution add a Invariant Cultrure to the ToString
Suggestion to fix this:
                CultureInfo invC = CultureInfo.InvariantCulture;
                StringBuilder poly = new StringBuilder();
                poly.Append("POLYGON((");
                poly.Append(left.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(", ");
                poly.Append(right.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(", ");
                poly.Append(right.ToString(invC)).Append(" ").Append(bottom.ToString(invC)).Append(", ");
                poly.Append(left.ToString(invC)).Append(" ").Append(bottom.ToString(invC)).Append(", ");
                poly.Append(left.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(" ");
                poly.Append("))");
 

Problem: I get 24141: A number is expected at position 18 of the input. The input has ,1854

when using SqlGeometry.STGeomFromText

--------------------------------------------------------

 

In the code a POLYGON is constructed using ToString with out a Formatter ==> if you run this on a machine where you have , as decimal the 

counstructed expression will be  

 

POLYGON((-101,1854 -0,1386318, -57,89985 -0,1386318, -57,89985 43,14695, -101,1854 43,14695, -101,1854 -0,1386318 ))

 

instead of 

 

POLYGON((-101.1854 -0.1386318, -57.89985 -0.1386318, -57.89985 43.14695, -101.1854 43.14695, -101.1854 -0.1386318 ))

 

 

Solution add a Invariant Cultrure to the ToString

 

Suggestion to fix this:

 

                CultureInfo invC = CultureInfo.InvariantCulture;

                StringBuilder poly = new StringBuilder();

                poly.Append("POLYGON((");

                poly.Append(left.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(", ");

                poly.Append(right.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(", ");

                poly.Append(right.ToString(invC)).Append(" ").Append(bottom.ToString(invC)).Append(", ");

                poly.Append(left.ToString(invC)).Append(" ").Append(bottom.ToString(invC)).Append(", ");

                poly.Append(left.ToString(invC)).Append(" ").Append(top.ToString(invC)).Append(" ");

                poly.Append("))");