Exemplo n.º 1
0
        public void CanMatchRows()
        {
            const string  textField1    = "Text1";
            const string  textField2    = "Text2";
            const string  textFieldBoth = "Text";
            IFeatureClass fc1           = CreateFeatureClass("CanMatchRows_fc1",
                                                             esriGeometryType.esriGeometryPolygon,
                                                             FieldUtils.CreateTextField(textField1, 1),
                                                             FieldUtils.CreateTextField(textFieldBoth, 1));
            IFeatureClass fc2 = CreateFeatureClass("CanMatchRows_fc2",
                                                   esriGeometryType.esriGeometryPolygon,
                                                   FieldUtils.CreateTextField(textFieldBoth, 1),
                                                   FieldUtils.CreateTextField(textField2, 1));

            const bool     caseSensitive = true;
            MultiTableView view          = TableViewFactory.Create(new[] { (ITable)fc1, (ITable)fc2 },
                                                                   new[] { "G1", "G2" },
                                                                   "G1.TEXT1 = G2.TEXT2 AND G1.Text = 'x' AND G2.Text = 'y'",
                                                                   caseSensitive);

            IFeature f1A = fc1.CreateFeature();

            f1A.Value[fc1.FindField(textField1)]    = "A";
            f1A.Value[fc1.FindField(textFieldBoth)] = "x";
            f1A.Store();

            IFeature f2A = fc2.CreateFeature();

            f2A.Value[fc2.FindField(textField2)]    = "A";
            f2A.Value[fc2.FindField(textFieldBoth)] = "y";
            f2A.Store();

            Assert.IsTrue(view.MatchesConstraint(f1A, f2A));
            Assert.AreEqual("G1.TEXT1 = 'A'; G2.TEXT2 = 'A'; G1.TEXT = 'x'; G2.TEXT = 'y'",
                            view.ToString(f1A, f2A));

            IFeature f1B = fc1.CreateFeature();

            f1B.Value[fc1.FindField(textField1)]    = "b";
            f1B.Value[fc1.FindField(textFieldBoth)] = "x";
            f1B.Store();

            IFeature f2B = fc2.CreateFeature();

            f2B.Value[fc2.FindField(textField2)]    = "B";          // different case --> no match
            f2B.Value[fc2.FindField(textFieldBoth)] = "y";
            f2B.Store();

            Assert.IsFalse(view.MatchesConstraint(f1B, f2B));
            Assert.AreEqual("G1.TEXT1 = 'b'; G2.TEXT2 = 'B'; G1.TEXT = 'x'; G2.TEXT = 'y'",
                            view.ToString(f1B, f2B));
        }
Exemplo n.º 2
0
        public void CanUseShapeAreaAlias()
        {
            IFeatureClass fc1 = CreateFeatureClass("CanUseShapeAreaAlias_fc1",
                                                   esriGeometryType.esriGeometryPolygon);
            IFeatureClass fc2 = CreateFeatureClass("CanUseShapeAreaAlias_fc2",
                                                   esriGeometryType.esriGeometryPolygon);

            const bool     caseSensitive = true;
            MultiTableView view          = TableViewFactory.Create(new[] { (ITable)fc1, (ITable)fc2 },
                                                                   new[] { "G1", "G2" },
                                                                   "G1.$ShapeArea < G2.$ShapeArea",
                                                                   caseSensitive);

            IFeature f1A = fc1.CreateFeature();

            f1A.Shape = GeometryFactory.CreatePolygon(0, 0, 10, 10);
            f1A.Store();

            IFeature f1B = fc1.CreateFeature();

            f1B.Shape = GeometryFactory.CreatePolygon(0, 0, 100, 100);
            f1B.Store();

            IFeature f2A = fc2.CreateFeature();

            f2A.Shape = GeometryFactory.CreatePolygon(0, 0, 100, 100);
            f2A.Store();

            IFeature f2B = fc2.CreateFeature();

            f2B.Shape = GeometryFactory.CreatePolygon(0, 0, 10, 10);
            f2B.Store();

            Assert.IsTrue(view.MatchesConstraint(f1A, f2A));
            Assert.AreEqual("G1.$SHAPEAREA = 100; G2.$SHAPEAREA = 10000",
                            view.ToString(f1A, f2A));

            Assert.IsFalse(view.MatchesConstraint(f1B, f2B));
            Assert.AreEqual("G1.$SHAPEAREA = 10000; G2.$SHAPEAREA = 100",
                            view.ToString(f1B, f2B));
        }
Exemplo n.º 3
0
        private int CheckConstraint([NotNull] DirectedRow line,
                                    [CanBeNull] IRow centroid)
        {
            if (_constraintHelper == null && centroid != null)
            {
                _constraintHelper = CreateConstraintHelper(
                    line.Row.Row.Table, centroid.Table);
            }

            Assert.Null(line.LeftCentroid, "left centroid is not null");

            var errorCount = 0;

            if (line.RightCentroid != null)
            {
                var lineFeature = (IFeature)line.Row.Row;

                if (centroid != null &&
                    !_constraintHelper.MatchesConstraint(lineFeature,
                                                         centroid,
                                                         line.RightCentroid))
                {
                    errorCount +=
                        ReportError(
                            _constraintHelper.ToString(lineFeature,
                                                       centroid,
                                                       line.RightCentroid),
                            lineFeature.Shape,
                            Codes[Code.DoesNotMatchConstraint], null,
                            lineFeature, centroid, line.RightCentroid);
                }

                line.RightCentroid = null;
            }
            else
            {
                line.LeftCentroid = centroid;
            }

            return(errorCount);
        }
Exemplo n.º 4
0
        private string GetErrorDescription([NotNull] IRow row, [NotNull] IRow touchingRow,
                                           out IssueCode issueCode)
        {
            if (_compareHelper != null)
            {
                issueCode = Codes[Code.PolygonsTouch_ConstraintNotFulfilled];
                return(string.Format("Constraint '{0}' is not fulfilled: {1}",
                                     _constraint,
                                     _compareHelper.ToString(row, touchingRow)));
            }

            const string defaultMessage = "Polygons touch (no fields to compare)";

            if (_compareFieldIndexes != null)
            {
                if (_comparedFieldsString == null)
                {
                    _comparedFieldsString = GetCompareFieldsString(_polygonClass,
                                                                   _compareFieldIndexes);
                }

                if (_comparedFieldsString.Length == 0)
                {
                    issueCode = Codes[Code.PolygonsTouch_NoFieldsToCompare];
                    return(defaultMessage);
                }

                issueCode = Codes[Code.PolygonsTouch_AllFieldsEqual];
                return(string.Format(
                           "Polygons touch and have equal values for all compared fields ({0})",
                           _comparedFieldsString));
            }

            issueCode = Codes[Code.PolygonsTouch_NoFieldsToCompare];
            return(defaultMessage);
        }