コード例 #1
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));
        }
コード例 #2
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);
        }
コード例 #3
0
        public void CanTestEmptyGeometrySdeMultipatch()
        {
            IWorkspace workspace = TestUtils.OpenUserWorkspaceOracle();
            //IWorkspace workspace = ProSuite.Commons.AO.Test.TestUtils.OpenSDEWorkspaceOracle();

            IMultiPatch normalGeometry = GeometryFactory.CreateMultiPatch(
                GeometryFactory.CreateRing(new[]
            {
                new WKSPointZ {
                    X = 2600000, Y = 1200000, Z = 400
                },
                new WKSPointZ {
                    X = 2600000, Y = 1200100, Z = 400
                },
                new WKSPointZ {
                    X = 2600100, Y = 1200000, Z = 400
                },
                new WKSPointZ {
                    X = 2600000, Y = 1200000, Z = 400
                },
            }));

            GeometryUtils.MakeZAware(normalGeometry);

            IFeature feature =
                CreateEmptyGeometryFeature((IFeatureWorkspace)workspace,
                                           esriGeometryType.esriGeometryMultiPatch, normalGeometry);

            AssertOneErrorEmptyGeometry((IFeatureClass)feature.Class);
        }
コード例 #4
0
 public void CanSearchSingleMultipatch()
 {
     AssertCanFindGeometry(
         GeometryFactory.CreateMultiPatch(
             GeometryFactory.CreatePolygon(1000, 1000,
                                           2000, 2000,
                                           100)));
 }
コード例 #5
0
        public void CanTestMultiPatch()
        {
            IPolygon polygon =
                GeometryFactory.CreatePolygon(GeometryFactory.CreateEnvelope(0, 0, 10, 10,
                                                                             100, 100));

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(polygon, 10);

            multiPatch.SpatialReference = CreateSpatialReference();
            multiPatch.SnapToSpatialReference();

            AssertFulfilled("$ISCLOSED IS NULL", multiPatch);
            AssertFulfilled("$CIRCULARARCCOUNT = 0", multiPatch);
            AssertFulfilled("$ELLIPTICARCCOUNT = 0", multiPatch);
            AssertFulfilled("$BEZIERCOUNT = 0", multiPatch);
            AssertFulfilled("$SEGMENTCOUNT = 0", multiPatch);
            AssertFulfilled("$LINEARSEGMENTCOUNT = 0", multiPatch);
            AssertFulfilled("$NONLINEARSEGMENTCOUNT = 0", multiPatch);
            AssertFulfilled("$PARTCOUNT = 3", multiPatch);             // 2 rings, one triangle strip
            AssertFulfilled("$VERTEXCOUNT = 20", multiPatch);
            AssertFulfilled("$ISMULTIPART", multiPatch);
            AssertFulfilled("$AREA = 100", multiPatch);
            AssertFulfilled("$LENGTH = 40", multiPatch);
            AssertFulfilled("$SLIVERRATIO = 16", multiPatch);
            AssertFulfilled("$DIMENSION = 2", multiPatch);
            AssertFulfilled("$INTERIORRINGCOUNT = 0", multiPatch);
            AssertFulfilled("$EXTERIORRINGCOUNT = 2", multiPatch);
            AssertFulfilled("$RINGCOUNT = 2", multiPatch);
            AssertFulfilled("$TRIANGLEFANCOUNT = 0", multiPatch);
            AssertFulfilled("$TRIANGLESTRIPCOUNT = 1", multiPatch);
            AssertFulfilled("$TRIANGLESPATCHCOUNT = 0", multiPatch);
            AssertFulfilled("NOT $ISEXTERIORRING", multiPatch);
            AssertFulfilled("NOT $ISINTERIORRING", multiPatch);
            AssertFulfilled("$XMIN = 0", multiPatch);
            AssertFulfilled("$YMIN = 0", multiPatch);
            AssertFulfilled("$XMAX = 10", multiPatch);
            AssertFulfilled("$YMAX = 10", multiPatch);
            AssertFulfilled("$ZMIN = 100", multiPatch);
            AssertFulfilled("$ZMAX = 110", multiPatch);
            AssertFulfilled("$MMIN IS NULL", multiPatch);
            AssertFulfilled("$MMAX IS NULL", multiPatch);
            AssertFulfilled("$UNDEFINEDMVALUECOUNT = 20", multiPatch);
            AssertFulfilled("$CONTROLPOINTCOUNT = 0", multiPatch);
        }
コード例 #6
0
        public void CanCutMultipatch()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

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

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly);

            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;

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

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

            Assert.IsTrue(MathUtils.AreEqual(((IArea)originalPoly).Area, areaSum));
        }
コード例 #7
0
        public void CanCreateSpatialFilterWithMultipatch()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc);

            IEnvelope largeEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                     2601000, 1201000,
                                                                     445, spatialReference);

            IMultiPatch multiPatch =
                GeometryFactory.CreateMultiPatch(GeometryFactory.CreatePolygon(largeEnvelope));

            double xyResolution =
                SpatialReferenceUtils.GetXyResolution(Assert.NotNull(spatialReference));

            // NOTE: Multipatch implements IRelationalOperator since a while!
            IGeometry validGeometry;
            string    message;

            Assert.True(GdbQueryUtils.IsValidFilterGeometry(
                            multiPatch, xyResolution, out validGeometry, out message),
                        "Multipatch should be valid");
            Assert.NotNull(validGeometry);
            Assert.True(multiPatch == validGeometry,
                        "Multipatch should be valid");

            Assert.True(GdbQueryUtils.IsValidFilterGeometry(
                            validGeometry, xyResolution, out validGeometry, out message),
                        "Corrected geometry should be valid");

            IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(
                fc, multiPatch, esriSpatialRelEnum.esriSpatialRelIntersects, false,
                spatialReference);

            Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found.");
        }
コード例 #8
0
        public void CanReadWriteMultipartPolygonXyz()
        {
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            IPolygon outerRing =
                GeometryFactory.CreatePolygon(2600000, 1200000, 2601000, 1201000, 432);

            outerRing.SpatialReference = sr;
            IPolygon innerRing =
                GeometryFactory.CreatePolygon(2600100, 1200100, 2600200, 1200200, 421);

            innerRing.SpatialReference = sr;

            IPolygon polyWithHole = (IPolygon)IntersectionUtils.Difference(outerRing, innerRing);

            IPolygon poly2 = GeometryFactory.CreatePolygon(2610000, 1200000, 2611000, 1201000, 543);

            poly2.SpatialReference = sr;

            IPolygon multiPolygon = (IPolygon)GeometryUtils.Union(polyWithHole, poly2);

            Assert.IsTrue(GeometryUtils.IsZAware(multiPolygon));

            GeometryUtils.Simplify(multiPolygon);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WritePolygon(multiPolygon);

            // Wkx
            var ordinates                        = Ordinates.Xyz;
            IList <IGeometry> parts              = GeometryUtils.GetParts(multiPolygon).ToList();
            IGeometry         exteriorRing       = parts[0];
            IGeometry         interiorRing       = parts[1];
            IGeometry         secondExteriorRing = parts[2];

            LinearRing wkxOuterRing = ToWkxLinearRing(exteriorRing, ordinates);
            LinearRing wkxInnerRing = ToWkxLinearRing(interiorRing, ordinates);

            Polygon wkxPolygon1 = ToWkxPolygon(wkxOuterRing, new[] { wkxInnerRing });
            Polygon wkxPolygon2 = ToWkxPolygon(ToWkxLinearRing(secondExteriorRing, ordinates));

            MultiPolygon wkxMultiPolygon = new MultiPolygon(new[] { wkxPolygon1, wkxPolygon2 });

            byte[] wkx = ToChristianSchwarzWkb(wkxMultiPolygon);
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter  geomWriter = new WkbGeomWriter();
            MultiPolycurve multiPly   = GeometryConversionUtils.CreateMultiPolycurve(multiPolygon);

            byte[] wkbGeom = geomWriter.WriteMultipolygon(multiPly, ordinates);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IPolygon restored = reader.ReadPolygon(new MemoryStream(wkb));

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

            // Geom:
            WkbGeomReader     geomReader       = new WkbGeomReader();
            IList <RingGroup> readMultiPolygon =
                geomReader.ReadMultiPolygon(new MemoryStream(wkbGeom));
            var readMultiPolycurve = new MultiPolycurve(
                readMultiPolygon.SelectMany(g => g.GetLinestrings()));

            Assert.IsTrue(multiPly.Equals(readMultiPolycurve));

            // As multipatch
            IMultiPatch multipatch = GeometryFactory.CreateMultiPatch(multiPolygon);

            wkb = writer.WriteMultipatch(multipatch);

            IMultiPatch readMultipatch = (IMultiPatch)reader.ReadGeometry(new MemoryStream(wkb));

            // TODO: Implement AreEqual for multipatch that is more permissive regarding First/Outer ring type
            AssertEqual(multipatch, readMultipatch);
        }