/// <summary> /// Returns the extent of the provided geometries /// </summary> /// <param name="geometries">The geometries to calculate the extent from.</param> /// <returns>The geometries extent. </returns> public static ILucidExtent CalculateExtent(params ILucidGeometry[] geometries) { ILucidExtent extentOut = new LucidExtent(); bool initialSet = false; int count = 0; foreach (var geometry in geometries) { foreach (var point in geometry.Vertices) { count++; var x = point.X; var y = point.Y; if (!initialSet) { extentOut.XMax = extentOut.XMin = x; extentOut.YMax = extentOut.YMin = y; initialSet = true; } else { if (extentOut.XMin > x) { extentOut.XMin = x; } if (extentOut.XMax < x) { extentOut.XMax = x; } if (extentOut.YMin > y) { extentOut.YMin = y; } if (extentOut.YMax < y) { extentOut.YMax = y; } } } } if (count == 1) { extentOut = GeometryHelper.Buffer(extentOut, .5); } return(extentOut); }
public static ILucidGeometry Create(string geometryJson) { if (geometryJson.Contains("\"x\"")) { return(LucidPoint.Create(geometryJson)); } if (geometryJson.Contains("\"xmax\"")) { return(LucidExtent.Create(geometryJson)); } if (geometryJson.Contains("\"paths\"")) { return(LucidLine.Create(geometryJson)); } if (geometryJson.Contains("\"rings\"")) { return(LucidPolygon.Create(geometryJson)); } throw new Exception($"Unrecognized geometry type {geometryJson}"); }