public void CanCheckPolygonFastEnough() { IPolygon area = GeometryFactory.CreatePolygon(0, 0, 10, 10); var constraint = new GeometryConstraint("$AREA > 50 AND $LENGTH > 30 AND " + "$SLIVERRATIO < 100 AND NOT $ISMULTIPART AND " + "$PARTCOUNT = 1 AND $VERTEXCOUNT = 5 AND " + "$SEGMENTCOUNT = 4 AND $ELLIPTICARCCOUNT = 0"); var watch = new Stopwatch(); watch.Start(); const int count = 10000; for (var i = 0; i < count; i++) { Assert.True(constraint.IsFulfilled(area)); } watch.Stop(); long milliseconds = watch.ElapsedMilliseconds; Console.WriteLine(@"{0} s for {1:N0} operations", milliseconds / 1000d, count); double millisecondsPerOperation = (double)milliseconds / count; Console.WriteLine(@"{0} ms per operation", millisecondsPerOperation); const double maximumMilliseconds = 0.15; Assert.LessOrEqual(millisecondsPerOperation, maximumMilliseconds); }
public static int ReportIntersections( [NotNull] IRow row1, int tableIndex1, [NotNull] IRow row2, int tableIndex2, [NotNull] IErrorReporting errorReporting, [CanBeNull] IssueCode issueCode, [CanBeNull] IValidRelationConstraint validRelationConstraint, bool reportIndividualParts, [CanBeNull] GeometryConstraint validIntersectionGeometryConstraint = null, GeometryComponent geomComponent1 = GeometryComponent.EntireGeometry, GeometryComponent geomComponent2 = GeometryComponent.EntireGeometry) { Assert.ArgumentNotNull(row1, nameof(row1)); Assert.ArgumentNotNull(row2, nameof(row2)); Assert.ArgumentNotNull(errorReporting, nameof(errorReporting)); if (row1 == row2) { return(_noError); } string errorDescription; if (HasFulfilledConstraint(row1, tableIndex1, row2, tableIndex2, validRelationConstraint, "Features intersect", out errorDescription)) { return(_noError); } IGeometry shape1 = ((IFeature)row1).Shape; IGeometry shape2 = ((IFeature)row2).Shape; var g1 = GeometryComponentUtils.GetGeometryComponent(shape1, geomComponent1); var g2 = GeometryComponentUtils.GetGeometryComponent(shape2, geomComponent2); var errorCount = 0; if (g1 != null && g2 != null) { foreach (IGeometry errorGeometry in IntersectionUtils.GetAllIntersections(g1, g2)) { if (validIntersectionGeometryConstraint == null || !validIntersectionGeometryConstraint.IsFulfilled(errorGeometry)) { errorCount += errorReporting.Report(errorDescription, errorGeometry, issueCode, reportIndividualParts, row1, row2); } } } return(errorCount); }
private static bool IsFulfilled([NotNull] string expression, [CanBeNull] IGeometry geometry, [NotNull] out string values) { var constraint = new GeometryConstraint(expression); values = constraint.FormatValues(geometry, CultureInfo.InvariantCulture); return(constraint.IsFulfilled(geometry)); }
public void CanFormatValuesMeters() { IPolygon area = GeometryFactory.CreatePolygon( 0, 0, 1.234, 1.234, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)); var constraint = new GeometryConstraint("$Length > 10"); string values = constraint.FormatValues(area, CultureInfo.InvariantCulture); Console.WriteLine(values); Assert.AreEqual("$Length=4.94", values); }
public void CanFormatValuesDecimalDegrees() { IPolygon area = GeometryFactory.CreatePolygon( 0, 0, 0.000123, 0.00000123, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.WGS84)); var constraint = new GeometryConstraint("$Length > 10"); string values = constraint.FormatValues(area, CultureInfo.InvariantCulture); Console.WriteLine(values); Assert.AreEqual("$Length=0.00024846", values); }
public void Write(TProtocol oprot) { oprot.IncrementRecursionDepth(); try { TStruct struc = new TStruct("MJointConstraint"); oprot.WriteStructBegin(struc); TField field = new TField(); field.Name = "JointType"; field.Type = TType.I32; field.ID = 1; oprot.WriteFieldBegin(field); oprot.WriteI32((int)JointType); oprot.WriteFieldEnd(); if (GeometryConstraint != null && __isset.GeometryConstraint) { field.Name = "GeometryConstraint"; field.Type = TType.Struct; field.ID = 2; oprot.WriteFieldBegin(field); GeometryConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (VelocityConstraint != null && __isset.VelocityConstraint) { field.Name = "VelocityConstraint"; field.Type = TType.Struct; field.ID = 3; oprot.WriteFieldBegin(field); VelocityConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (AccelerationConstraint != null && __isset.AccelerationConstraint) { field.Name = "AccelerationConstraint"; field.Type = TType.Struct; field.ID = 4; oprot.WriteFieldBegin(field); AccelerationConstraint.Write(oprot); oprot.WriteFieldEnd(); } oprot.WriteFieldStop(); oprot.WriteStructEnd(); } finally { oprot.DecrementRecursionDepth(); } }
/// <summary> /// Initializes a new instance of the <see cref="IntersectionMatrixHelper" /> class. /// </summary> /// <param name="intersectionMatrix">The intersection matrix.</param> /// <param name="validRelationConstraint">The match constraint. If the constraint is defined and fulfilled /// for a given row pair that matches the intersection matrix, then no error is reported.</param> /// <param name="constraintIsDirected">if set to <c>true</c> the constraint is directed, /// i.e. row1/row2 only maps to G1/G2 and not also to G2/G1.</param> /// <param name="validIntersectionDimensions">The valid intersection dimensions.</param> /// <param name="constraintIsCaseSensitive">Indicates if the constraint is case sensitive</param> /// <param name="intersectionGeometryConstraint">The intersection geometry constraint.</param> public IntersectionMatrixHelper( [NotNull] IntersectionMatrix intersectionMatrix, [CanBeNull] string validRelationConstraint = null, bool constraintIsDirected = false, [CanBeNull] ICollection <esriGeometryDimension> validIntersectionDimensions = null, bool constraintIsCaseSensitive = false, GeometryConstraint intersectionGeometryConstraint = null) : base(validRelationConstraint, constraintIsDirected, false, constraintIsCaseSensitive) { Assert.ArgumentNotNull(intersectionMatrix, nameof(intersectionMatrix)); _intersectionMatrix = intersectionMatrix; _validIntersectionDimensions = validIntersectionDimensions; _intersectionGeometryConstraint = intersectionGeometryConstraint; }
public void CanFormatValues() { IPolygon area = GeometryFactory.CreatePolygon(0, 0, 10, 10); var constraint = new GeometryConstraint("$AREA > 50 AND $LENGTH > 30 AND " + "$SLIVERRATIO < 100 AND $PARTCOUNT = 1 AND " + "$VERTEXCOUNT = 5 AND $ISCLOSED AND NOT $ISMULTIPART"); string values = constraint.FormatValues(area, CultureInfo.InvariantCulture); Console.WriteLine(values); // columns are formatted in alphabetic order Assert.AreEqual( "$Area=100; $IsClosed=True; $IsMultipart=False; $Length=40; $PartCount=1; $SliverRatio=16.000; $VertexCount=5", values); }
public QaGeometryConstraint( [Doc(nameof(DocStrings.QaGeometryConstraint_featureClass))][NotNull] IFeatureClass featureClass, [Doc(nameof(DocStrings.QaGeometryConstraint_geometryConstraint))][NotNull] string geometryConstraint, [Doc(nameof(DocStrings.QaGeometryConstraint_perPart))] bool perPart) : base((ITable)featureClass) { Assert.ArgumentNotNullOrEmpty(geometryConstraint, nameof(geometryConstraint)); _shapeFieldName = featureClass.ShapeFieldName; _perPart = perPart; _geometryType = featureClass.ShapeType; _constraint = new GeometryConstraint(geometryConstraint); }
public override string ToString() { StringBuilder __sb = new StringBuilder("MJointConstraint("); __sb.Append(", JointType: "); __sb.Append(JointType); if (GeometryConstraint != null && __isset.GeometryConstraint) { __sb.Append(", GeometryConstraint: "); __sb.Append(GeometryConstraint == null ? "<null>" : GeometryConstraint.ToString()); } if (VelocityConstraint != null && __isset.VelocityConstraint) { __sb.Append(", VelocityConstraint: "); __sb.Append(VelocityConstraint == null ? "<null>" : VelocityConstraint.ToString()); } if (AccelerationConstraint != null && __isset.AccelerationConstraint) { __sb.Append(", AccelerationConstraint: "); __sb.Append(AccelerationConstraint == null ? "<null>" : AccelerationConstraint.ToString()); } __sb.Append(")"); return(__sb.ToString()); }
public void Write(TProtocol oprot) { oprot.IncrementRecursionDepth(); try { TStruct struc = new TStruct("MConstraint"); oprot.WriteStructBegin(struc); TField field = new TField(); if (ID == null) { throw new TProtocolException(TProtocolException.INVALID_DATA, "required field ID not set"); } field.Name = "ID"; field.Type = TType.String; field.ID = 1; oprot.WriteFieldBegin(field); oprot.WriteString(ID); oprot.WriteFieldEnd(); if (GeometryConstraint != null && __isset.GeometryConstraint) { field.Name = "GeometryConstraint"; field.Type = TType.Struct; field.ID = 2; oprot.WriteFieldBegin(field); GeometryConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (VelocityConstraint != null && __isset.VelocityConstraint) { field.Name = "VelocityConstraint"; field.Type = TType.Struct; field.ID = 3; oprot.WriteFieldBegin(field); VelocityConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (AccelerationConstraint != null && __isset.AccelerationConstraint) { field.Name = "AccelerationConstraint"; field.Type = TType.Struct; field.ID = 4; oprot.WriteFieldBegin(field); AccelerationConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (PathConstraint != null && __isset.PathConstraint) { field.Name = "PathConstraint"; field.Type = TType.Struct; field.ID = 5; oprot.WriteFieldBegin(field); PathConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (JointPathConstraint != null && __isset.JointPathConstraint) { field.Name = "JointPathConstraint"; field.Type = TType.Struct; field.ID = 6; oprot.WriteFieldBegin(field); JointPathConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (PostureConstraint != null && __isset.PostureConstraint) { field.Name = "PostureConstraint"; field.Type = TType.Struct; field.ID = 7; oprot.WriteFieldBegin(field); PostureConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (JointConstraint != null && __isset.JointConstraint) { field.Name = "JointConstraint"; field.Type = TType.Struct; field.ID = 8; oprot.WriteFieldBegin(field); JointConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (Properties != null && __isset.Properties) { field.Name = "Properties"; field.Type = TType.Map; field.ID = 9; oprot.WriteFieldBegin(field); { oprot.WriteMapBegin(new TMap(TType.String, TType.String, Properties.Count)); foreach (string _iter4 in Properties.Keys) { oprot.WriteString(_iter4); oprot.WriteString(Properties[_iter4]); } oprot.WriteMapEnd(); } oprot.WriteFieldEnd(); } oprot.WriteFieldStop(); oprot.WriteStructEnd(); } finally { oprot.DecrementRecursionDepth(); } }
public static int ReportTouches( [NotNull] IRow row1, int tableIndex1, [NotNull] IRow row2, int tableIndex2, [NotNull] IErrorReporting errorReporting, [CanBeNull] IssueCode issueCode, [CanBeNull] IValidRelationConstraint validRelationConstraint, [CanBeNull] GeometryConstraint validTouchGeometryConstraint, bool reportIndividualParts = false) { Assert.ArgumentNotNull(row1, nameof(row1)); Assert.ArgumentNotNull(row2, nameof(row2)); Assert.ArgumentNotNull(errorReporting, nameof(errorReporting)); if (row1 == row2) { return(_noError); } IGeometry g1 = ((IFeature)row1).Shape; IGeometry g2 = ((IFeature)row2).Shape; string errorDescription; if (HasFulfilledConstraint(row1, tableIndex1, row2, tableIndex2, validRelationConstraint, "Geometries touch", out errorDescription)) { return(_noError); } var errorCount = 0; foreach (IGeometry geometry in GetTouches(g1, g2)) { if (geometry.IsEmpty) { continue; } if (reportIndividualParts) { foreach (IGeometry part in GeometryUtils.Explode(geometry)) { if (part.IsEmpty || validTouchGeometryConstraint != null && validTouchGeometryConstraint.IsFulfilled(part)) { continue; } errorCount += errorReporting.Report(errorDescription, part, issueCode, false, // already exploded row1, row2); } } else { if (validTouchGeometryConstraint != null && validTouchGeometryConstraint.IsFulfilled(geometry)) { continue; } errorCount += errorReporting.Report(errorDescription, geometry, issueCode, false, row1, row2); } } return(errorCount); }