public LogisticGeometrySimplificationParameters(T first, T middle, T last, /*int zoomLevel, */ List <LogisticGeometrySimplificationFeatures> features, Func <T, T> toScreenMap = null) : this() { var firstScreenPoint = toScreenMap == null ? first : toScreenMap(first); var middleScreenPoint = toScreenMap == null ? middle : toScreenMap(middle); var lastScreenPoint = toScreenMap == null ? last : toScreenMap(last); this.Features = features; //if (Features.Contains(LogisticGeometrySimplificationFeatures.Area)) this.Area = SpatialUtility.GetUnsignedTriangleArea(firstScreenPoint, middleScreenPoint, lastScreenPoint); //if (Features.Contains(LogisticGeometrySimplificationFeatures.DistanceToNext)) this.DistanceToNext = SpatialUtility.GetDistance(middleScreenPoint, lastScreenPoint); //if (Features.Contains(LogisticGeometrySimplificationFeatures.DistanceToPrevious)) this.DistanceToPrevious = SpatialUtility.GetDistance(middleScreenPoint, firstScreenPoint); //if (Features.Contains(LogisticGeometrySimplificationFeatures.CosineOfAngle)) this.CosineOfAngle = SpatialUtility.GetCosineOfAngle(firstScreenPoint, middleScreenPoint, lastScreenPoint); //if (Features.Contains(LogisticGeometrySimplificationFeatures.SquareCosineOfAngle)) //this.SquareCosineOfAngle = SpatialUtility.GetSquareCosineOfAngle(firstScreenPoint, middleScreenPoint, lastScreenPoint); this.SquareCosineOfAngle = CosineOfAngle * CosineOfAngle; //if (Features.Contains(LogisticGeometrySimplificationFeatures.VerticalDistance)) this.VerticalDistance = SpatialUtility.GetPointToLineSegmentDistance(firstScreenPoint, lastScreenPoint, middleScreenPoint); //if (Features.Contains(LogisticGeometrySimplificationFeatures.BaseLength)) this.BaseLength = SpatialUtility.GetDistance(firstScreenPoint, lastScreenPoint); }
/// <summary> /// Determines whether this instance contains the specified point /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <returns> /// <c>true</c> if this instance contains the specified point /// </returns> public bool Contains(double x, double y) { IPoint pt = FdoGeometryFactory.Instance.CreatePoint(FdoGeometryUtil.FDO_DIM_XY, new double[] { x, y }); bool contains = SpatialUtility.Evaluate(this.InternalInstance, OSGeo.FDO.Filter.SpatialOperations.SpatialOperations_Contains, pt); pt.Dispose(); return(contains); }
/// <summary> /// Determines whether this instance contains the specified envelope /// </summary> /// <param name="env">The envelope</param> /// <returns> /// <c>true</c> if this instance contains the specified envelope; otherwise, <c>false</c>. /// </returns> public bool Contains(IEnvelope env) { FdoGeometryFactory fact = FdoGeometryFactory.Instance; IGeometry geom = fact.CreateGeometry(env); bool contains = SpatialUtility.Evaluate(this.InternalInstance, OSGeo.FDO.Filter.SpatialOperations.SpatialOperations_Contains, geom); geom.Dispose(); return(contains); }
//1399.06.11 //مساحت مثلتهای تشکیل دهنده شکل هندسی public static List <double> GetPrimitiveAreas(SqlGeometry geometry) { var result = new List <double>(); if (geometry == null) { return(result); } return(SpatialUtility.GetPrimitiveAreas(geometry.AsGeometry())); }
public void TestClockwise() { List <IPoint> lineString = new List <IPoint>() { new Point(5, 0), new Point(6, 4), new Point(4, 5), new Point(1, 5), new Point(1, 0) }; Assert.AreEqual(false, SpatialUtility.IsClockwise(lineString)); List <IPoint> polygon = new List <IPoint>() { new Point(5, 0), new Point(6, 4), new Point(4, 1), new Point(1, 5), new Point(1, 0), new Point(5, 0) }; Assert.AreEqual(false, SpatialUtility.IsClockwise(polygon)); polygon.Reverse(); Assert.AreEqual(true, SpatialUtility.IsClockwise(polygon)); }
private List <T> FindNeighbours(T point, double radius, BalancedKdTreeNode <T> node, Func <T, T, double> distanceFunc = null) { var result = new List <T>(); //if (distanceFunc(point, node.Point) <= radius) //{ // result.Add(node.Point); //} if (node.LeftChild != null && !node.LeftChild.IsNilNode()) { var relation = SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(PointFunc(point), radius, node.LeftChild.MinimumBoundingBox); if (relation == IRI.Msh.Common.Model.SpatialRelation.Contained) { result.AddRange(GetAllValues(node.LeftChild)); } else if (relation == IRI.Msh.Common.Model.SpatialRelation.Intersects) { result.AddRange(FindNeighbours(point, radius, node.LeftChild, distanceFunc)); } } if (node.RightChild != null && !node.RightChild.IsNilNode()) { var relation = SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(PointFunc(point), radius, node.RightChild.MinimumBoundingBox); if (relation == IRI.Msh.Common.Model.SpatialRelation.Contained) { result.AddRange(GetAllValues(node.RightChild)); } else if (relation == IRI.Msh.Common.Model.SpatialRelation.Intersects) { result.AddRange(FindNeighbours(point, radius, node.RightChild, distanceFunc)); } } return(result); }
private T FindNearestNeighbour(T point, double distance, BalancedKdTreeNode <T> node, Func <T, T, double> distanceFunc) { double minDistance = Math.Min(distance, distanceFunc(point, node.Point)); T result = node.Point; if (node.LeftChild != null && !node.LeftChild.IsNilNode() && SpatialUtility.CircleRectangleIntersects(PointFunc(point), minDistance, node.LeftChild.MinimumBoundingBox)) { var newPoint = FindNearestNeighbour(point, minDistance, node.LeftChild, distanceFunc); if (distanceFunc(point, newPoint) < minDistance) { minDistance = distanceFunc(point, newPoint); result = newPoint; } } if (node.RightChild != null && !node.RightChild.IsNilNode() && SpatialUtility.CircleRectangleIntersects(PointFunc(point), minDistance, node.RightChild.MinimumBoundingBox)) { var newPoint = FindNearestNeighbour(point, minDistance, node.RightChild, distanceFunc); if (distanceFunc(point, newPoint) < minDistance) { minDistance = distanceFunc(point, newPoint); result = newPoint; } } return(result); }
private void Bind(FdoRow row) { //Set all property values to null and then set the proper values foreach (string propName in currentValues.Keys) { //Get the [target] property name. If reverse-mapped to the [source], use the //mapped [source] property name. Otherwise it is assumed that [source] name //is the same as the [target] name string name = propName; if (_mappings[name] != null) { name = _mappings[name]; } LiteralValue lVal = currentValues[propName] as LiteralValue; if (lVal.LiteralValueType == LiteralValueType.LiteralValueType_Data) { DataValue dVal = lVal as DataValue; dVal.SetNull(); switch (dVal.DataType) { case DataType.DataType_BLOB: { byte [] blob = row[name] as byte[]; if (blob != null) { (dVal as BLOBValue).Data = blob; } } break; case DataType.DataType_Boolean: { if (row[name] != null) { (dVal as BooleanValue).Boolean = Convert.ToBoolean(row[name]); } } break; case DataType.DataType_Byte: { if (row[name] != null) { (dVal as ByteValue).Byte = Convert.ToByte(row[name]); } } break; case DataType.DataType_CLOB: { byte[] clob = row[name] as byte[]; if (clob != null) { (dVal as CLOBValue).Data = clob; } } break; case DataType.DataType_DateTime: { if (row[name] != null) { (dVal as DateTimeValue).DateTime = Convert.ToDateTime(row[name]); } } break; case DataType.DataType_Decimal: { if (row[name] != null) { (dVal as DecimalValue).Decimal = Convert.ToDouble(row[name]); } } break; case DataType.DataType_Double: { if (row[name] != null) { (dVal as DoubleValue).Double = Convert.ToDouble(row[name]); } } break; case DataType.DataType_Int16: { if (row[name] != null) { (dVal as Int16Value).Int16 = Convert.ToInt16(row[name]); } } break; case DataType.DataType_Int32: { if (row[name] != null) { (dVal as Int32Value).Int32 = Convert.ToInt32(row[name]); } } break; case DataType.DataType_Int64: { if (row[name] != null) { (dVal as Int64Value).Int64 = Convert.ToInt64(row[name]); } } break; case DataType.DataType_Single: { if (row[name] != null) { (dVal as SingleValue).Single = Convert.ToSingle(row[name]); } } break; case DataType.DataType_String: { if (row[name] != null) { (dVal as StringValue).String = row[name].ToString(); } } break; } } else { GeometryValue gVal = lVal as GeometryValue; gVal.SetNull(); IGeometry geom = row[name] as IGeometry; if (geom != null) { IGeometry origGeom = geom; //HACK: Just for you SQL Server 2008! if (geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_Polygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_CurvePolygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiCurvePolygon || geom.DerivedType == OSGeo.FDO.Common.GeometryType.GeometryType_MultiPolygon) { if (_conn.Provider.ToUpper().StartsWith("OSGEO.SQLSERVERSPATIAL")) { //This isn't the most optimal way, as the most optimal //method according to RFC48 is to get the source rule and //strictness and pass that to SpatialUtility.GetPolygonVertexOrderAction() //along with the target rule and strictness. I don't think warping the //existing API to address such a provider-specific corner case is worth it. var caps = _clsDef.Capabilities; var rule = caps.get_PolygonVertexOrderRule(name); geom = SpatialUtility.FixPolygonVertexOrder(origGeom, rule); } } if (geom != null) { gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(geom); } else { gVal.Geometry = FdoGeometryFactory.Instance.GetFgf(origGeom); } } } } }
/// <summary> /// Determines whether this instance's envelope intersects the specified geometry /// </summary> /// <param name="geom">The geometry to test against</param> /// <returns></returns> public bool EnvelopeIntersects(IFdoGeometry geom) { return(SpatialUtility.Evaluate(this.InternalInstance, OSGeo.FDO.Filter.SpatialOperations.SpatialOperations_EnvelopeIntersects, geom.InternalInstance)); }
/// <summary> /// Determines whether this instance is inside the specified geometry /// </summary> /// <param name="geom">The geometry to test against</param> /// <returns></returns> public bool Inside(IFdoGeometry geom) { return(SpatialUtility.Evaluate(this.InternalInstance, OSGeo.FDO.Filter.SpatialOperations.SpatialOperations_Inside, geom.InternalInstance)); }
public void TestCircleRectangleIntersects() { // ------- // | | // | | // | | // ------- BoundingBox rectangle = new BoundingBox(0, 0, 10, 20); var radius = 5; Point insideRectangle = new Point(5, 9); Assert.AreEqual(true, SpatialUtility.CircleRectangleIntersects(insideRectangle, radius, rectangle)); Point topOfRectangle = new Point(5, 25.1); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(topOfRectangle, radius, rectangle)); Point bottomOfRectangle = new Point(5, -6); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(bottomOfRectangle, radius, rectangle)); Point topRightCorner = new Point(13, 24); Assert.AreEqual(true, SpatialUtility.CircleRectangleIntersects(topRightCorner, radius, rectangle)); Point topRightCorner2 = new Point(13.1, 24); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(topRightCorner2, radius, rectangle)); Point centerRectangle = new Point(5, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(centerRectangle, radius, rectangle)); Point insideRectangle2 = new Point(5.1, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle2, radius, rectangle)); Point insideRectangle3 = new Point(5.1, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle3, 11.19, rectangle)); Point insideRectangle4 = new Point(5, 10); Assert.AreEqual(true, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle4, 11.19, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topOfRectangle, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(bottomOfRectangle, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topRightCorner, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topRightCorner2, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(centerRectangle, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle2, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle3, 11.19, rectangle)); Assert.AreEqual(Contained, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle4, 11.19, rectangle)); }