public static int Execute([NotNull] TestContainer container, [CanBeNull] AreaOfInterest areaOfInterest) { Assert.ArgumentNotNull(container, nameof(container)); IGeometry testPerimeter = areaOfInterest?.Geometry; // TODO move enlarging by search distance WITHIN the container? IGeometry enlargedTestPerimeter = GetEnlargedTestPerimeter(container, testPerimeter); var box = enlargedTestPerimeter as IEnvelope; if (box != null) { return(container.Execute(box)); } var polygon = enlargedTestPerimeter as IPolygon; if (polygon != null) { return(container.Execute(polygon)); } if (enlargedTestPerimeter == null) { return(container.Execute()); } throw new ArgumentException("Invalid geometry type " + enlargedTestPerimeter.GeometryType); }
private void TestConnections(IFeatureWorkspace ws) { IFieldsEdit fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateIntegerField("LineTyp", "LineTyp")); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000, false, false)); IFeatureClass fc = DatasetUtils.CreateSimpleFeatureClass(ws, "TestConnections", fields, null); IList <ITable> tbls = new[] { (ITable)fc }; // make sure the table is known by the workspace ((IWorkspaceEdit)ws).StartEditing(false); ((IWorkspaceEdit)ws).StopEditing(true); { IFeature row = fc.CreateFeature(); row.set_Value(1, 1); row.Shape = CurveConstruction.StartLine(100, 100).LineTo(200, 200).Curve; row.Store(); } { IFeature row = fc.CreateFeature(); row.set_Value(1, 2); row.Shape = CurveConstruction.StartLine(100, 100.1).LineTo(100, 200).Curve; row.Store(); } IList <QaConnectionRule> rules = new[] { new QaConnectionRule(tbls, new[] { "LineTyp = 1" }), new QaConnectionRule(tbls, new[] { "LineTyp = 2" }) }; var test = new QaConnections(new[] { fc }, rules, 0); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(0, _errorCount); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); container.QaError += Test_QaError; _errorCount = 0; container.Execute(); Assert.AreEqual(0, _errorCount); }
private void TestFlowDirExpression(IFeatureWorkspace ws) { IFieldsEdit fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); IFeatureClass featureClass = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirExpression", fields); // make sure the table is known by the workspace ((IWorkspaceEdit)ws).StartEditing(false); ((IWorkspaceEdit)ws).StopEditing(true); { IFeature row = featureClass.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(100, 200), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = featureClass.CreateFeature(); row.set_Value(1, 10); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(110, 190)); row.Store(); } IPoint lastPoint; { IFeature row = featureClass.CreateFeature(); row.set_Value(1, null); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(130, 190)); row.Store(); lastPoint = ((IPolyline)row.Shape).ToPoint; } var test = new QaFlowLogic(new[] { featureClass }, new[] { "FlowDir > 6" }); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(1, _errorCount); Assert.AreEqual(lastPoint.X, _lastErrorPoint.X); Assert.AreEqual(lastPoint.Y, _lastErrorPoint.Y); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); container.QaError += Test_QaError; _errorCount = 0; container.Execute(); Assert.AreEqual(1, _errorCount); Assert.AreEqual(lastPoint.X, _lastErrorPoint.X); Assert.AreEqual(lastPoint.Y, _lastErrorPoint.Y); }
private void TestFlowDirMultiExpression(IFeatureWorkspace ws) { IFeatureClass fc1; { var fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); fc1 = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirMultiExpression1", fields); } IFeatureClass fc2; { var fields = new FieldsClass(); fields.AddField(FieldUtils.CreateOIDField()); fields.AddField(FieldUtils.CreateField("FlowDir", esriFieldType.esriFieldTypeInteger)); fields.AddField(FieldUtils.CreateShapeField( "Shape", esriGeometryType.esriGeometryPolyline, SpatialReferenceUtils.CreateSpatialReference ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true), 1000)); fc2 = DatasetUtils.CreateSimpleFeatureClass(ws, "TestFlowDirMultiExpression2", fields); } // make sure the tables are known by the workspace ((IWorkspaceEdit)ws).StartEditing(false); ((IWorkspaceEdit)ws).StopEditing(true); { IFeature row = fc1.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(100, 200), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = fc2.CreateFeature(); row.set_Value(1, 5); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(110, 190)); row.Store(); } { IFeature row = fc1.CreateFeature(); row.set_Value(1, null); row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(120, 190), GeometryFactory.CreatePoint(130, 190)); row.Store(); } { var test = new QaFlowLogic( new[] { fc1, fc2 }, new[] { "FlowDir > 6", "FlowDir < 6" } // no feature fc1 will be inverted, feature of fc2 will be inverted ); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(1, _errorCount); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); _errorCount = 0; container.QaError += Test_QaError; container.Execute(); Assert.AreEqual(1, _errorCount); } { var test = new QaFlowLogic( new[] { fc1, fc2 }, new[] { "FlowDir > 6" } // no feature will be inverted ); test.QaError += Test_QaError; _errorCount = 0; test.Execute(); Assert.AreEqual(3, _errorCount); test.QaError -= Test_QaError; var container = new TestContainer(); container.AddTest(test); container.QaError += Test_QaError; _errorCount = 0; container.Execute(); Assert.AreEqual(3, _errorCount); } }