protected Shape ReadStandardShape(String str)
{
if (string.IsNullOrEmpty(str))
throw new InvalidShapeException(str);
string[] st;
var tokenPos = 0;
if (Char.IsLetter(str[0]))
{
if (str.StartsWith("Circle(") || str.StartsWith("CIRCLE("))
{
int idx = str.LastIndexOf(')');
if (idx > 0)
{
//Substring in .NET is (startPosn, length), But in Java it's (startPosn, endPosn)
//see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int, int)
var body = str.Substring("Circle(".Length,
(idx - "Circle(".Length));
st = body.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
String token = st[tokenPos++];
Point pt;
if (token.IndexOf(',') != -1)
{
pt = ReadLatCommaLonPoint(token);
}
else
{
double x = Double.Parse(token, CultureInfo.InvariantCulture);
double y = Double.Parse(st[tokenPos++], CultureInfo.InvariantCulture);
pt = Ctx.MakePoint(x, y);
}
double d;
String arg = st[tokenPos++];
idx = arg.IndexOf('=');
if (idx > 0)
{
String k = arg.Substring(0, idx);
if (k.Equals("d") || k.Equals("distance"))
{
if (!Double.TryParse(arg.Substring(idx + 1), NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d))
throw new InvalidShapeException("Missing Distance: " + str);
}
else
{
throw new InvalidShapeException("unknown arg: " + k + " :: " + str);
}
}
else
{
if (!Double.TryParse(arg, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d)) throw new InvalidShapeException("Missing Distance: " + str);
}
if (st.Length > tokenPos)
{
throw new InvalidShapeException("Extra arguments: " + st[tokenPos] + " :: " + str);
}
//NOTE: we are assuming the units of 'd' is the same as that of the spatial context.
return Ctx.MakeCircle(pt, d);
}
}
return null;
}
if (str.IndexOf(',') != -1)
return ReadLatCommaLonPoint(str);
st = str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double p0 = Double.Parse(st[tokenPos++], CultureInfo.InvariantCulture);
double p1 = Double.Parse(st[tokenPos++], CultureInfo.InvariantCulture);
if (st.Length > tokenPos)
{
double p2 = Double.Parse(st[tokenPos++], CultureInfo.InvariantCulture);
double p3 = Double.Parse(st[tokenPos++], CultureInfo.InvariantCulture);
if (st.Length > tokenPos)
throw new InvalidShapeException("Only 4 numbers supported (rect) but found more: " + str);
return Ctx.MakeRectangle(p0, p2, p1, p3);
}
return Ctx.MakePoint(p0, p1);
}