Exemplo n.º 1
0
        private static ISpatialReference CreateDefaultSpatialReference()
        {
            var spatialReference =
                (ISpatialReference3)
                SpatialReferenceUtils.CreateSpatialReference(
                    WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            var controlPrecision = (IControlPrecision2)spatialReference;

            //Determines whether you are constructing a high or low.
            controlPrecision.IsHighPrecision = true;
            var spatialReferenceResolution =
                (ISpatialReferenceResolution)spatialReference;

            //These three methods are the keys, construct horizon, then set the default x,y resolution and tolerance.
            spatialReferenceResolution.ConstructFromHorizon();

            //Set the default x,y resolution value.
            spatialReferenceResolution.SetDefaultXYResolution();

            spatialReferenceResolution.set_XYResolution(true, 0.00001);
            spatialReferenceResolution.set_ZResolution(true, 0.00001);

            //Set the default x,y tolerance value.
            var spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference;

            spatialReferenceTolerance.XYTolerance = 0.0001;
            spatialReferenceTolerance.ZTolerance  = 0.0001;

            return(spatialReference);
        }
Exemplo n.º 2
0
        public void CanGetChangedVerticesSimplifiedZigZag()
        {
            // the source polyline visits the same points several times by going back and forth
            ISpatialReference lv95 =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IPolyline sourcePolyline = GeometryFactory.CreatePolyline(
                lv95,
                GeometryFactory.CreatePoint(0, 0),
                GeometryFactory.CreatePoint(10, 0),
                GeometryFactory.CreatePoint(20, 0),
                GeometryFactory.CreatePoint(10, 0),
                GeometryFactory.CreatePoint(20, 0),
                GeometryFactory.CreatePoint(30, 10));

            IPolyline simplifiedPolyline = GeometryFactory.Clone(sourcePolyline);

            const bool allowNonPlanarLines = false;
            string     nonSimpleReasonDescription;
            GeometryNonSimpleReason?nonSimpleReason;
            bool isSimple = GeometryUtils.IsGeometrySimple(sourcePolyline,
                                                           lv95,
                                                           allowNonPlanarLines,
                                                           out nonSimpleReasonDescription,
                                                           out nonSimpleReason);

            Assert.IsFalse(isSimple);

            GeometryUtils.Simplify(simplifiedPolyline, true, !allowNonPlanarLines);

            var geometryComparison = new GeometryComparison(
                sourcePolyline, simplifiedPolyline, 0.00125, 0.0125);

            const bool        reportDuplicateVertices = true;
            IList <WKSPointZ> changes = geometryComparison.GetDifferentVertices(false,
                                                                                reportDuplicateVertices);

            Assert.AreEqual(2, changes.Count);

            changes =
                geometryComparison.GetDifferentVertices(true, reportDuplicateVertices);
            Assert.AreEqual(2, changes.Count);

            changes = geometryComparison.GetDifferentVertices(true, false);
            Assert.AreEqual(0, changes.Count);

            geometryComparison = new GeometryComparison(
                simplifiedPolyline, sourcePolyline, 0.00125, 0.0125);

            changes =
                geometryComparison.GetDifferentVertices(false, reportDuplicateVertices);
            Assert.AreEqual(0, changes.Count);

            changes =
                geometryComparison.GetDifferentVertices(true, reportDuplicateVertices);
            Assert.AreEqual(2, changes.Count);

            changes = geometryComparison.GetDifferentVertices(true, false);
            Assert.AreEqual(0, changes.Count);
        }
Exemplo n.º 3
0
        public void CanDeterminePolygonReshapeSideInsideOnlySeveralParts()
        {
            ISpatialReference spatialReference = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IGeometry geometryToReshape =
                GeometryFactory.CreatePolygon(100, 100, 200, 200, spatialReference);

            IGeometry reshapeLine =
                GeometryFactory.CreatePolyline(spatialReference,
                                               GeometryFactory.CreatePoint(100, 200),
                                               GeometryFactory.CreatePoint(150, 100),
                                               GeometryFactory.CreatePoint(200, 200));

            ReshapeInfo reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape),
                                              reshapeLine, false);

            ExpectResult(reshapeInfo, RingReshapeSideOfLine.Left, 5000, 1, 1);

            const bool useNonDefaultSide = true;

            reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape),
                                  reshapeLine, useNonDefaultSide);

            ExpectResult(reshapeInfo, RingReshapeSideOfLine.Right, 5000, 2, 2);
        }
Exemplo n.º 4
0
        public void CanReshapeMultipatch()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

            IPolygon polygon = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 50, 20, lv95));

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(
                polygon);

            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2600000 - 100, 1200000),
                GeometryFactory.CreatePoint(2600000 + 100, 1200000));

            cutLine.SpatialReference = lv95;

            var reshapePath = (IPath)((IGeometryCollection)cutLine).Geometry[0];

            var reshapeInfo = new ReshapeInfo(multiPatch, reshapePath, null);

            IList <ReshapeInfo> singleReshapes;

            ReshapeUtils.ReshapeAllGeometryParts(reshapeInfo, reshapePath,
                                                 out singleReshapes);

            var reshapedRing = (IRing)((IGeometryCollection)multiPatch).Geometry[0];

            Assert.True(MathUtils.AreEqual(((IArea)reshapedRing).Area,
                                           ((IArea)polygon).Area / 2,
                                           0.1));
        }
Exemplo n.º 5
0
        public void CanCutMultipatchWithInnerRingThroughInnerRing()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

            IPolygon originalPoly = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 50, 50, lv95));

            IPolygon innerRingPoly = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95));
            var innerRing = (IRing)((IGeometryCollection)innerRingPoly).Geometry[0];

            innerRing.ReverseOrientation();

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly);

            GeometryFactory.AddRingToMultiPatch(innerRing, multiPatch,
                                                esriMultiPatchRingType
                                                .esriMultiPatchInnerRing);

            // cut line cuts through the inner ring
            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2600000 - 100, 1200000),
                GeometryFactory.CreatePoint(2600000 + 100, 1200000));

            cutLine.SpatialReference = lv95;

            IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch);

            var cutter = new FeatureCutter(new[] { mockFeature });

            cutter.ZSourceProvider =
                new DatasetSpecificSettingProvider <ChangeAlongZSource>(
                    string.Empty, ChangeAlongZSource.SourcePlane);

            cutter.Cut(cutLine);

            IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature];

            Assert.AreEqual(2, results.Count);

            double areaSum   = 0;
            var    partCount = 0;

            foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature])
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                areaSum +=
                    GeometryUtils.GetParts((IGeometryCollection)result)
                    .Sum(part => ((IArea)part).Area);

                partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count();
            }

            Assert.AreEqual(2, partCount);

            Assert.AreEqual(((IArea)originalPoly).Area + ((IArea)innerRing).Area,
                            areaSum, 0.0001);
        }
Exemplo n.º 6
0
        public void CanValidateReshapeLine()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IPath reshapePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600000.12, 1200000.12, sr),
                GeometryFactory.CreatePoint(2600000.121, 1200000.121, sr));

            IPolyline polyline = GeometryFactory.CreatePolyline(2600000, 1200000, 2600001,
                                                                1200001);
            var reshapeInfo = new ReshapeInfo(polyline, reshapePath, null);

            // It says it's closed but it's just a bit short
            Assert.IsTrue(reshapePath.IsClosed);
            Assert.IsFalse(reshapeInfo.ValidateReshapePath());

            // even with 3 points:
            WKSPoint middlePoint;

            middlePoint.X = 2600000.1205;
            middlePoint.Y = 1200000.1205;
            ((IPointCollection)reshapePath).InsertWKSPoints(1, 1, middlePoint);

            reshapeInfo = new ReshapeInfo(polyline, reshapePath, null);

            Assert.IsTrue(reshapePath.IsClosed);
            Assert.IsFalse(reshapeInfo.ValidateReshapePath());
        }
Exemplo n.º 7
0
        public void CanCreateFeatureWithoutTableSchema()
        {
            ISpatialReference sr =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IPolygon shape = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2600050, 1200080, sr));

            GdbObjectMsg featureMsg = new GdbObjectMsg
            {
                ClassHandle = -1,
                ObjectId    = 42,
                Shape       = ProtobufGeometryUtils.ToShapeMsg(shape)
            };

            GdbFeatureClass fClass =
                new GdbFeatureClass(1, "Test", esriGeometryType.esriGeometryPolygon);

            GdbRow gdbRow = ProtobufConversionUtils.FromGdbObjectMsg(featureMsg, fClass);

            GdbFeature feature = (GdbFeature)gdbRow;

            Assert.AreEqual(42, feature.OID);
            Assert.True(GeometryUtils.AreEqual(shape, feature.Shape));
            Assert.AreEqual(1, feature.Class.ObjectClassID);
        }
Exemplo n.º 8
0
        public void CanDetectNonUniqueSpatialReference()
        {
            ISpatialReference sref1 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);
            ISpatialReference sref2 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV03);
            ISpatialReference sref3 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            SpatialReferenceUtils.SetXYDomain(sref1, 0, 0, 1000, 1000, 0.001, 0.01);
            SpatialReferenceUtils.SetXYDomain(sref2, 0, 0, 1000, 1000, 0.00001, 0.0001);
            SpatialReferenceUtils.SetXYDomain(sref3, 0, 0, 1000, 1000, 0.0001, 0.001);

            var spatialReferences = new List <ISpatialReference> {
                sref1, sref2, sref3
            };

            string exception = null;

            try
            {
                TestUtils.GetUniqueSpatialReference(spatialReferences,
                                                    requireEqualVerticalCoordinateSystems
                                                    : true);
            }
            catch (Exception ex)
            {
                exception = ex.Message;
            }

            Assert.True(exception == "Coordinate systems are not equal: CH1903_LV03, CH1903+_LV95");
        }
        public void SetupFixture()
        {
            _lic.Checkout();

            _spatialReference = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);
        }
Exemplo n.º 10
0
        private IFeature CreateEmptyGeometryFeature(IFeatureWorkspace ws,
                                                    esriGeometryType geometryType,
                                                    IGeometry andAlso = null)
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference
                                       ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                       true);

            IFeatureClass featureClass =
                EnsureFeatureClass(ws, geometryType, geometryType.ToString(), sr);

            IGdbTransaction transaction = new GdbTransaction();

            IFeature feature  = null;
            bool     inserted = transaction.Execute((IWorkspace)ws, () =>
            {
                if (andAlso != null)
                {
                    andAlso.SpatialReference = sr;
                    IFeature nonEmpty        = featureClass.CreateFeature();
                    nonEmpty.Shape           = andAlso;
                    nonEmpty.Store();
                }

                feature = featureClass.CreateFeature();

                // NOTE: There is no difference when setting an empty geometry
                feature.Store();
            }, "Insert feature");

            Assert.IsTrue(inserted);

            return(feature);
        }
Exemplo n.º 11
0
        ///  <summary>
        ///  Returns two overlapping square polygons:
        ///
        ///         _____________
        ///        |             |
        ///        |    target   |
        ///  ______|______       |
        /// |      |      |      |
        /// |      |      |      |
        /// |      |______|______|
        /// |             |
        /// |	source    |
        /// |_____________|
        ///
        ///  </summary>
        ///  <param name="sourceFeature"></param>
        ///  <param name="targetFeature"></param>
        ///  <returns></returns>
        private static void GetOverlappingPolygons(out GdbFeature sourceFeature,
                                                   out GdbFeature targetFeature)
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolygon);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LN02);

            fClass.SpatialReference = sr;

            IPolygon polygon1 = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2601000, 1201000, sr));

            polygon1.SpatialReference = sr;

            sourceFeature = new GdbFeature(42, fClass)
            {
                Shape = polygon1
            };

            IPolygon polygon2 = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601500, 1201500, sr));

            polygon2.SpatialReference = sr;

            targetFeature = new GdbFeature(43, fClass)
            {
                Shape = polygon2
            };
        }
Exemplo n.º 12
0
        public void CanCreateBagWithCopies()
        {
            ISpatialReference sref =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);
            IGeometry pt1 = GeometryFactory.CreatePoint(100, 200, 0);
            IGeometry pt2 = GeometryFactory.CreatePoint(100, 200, 0);

            pt1.SpatialReference = sref;

            IGeometryBag bag = GeometryFactory.CreateBag(pt1, pt2);

            var collection = (IGeometryCollection)bag;

            Assert.AreEqual(2, collection.GeometryCount);
            IGeometry bagPt1 = collection.get_Geometry(0);
            IGeometry bagPt2 = collection.get_Geometry(1);

            // expect copies in the bag
            Assert.AreNotEqual(pt1, bagPt1);
            Assert.AreNotEqual(pt2, bagPt2);

            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bag.SpatialReference, true, true));
            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bagPt1.SpatialReference, true,
                                               true));
            Assert.IsTrue(
                SpatialReferenceUtils.AreEqual(sref, bagPt2.SpatialReference, true,
                                               true));
        }
        public void CanConvertToFromFeature()
        {
            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            var fClass = new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolygon);

            fClass.SpatialReference = sr;

            GdbFeature featureWithNoShape = new GdbFeature(41, fClass);

            AssertCanConvertToDtoAndBack(featureWithNoShape);

            IPolygon polygon = GeometryFactory.CreatePolygon(
                GeometryFactory.CreatePoint(2600000, 1200000, sr),
                GeometryFactory.CreatePoint(2601000, 1201000, sr));

            polygon.SpatialReference = sr;

            GdbFeature featureWithShape = new GdbFeature(42, fClass)
            {
                Shape = polygon
            };

            AssertCanConvertToDtoAndBack(featureWithShape);
        }
Exemplo n.º 14
0
        private static IFeatureWorkspace CreateTestWorkspace(
            [NotNull] string fgdbName,
            [NotNull] string fcName, [NotNull] string tableName, [NotNull] string relClassName,
            [NotNull] out IFeatureClass fc,
            [NotNull] out ITable table,
            [NotNull] out IRelationshipClass rc)
        {
            IFeatureWorkspace ws = TestWorkspaceUtils.CreateTestFgdbWorkspace(fgdbName);

            ISpatialReference sref = SpatialReferenceUtils.CreateSpatialReference(
                (int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true);

            fc = DatasetUtils.CreateSimpleFeatureClass(
                ws, fcName, null,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateIntegerField("FKEY"),
                FieldUtils.CreateShapeField(
                    "SHAPE", esriGeometryType.esriGeometryPoint,
                    sref, 1000));

            table = DatasetUtils.CreateTable(ws, tableName,
                                             FieldUtils.CreateOIDField(),
                                             FieldUtils.CreateTextField("TEXT", 100));

            rc = TestWorkspaceUtils.CreateSimple1NRelationship(
                ws, relClassName,
                table, (ITable)fc,
                table.OIDFieldName, "FKEY");

            return(ws);
        }
Exemplo n.º 15
0
        public void CanGetUniqueSpatialReferenceIgnoringVerticalCoordinateSystems()
        {
            ISpatialReference sref1 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);
            ISpatialReference sref2 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LN02);
            ISpatialReference sref3 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            const double maxRes = 0.00001;

            SpatialReferenceUtils.SetXYDomain(sref1, 0, 0, 1000, 1000, maxRes * 100,
                                              0.01);
            SpatialReferenceUtils.SetXYDomain(sref2, 0, 0, 1000, 1000, maxRes * 10,
                                              0.001);
            SpatialReferenceUtils.SetXYDomain(sref3, 0, 0, 1000, 1000, maxRes, 0.0001);

            var spatialReferences = new List <ISpatialReference> {
                sref1, sref2, sref3
            };

            ISpatialReference uniqueSpatialReference =
                TestUtils.GetUniqueSpatialReference(
                    spatialReferences, requireEqualVerticalCoordinateSystems: false);

            Assert.IsNotNull(uniqueSpatialReference);

            Assert.AreEqual(maxRes,
                            SpatialReferenceUtils.GetXyResolution(
                                uniqueSpatialReference));
        }
Exemplo n.º 16
0
        private static void VerifyErrorHasZ(IFeatureWorkspace ws)
        {
            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPolyline,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000, true, false));

            IFeatureClass featureClass =
                DatasetUtils.CreateSimpleFeatureClass(ws, "VerifyErrorHasZ", fields,
                                                      null);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            IPolycurve line1 = CurveConstruction.StartLine(0, 0, 5)
                               .LineTo(2, 0, 5)
                               .Curve;
            IFeature row1 = featureClass.CreateFeature();

            row1.Shape = line1;
            row1.Store();

            IPolycurve line2 = CurveConstruction.StartLine(-1, 0.02, 5)
                               .LineTo(1, 0.02, 5)
                               .Curve;
            IFeature row2 = featureClass.CreateFeature();

            row2.Shape = line2;
            row2.Store();

            var test = new QaNotNear(featureClass, 0.1, 0.5);

            var runners =
                new List <QaTestRunnerBase>
            {
                new QaTestRunner(test)
                {
                    KeepGeometry = true
                },
                new QaContainerTestRunner(1000, test)
                {
                    KeepGeometry = true
                }
            };

            foreach (QaTestRunnerBase runner in runners)
            {
                runner.Execute();
                Assert.True(runner.ErrorGeometries.Count > 0);
                foreach (IGeometry errorGeometry in runner.ErrorGeometries)
                {
                    Assert.AreEqual(5, errorGeometry.Envelope.ZMin);
                }
            }
        }
Exemplo n.º 17
0
        public void CanReadWriteMultipointXy()
        {
            var points = new WKSPointZ[4];

            points[0] = new WKSPointZ {
                X = 2600000, Y = 1200000, Z = double.NaN
            };
            points[1] = new WKSPointZ {
                X = 2600030, Y = 1200020, Z = double.NaN
            };
            points[2] = new WKSPointZ {
                X = 2600020, Y = 1200030, Z = double.NaN
            };
            points[3] = new WKSPointZ {
                X = 2600040, Y = 1200040, Z = double.NaN
            };

            ISpatialReference sr =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IMultipoint multipoint = GeometryFactory.CreateMultipoint(points, sr);

            GeometryUtils.MakeNonZAware(multipoint);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WriteMultipoint(multipoint);

            // ArcObjects
            byte[] arcObjectsWkb = GeometryUtils.ToWkb(multipoint);
            Assert.AreEqual(wkb, arcObjectsWkb);

            // Wkx
            byte[] wkx = ToChristianSchwarzWkb(ToWkxMultipoint(points, Ordinates.Xy));
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter     geomWriter = new WkbGeomWriter();
            Multipoint <IPnt> multipnt   = GeometryConversionUtils.CreateMultipoint(multipoint);

            byte[] wkbGeom = geomWriter.WriteMultipoint(multipnt, Ordinates.Xy);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IMultipoint restored = reader.ReadMultipoint(new MemoryStream(wkb));

            Assert.IsTrue(GeometryUtils.AreEqual(multipoint, restored));

            // Geom
            WkbGeomReader geomReader = new WkbGeomReader();

            Multipoint <IPnt> deserializedPnts =
                geomReader.ReadMultiPoint(new MemoryStream(wkbGeom));

            Assert.IsTrue(
                GeomRelationUtils.AreMultipointsEqualXY(multipnt, deserializedPnts,
                                                        double.Epsilon));
        }
Exemplo n.º 18
0
        private static ISpatialReference CreateSpatialReference()
        {
            ISpatialReference sref =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95, true);

            ((ISpatialReferenceResolution)sref).set_XYResolution(true, 0.01);
            return(sref);
        }
        public void CanDetermineNodeDegreeAtAreaOfInterestBoundaryOneEdgeFullyOutside()
        {
            // General idea: The southernmost edge can be traversed from the inside to the
            // outside, but not vice versa. Degree 3 should be determined correctly
            //  _______________________
            //  |                     |
            //  |    \     /          |
            //  |_____\___/___________|
            //         \ /
            //          |
            //          |
            //          |
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IEnvelope aoi = GeometryFactory.CreateEnvelope(2600000, 1200000, 2600100, 1200100, sr);

            FeatureClassMock edgeClass =
                new FeatureClassMock(1, "ROADS", esriGeometryType.esriGeometryPolyline);

            PolylineGraphConnectivity connectivity = new PolylineGraphConnectivity(sr, aoi);

            // Create node with degree 3 where one feature is partially outside the AOI

            IPoint junction = GeometryFactory.CreatePoint(2600050, 1199900, sr);

            FeatureMock feature1 =
                new FeatureMock(11, edgeClass)
            {
                Shape = GeometryFactory.CreatePolyline(
                    GeometryFactory.CreatePoint(2600050, 1199800, sr),
                    junction)
            };

            FeatureMock feature2 =
                new FeatureMock(12, edgeClass)
            {
                Shape = GeometryFactory.CreatePolyline(
                    junction,
                    GeometryFactory.CreatePoint(2600030, 1200050, sr))
            };

            FeatureMock feature3 =
                new FeatureMock(13, edgeClass)
            {
                Shape = GeometryFactory.CreatePolyline(
                    junction,
                    GeometryFactory.CreatePoint(2600070, 1200050, sr))
            };

            connectivity.AddConnectivity(feature1, false);
            connectivity.AddConnectivity(feature2, false);
            connectivity.AddConnectivity(feature3, false);

            var edges = connectivity.GetIncidentEdges(junction).ToList();

            Assert.AreEqual(0, edges.Count);
        }
Exemplo n.º 20
0
        public void CanSplitEdgeOnNodeInsertion()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            FeatureClassMock edgeClass, junctionClass;
            LinearNetworkDef networkDef = CreateSimpleNetworkDef(out edgeClass, out junctionClass);

            var networkFeatureFinder = new NetworkFeatureFinderMock();

            LinearNetworkEditAgent observer = new LinearNetworkEditAgent(
                networkDef, networkFeatureFinder);

            observer.NoCaching = true;

            // Existing feature:
            IPolyline edge1Polyline = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePoint(2600000, 1200000, 450, double.NaN, sr),
                GeometryFactory.CreatePoint(2600020, 1200010, 452, double.NaN, sr));

            IFeature existingFeature = CreateInOperation(
                () => CreateFeature(edgeClass, edge1Polyline), observer);

            Assert.AreEqual(1, observer.GetCreatedInLastOperation().Count());
            Assert.IsTrue(existingFeature == observer.GetCreatedInLastOperation().First());

            // New features get added to the feature finder's cache: 1 edge + 2 junctions
            Assert.AreEqual(3, networkFeatureFinder.TargetFeatureCandidates.Count);

            // Create edge snapped onto interior (Z actually does not matter):
            IPolyline edge2Polyline = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePoint(2600010, 1200010, 450, double.NaN, sr),
                GeometryFactory.CreatePoint(2600010, 1200005, 451, double.NaN, sr));

            IFeature snappedFeature = CreateInOperation(
                () => CreateFeature(edgeClass, edge2Polyline), observer);

            Assert.NotNull(snappedFeature);

            Assert.AreEqual(1, observer.GetCreatedInLastOperation().Count());

            // 3 original features + 1 new edge + 2 junctions + 1 new split-edge
            Assert.AreEqual(7, networkFeatureFinder.TargetFeatureCandidates.Count);

            // Now just add a junction feature
            IPoint junctionPoint =
                GeometryFactory.CreatePoint(2600002, 1200001, 450, double.NaN, sr);

            IFeature insertedJunction = CreateInOperation(
                () => CreateFeature(junctionClass, junctionPoint), observer);

            Assert.NotNull(insertedJunction);

            Assert.AreEqual(1, observer.GetCreatedInLastOperation().Count());

            // 7 original features + 1 new junction + 1 new split-edge
            Assert.AreEqual(9, networkFeatureFinder.TargetFeatureCandidates.Count);
        }
Exemplo n.º 21
0
        public void CanGetOpenJawReshapeLineReplaceEndPoint()
        {
            var fClass =
                new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolyline);

            var sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95,
                WellKnownVerticalCS.LN02);

            fClass.SpatialReference = sr;

            IPath sourcePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600500, 1200000, sr),
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2601000, 1200500, sr));

            sourcePath.SpatialReference = sr;

            IPolyline sourcePolyline = GeometryFactory.CreatePolyline(sourcePath);

            GdbFeature sourceFeature = new GdbFeature(42, fClass)
            {
                Shape = sourcePolyline
            };

            IPath reshapePath = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600500, 1200500, sr),
                GeometryFactory.CreatePoint(2600500, 1201000, sr));

            reshapePath.SpatialReference = sr;

            IPolyline reshapePolyline = GeometryFactory.CreatePolyline(reshapePath);

            var sourceFeatureMsg = ProtobufGdbUtils.ToGdbObjectMsg(sourceFeature);
            var reshapePathMsg   = ProtobufGeometryUtils.ToShapeMsg(reshapePolyline);

            var request = new OpenJawReshapeLineReplacementRequest
            {
                Feature     = sourceFeatureMsg,
                ReshapePath = reshapePathMsg
            };

            ShapeMsg response =
                AdvancedReshapeServiceUtils.GetOpenJawReshapeReplaceEndPoint(request);

            IPoint resultPoint = (IPoint)ProtobufGeometryUtils.FromShapeMsg(response);

            Assert.IsTrue(GeometryUtils.AreEqual(sourcePolyline.ToPoint, resultPoint));

            // Non-default side:
            request.UseNonDefaultReshapeSide = true;

            response =
                AdvancedReshapeServiceUtils.GetOpenJawReshapeReplaceEndPoint(request);
            resultPoint = (IPoint)ProtobufGeometryUtils.FromShapeMsg(response);

            Assert.IsTrue(GeometryUtils.AreEqual(sourcePolyline.FromPoint, resultPoint));
        }
Exemplo n.º 22
0
        public void CanGetRasterFileFromMosaicDatasetUsingSpatialQuery()
        {
            IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle();

            IMosaicDataset mosaicDataset = DatasetUtils.OpenMosaicDataset(workspace,
                                                                          "TOPGIS_TLM.TLM_DTM_MOSAIC");

            IFeatureClass rasterCatalog = mosaicDataset.Catalog;

            IEnvelope winterthur = GeometryFactory.CreateEnvelope(
                2690000, 1254000, 2707500, 1266000,
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95));

            winterthur.Expand(-0.1, -0.1, false);

            IQueryFilter spatialFilter =
                GdbQueryUtils.CreateSpatialFilter(rasterCatalog, winterthur);

            IStringArray stringArray;
            Stopwatch    watch = Stopwatch.StartNew();

            int count = 0;

            foreach (IFeature catalogFeature in GdbQueryUtils.GetFeatures(
                         rasterCatalog, spatialFilter, false))
            {
                // Method 1 (slow):
                var rasterCatalogItem = (IRasterCatalogItem)catalogFeature;

                IRasterDataset rasterDataset = rasterCatalogItem.RasterDataset;
                var            itemPaths     = (IItemPaths)rasterDataset;
                stringArray = itemPaths.GetPaths();
                Marshal.ReleaseComObject(rasterDataset);

                Assert.AreEqual(1, stringArray.Count);

                string resultPathViaRasterDataset = stringArray.Element[0];

                // Method 2 (fast):
                var itemPathsQuery = (IItemPathsQuery)mosaicDataset;

                if (itemPathsQuery.QueryPathsParameters == null)
                {
                    itemPathsQuery.QueryPathsParameters = new QueryPathsParametersClass();
                }

                stringArray = itemPathsQuery.GetItemPaths(catalogFeature);
                Assert.AreEqual(1, stringArray.Count);

                string resultPathViaItemPathsQuery = stringArray.Element[0];
                Assert.AreEqual(resultPathViaRasterDataset, resultPathViaItemPathsQuery);
                count++;
            }

            Console.WriteLine("Successfully extracted {0} raster paths in {1}s", count,
                              watch.Elapsed.TotalSeconds);
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
 public void SetUp()
 {
     _wgs84 = SpatialReferenceUtils.CreateSpatialReference(
         (int)esriSRGeoCSType.esriSRGeoCS_WGS1984,
         true);
     _lv95 = SpatialReferenceUtils.CreateSpatialReference(
         WellKnownHorizontalCS.LV95,
         true);
 }
        private static ISpatialReference CreateLV95()
        {
            ISpatialReference result = SpatialReferenceUtils.CreateSpatialReference
                                           ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true);

            SpatialReferenceUtils.SetXYDomain(result, -10000, -10000, 10000, 10000,
                                              0.0001, _xyTolerance);
            return(result);
        }
Exemplo n.º 26
0
        public void CanFindJunctionAtEdgeEnd()
        {
            const string fgdbName = "NetworkJunctionFinderTest.gdb";

            // Create FGDB with test features:
            IFeatureClass edgeClass, junctionClass;
            LinearNetworkGdbFeatureFinder featureFinder =
                CreateTestGdbSchema(fgdbName, out edgeClass, out junctionClass);

            ISpatialReference lv95 =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            IPoint fromPoint1 = GeometryFactory.CreatePoint(2600000, 1200000, lv95);
            IPoint toPoint1   = GeometryFactory.CreatePoint(2600020, 1200010, lv95);

            CreateEdge(edgeClass, fromPoint1, toPoint1);

            Assert.AreEqual(0, featureFinder.FindJunctionFeaturesAt(fromPoint1).Count);
            Assert.AreEqual(0, featureFinder.FindJunctionFeaturesAt(toPoint1).Count);

            IFeature from1Junction = CreateJunction(junctionClass, fromPoint1);

            IList <IFeature> found = featureFinder.FindJunctionFeaturesAt(fromPoint1);

            Assert.AreEqual(1, found.Count);
            Assert.AreEqual(from1Junction.OID, found[0].OID);

            Assert.AreEqual(0, featureFinder.FindJunctionFeaturesAt(toPoint1).Count);

            // Duplicate junction (different Z)
            fromPoint1.Z = 123;
            IFeature fromJunction2 = CreateJunction(junctionClass, fromPoint1);

            found = featureFinder.FindJunctionFeaturesAt(fromPoint1);
            Assert.AreEqual(2, found.Count);
            Assert.AreNotEqual(found[0].OID, found[1].OID);

            Assert.IsTrue(found.Any(
                              j => GdbObjectUtils.IsSameObject(
                                  j, fromJunction2, ObjectClassEquality.SameInstance)));

            Assert.IsTrue(found[0].Class == junctionClass && found[1].Class == junctionClass);

            // Stand-alone junction
            IPoint disjointPoint = GeometryFactory.CreatePoint(2600025, 1200011, lv95);

            found = featureFinder.FindJunctionFeaturesAt(disjointPoint);
            Assert.AreEqual(0, found.Count);

            IFeature standalone = CreateJunction(junctionClass, disjointPoint);

            found = featureFinder.FindJunctionFeaturesAt(disjointPoint);
            Assert.AreEqual(1, found.Count);
            Assert.IsTrue(GdbObjectUtils.IsSameObject(found[0], standalone,
                                                      ObjectClassEquality.SameInstance));
        }
Exemplo n.º 27
0
        private static ISpatialReference CreateSpatialReference()
        {
            ISpatialReference spatialReference =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95);

            SpatialReferenceUtils.SetXYDomain(spatialReference,
                                              -1000, -1000, 1000, 1000,
                                              0.0001, 0.001);
            return(spatialReference);
        }
        private static ISpatialReference CreateSpatialReference()
        {
            ISpatialReference result = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, true);

            SpatialReferenceUtils.SetXYDomain(result, -100000, -100000, 100000, 100000,
                                              _resolution, _tolerance);

            return(result);
        }
Exemplo n.º 29
0
        public void CanCreateGdbFeatureClass()
        {
            // An in-memory backing dataset is created automatically, if no factory method is provided
            GdbFeatureClass gdbFeatureClass =
                new GdbFeatureClass(41, "TESTABLE", esriGeometryType.esriGeometryPoint,
                                    "Test table");

            IFeatureClass featureClass = gdbFeatureClass;

            Assert.AreEqual(41, featureClass.ObjectClassID);
            Assert.AreEqual("TESTABLE", DatasetUtils.GetName(featureClass));
            Assert.AreEqual("Test table",
                            DatasetUtils.GetAliasName(featureClass));
            Assert.AreEqual(esriGeometryType.esriGeometryPoint,
                            featureClass.ShapeType);

            Assert.False(featureClass.HasOID);
            Assert.Null(featureClass.OIDFieldName);

            Assert.AreEqual(0, GdbQueryUtils.Count(featureClass, ""));

            // Add OID field
            gdbFeatureClass.AddField(FieldUtils.CreateOIDField());

            // Add Shape field
            gdbFeatureClass.AddField(
                FieldUtils.CreateShapeField(
                    esriGeometryType.esriGeometryPoint,
                    SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)));

            Assert.True(featureClass.HasOID);
            Assert.AreEqual("OBJECTID", featureClass.OIDFieldName);
            Assert.AreEqual("SHAPE", featureClass.ShapeFieldName);

            IQueryFilter queryFilter = GdbQueryUtils.CreateQueryFilter("OBJECTID");

            queryFilter.WhereClause = "OBJECTID < 0";

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            var backingDataset = gdbFeatureClass.BackingDataset as InMemoryDataset;

            Assert.NotNull(backingDataset);

            backingDataset.AllRows.Add(new GdbRow(1, gdbFeatureClass));

            Assert.AreEqual(0,
                            GdbQueryUtils.Count(featureClass, queryFilter));

            queryFilter.WhereClause = "OBJECTID > 0";

            Assert.AreEqual(1,
                            GdbQueryUtils.Count(featureClass, queryFilter));
        }
Exemplo n.º 30
0
        public void CanKeepConnectedStableOnMerge()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            FeatureClassMock edgeClass, junctionClass;
            LinearNetworkDef networkDef = CreateSimpleNetworkDef(out edgeClass, out junctionClass);

            var networkFeatureFinder = new NetworkFeatureFinderMock();

            LinearNetworkEditAgent observer = new LinearNetworkEditAgent(
                networkDef, networkFeatureFinder)
            {
                NoCaching = true
            };

            // Existing feature:
            IPolyline edge1Polyline = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePoint(2600000, 1200000, 450, double.NaN, sr),
                GeometryFactory.CreatePoint(2600020, 1200010, 452, double.NaN, sr));

            IFeature existingFeature = CreateInOperation(
                () => CreateFeature(edgeClass, edge1Polyline), observer);

            // Add a connected edge feature:
            IPolyline edge2Polyline =
                GeometryFactory.CreatePolyline(
                    GeometryFactory.CreatePoint(2600020, 1200010, 452, double.NaN, sr),
                    GeometryFactory.CreatePoint(2600030, 1200005, 450, double.NaN, sr));

            IPolyline edge2PolylineOrig = GeometryFactory.Clone(edge2Polyline);

            IFeature secondEdge = CreateInOperation(
                () => CreateFeature(edgeClass, edge2Polyline), observer);

            Assert.NotNull(secondEdge);
            Assert.AreEqual(1, observer.GetCreatedInLastOperation().Count());

            IPolyline edge3Polyline =
                GeometryFactory.CreatePolyline(
                    GeometryFactory.CreatePoint(2600020, 1200010, 452, double.NaN, sr),
                    GeometryFactory.CreatePoint(2600030, 1200015, 450, double.NaN, sr));

            IFeature thirdEdge = CreateInOperation(
                () => CreateFeature(edgeClass, edge3Polyline), observer);

            // Now merge features 1 and 2:
            MergeInOperation(existingFeature, thirdEdge, observer);

            Assert.AreEqual(1, observer.GetUpdatedInLastOperation().Count());

            // Make sure the second edge has not changed:
            Assert.IsTrue(GeometryUtils.AreEqual(edge2PolylineOrig, secondEdge.Shape));
        }