public void SetupFixture()
        {
            _lic.Checkout();

            _spatialReference = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);
        }
Exemplo n.º 2
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.º 3
0
        public void CanGetBoundaryBoundaryIntersectionLinesAndPoints()
        {
            const string matrixString = "****T****";

            IPolygon g1 = GeometryFactory.CreatePolygon(0, 0, 10, 10, 100);
            IPolygon g2 = GeometryFactory.CreatePolygon(5, 0, 15, 15, 1000);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            var matrix = new IntersectionMatrix(matrixString);

            IList <IGeometry> intersections = matrix.GetIntersections(g1, g2);

            WriteGeometries(intersections);

            Assert.AreEqual(2, intersections.Count);

            var polyline = (IPolyline)intersections[0];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(polyline));

            var multipoint = (IMultipoint)intersections[1];

            Assert.AreEqual(1, GeometryUtils.GetPartCount(multipoint));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         multipoint.SpatialReference));
        }
Exemplo n.º 4
0
        public void CanGetMultipointPolygonCrossesIntersection()
        {
            var matrix = new IntersectionMatrix("T*T******");

            IMultipoint g1 = GeometryFactory.CreateMultipoint(
                GeometryFactory.CreatePoint(5, 5, 0),
                GeometryFactory.CreatePoint(10, 5, 0),
                GeometryFactory.CreatePoint(15, 5, 0));
            IPolygon g2 = GeometryFactory.CreatePolygon(0, 0, 10, 10, 0);

            g1.SpatialReference = _spatialReference;
            g2.SpatialReference = _spatialReference;

            IList <IGeometry> result12 = matrix.GetIntersections(g1, g2);

            Assert.AreEqual(1, result12.Count);
            Console.WriteLine(GeometryUtils.ToString(result12[0]));
            Assert.AreEqual(2, GeometryUtils.GetPointCount(result12));
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(_spatialReference,
                                                         result12[0].SpatialReference));

            IList <IGeometry> result21 = matrix.GetIntersections(g2, g1);

            Assert.AreEqual(1, result21.Count);
            Console.WriteLine(GeometryUtils.ToString(result21[0]));
            Assert.IsTrue(
                GeometryUtils.AreEqualInXY(result21[0],
                                           g2));                 // can't subtract, same as g2
        }
Exemplo n.º 5
0
        public void CanCreateSpatialFilterWithNonZSimpleGeometry()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IEnvelope nonZSimpleEnvelope = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                          2700000, 1300000);

            GeometryUtils.MakeZAware(nonZSimpleEnvelope);

            Assert.False(((IZAware)nonZSimpleEnvelope).ZSimple, "Must be non-Z-simple");

            ISpatialReference spatialReference =
                Assert.NotNull(DatasetUtils.GetSpatialReference(fc));

            IGeometry validGeometry;
            string    message;

            Assert.False(GdbQueryUtils.IsValidFilterGeometry(
                             nonZSimpleEnvelope,
                             SpatialReferenceUtils.GetXyResolution(spatialReference),
                             out validGeometry, out message),
                         "Search geometry should not be valid");

            Assert.NotNull(validGeometry);

            IQueryFilter filter = GdbQueryUtils.CreateSpatialFilter(fc, nonZSimpleEnvelope);

            Assert.True(GdbQueryUtils.GetFeatures(fc, filter, true).Any(), "No features found");
        }
Exemplo n.º 6
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.º 7
0
        private ISpatialReference GetUniqueErrorFeatureClassSpatialReference()
        {
            ISpatialReference result = null;

            foreach (IssueDatasetWriter issueWriter in GetIssueWriters())
            {
                if (issueWriter.SpatialReference == null)
                {
                    continue;
                }

                if (result == null)
                {
                    result = issueWriter.SpatialReference;
                }
                else
                {
                    const bool compareTolerances = false;
                    if (!SpatialReferenceUtils.AreEqualXYZ(result,
                                                           issueWriter.SpatialReference,
                                                           compareTolerances))
                    {
                        throw new InvalidOperationException(
                                  "The spatial references of all issue feature classes " +
                                  "(including xy and z precision and tolerances) must be equal");
                    }
                }
            }

            return(Assert.NotNull(result, "spatialReference"));
        }
Exemplo n.º 8
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.º 9
0
        private static IGeometryDef CreateGeometryDef(
            esriGeometryType geometryType,
            [NotNull] ISpatialReference spatialReference,
            double gridSize1,
            double gridSize2,
            double gridSize3,
            bool hasZ,
            bool hasM)
        {
            IGeometryDefEdit result = new GeometryDefClass();

            ISpatialReference highPrecisionSpatialReference;

            SpatialReferenceUtils.EnsureHighPrecision(spatialReference,
                                                      out highPrecisionSpatialReference);

            result.GeometryType_2     = geometryType;
            result.HasZ_2             = hasZ;
            result.HasM_2             = hasM;
            result.SpatialReference_2 = highPrecisionSpatialReference;

            ConfigureSpatialIndexGrid(result, gridSize1, gridSize2, gridSize3);

            return(result);
        }
Exemplo n.º 10
0
        public IssueRepository([NotNull] IssueRowWriter rowWriter,
                               [NotNull] IEnumerable <IssueFeatureWriter> featureWriters,
                               [NotNull] IIssueTableFields fields,
                               [NotNull] IFeatureWorkspace featureWorkspace)
        {
            Assert.ArgumentNotNull(rowWriter, nameof(rowWriter));
            Assert.ArgumentNotNull(featureWriters, nameof(featureWriters));
            Assert.ArgumentNotNull(fields, nameof(fields));
            Assert.ArgumentNotNull(featureWorkspace, nameof(featureWorkspace));

            FeatureWorkspace = featureWorkspace;
            _rowWriter       = rowWriter;
            _featureWriters  = featureWriters.ToList();

            _issueWritersByGeometryType = GetIssueWritersByGeometryType(rowWriter,
                                                                        _featureWriters);

            _issueDatasets = GetIssueDatasets(rowWriter, _featureWriters, fields);

            if (_featureWriters.Count > 0)
            {
                _spatialReference =
                    SpatialReferenceUtils.GetUniqueSpatialReference(
                        GetSpatialReferences(_featureWriters),
                        comparePrecisionAndTolerance: true,
                        compareVerticalCoordinateSystems: true);
            }
        }
Exemplo n.º 11
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.º 12
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));
        }
        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
        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");
        }
Exemplo n.º 15
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.º 16
0
        private static ISpatialReference CreateDefaultSpatialReference()
        {
            const string xml =
                @"<ProjectedCoordinateSystem xsi:type='typens:ProjectedCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/9.3'><WKT>PROJCS[&quot;CH1903+_LV95&quot;,GEOGCS[&quot;GCS_CH1903+&quot;,DATUM[&quot;D_CH1903+&quot;,SPHEROID[&quot;Bessel_1841&quot;,6377397.155,299.1528128]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433]],PROJECTION[&quot;Hotine_Oblique_Mercator_Azimuth_Center&quot;],PARAMETER[&quot;False_Easting&quot;,2600000.0],PARAMETER[&quot;False_Northing&quot;,1200000.0],PARAMETER[&quot;Scale_Factor&quot;,1.0],PARAMETER[&quot;Azimuth&quot;,90.0],PARAMETER[&quot;Longitude_Of_Center&quot;,7.439583333333333],PARAMETER[&quot;Latitude_Of_Center&quot;,46.95240555555556],UNIT[&quot;Meter&quot;,1.0],AUTHORITY[&quot;EPSG&quot;,2056]]</WKT><XOrigin>-27386400</XOrigin><YOrigin>-32067900</YOrigin><XYScale>800</XYScale><ZOrigin>-100000</ZOrigin><ZScale>800</ZScale><MOrigin>0</MOrigin><MScale>1</MScale><XYTolerance>0.0125</XYTolerance><ZTolerance>0.0125</ZTolerance><MTolerance>0.001</MTolerance><HighPrecision>true</HighPrecision><WKID>2056</WKID></ProjectedCoordinateSystem>";

            return(SpatialReferenceUtils.FromXmlString(xml));
        }
Exemplo n.º 17
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.º 18
0
        protected override int ExecuteCore(IRow row, int tableIndex)
        {
            var feature = row as IFeature;

            var multiPatch = feature?.Shape as IMultiPatch;

            if (multiPatch == null)
            {
                return(NoError);
            }

            if (_reducedResolutionSpatialReference == null && _resolutionFactor > 1)
            {
                _reducedResolutionSpatialReference =
                    SpatialReferenceUtils.CreateSpatialReferenceWithMinimumTolerance(
                        _spatialReference, _resolutionFactor);

                // for eliminating vertical walls, don't use the resolution factor,
                // but the original resolution with the minimum tolerance (2x) for it
                _minimumToleranceSpatialReference =
                    SpatialReferenceUtils.CreateSpatialReferenceWithMinimumTolerance(
                        _spatialReference);
            }

            return(CheckRings(multiPatch, feature));
        }
        public void CanCompareDomainOnlyDifferences()
        {
            Assert.IsTrue(SpatialReferenceUtils.AreEqual(
                              _lv95_xyres_001_zres_001,
                              _lv95_xyres_001_zres_001_largerdomains,
                              true, true, true,               // xy, z, m precisions
                              false, false));                 // tolerances, vcs

            Assert.IsTrue(SpatialReferenceUtils.AreEqual(
                              _lv95_xyres_001_zres_001,
                              _lv95_xyres_001_zres_001_largerdomains,
                              true, true, true,             // xy, z, m precisions
                              true, true));                 // tolerances, vcs

            Assert.IsTrue(SpatialReferenceUtils.AreEqual(
                              _lv95_xyres_001_zres_001_largerdomains,
                              _lv95_xyres_001_zres_001,
                              true, true, true,               // xy, z, m precisions
                              false, false));                 // tolerances, vcs

            Assert.IsTrue(SpatialReferenceUtils.AreEqual(
                              _lv95_xyres_001_zres_001_largerdomains,
                              _lv95_xyres_001_zres_001,
                              true, true, true,             // xy, z, m precisions
                              true, true));                 // tolerances, vcs
        }
Exemplo n.º 20
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.º 21
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.º 22
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
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PolylineGraphConnectivity"/> class.
        /// </summary>
        /// <param name="spatialReference"></param>
        /// <param name="areaOfInterest">An optional area of interest which is used to
        /// filter connectivities at points outside the AoI. This can be important if the
        /// node degree must be determined correctly (Example: two of three line features
        /// intersect the AoI and are connected -> the node is incorrectly determined to
        /// have degree 2 because the third line has never been added to the graph.</param>
        public PolylineGraphConnectivity(ISpatialReference spatialReference,
                                         [CanBeNull] IGeometry areaOfInterest = null)
        {
            SpatialReference = spatialReference;
            AreaOfInterest   = areaOfInterest;

            _queryPointFrom = new PointClass {
                SpatialReference = SpatialReference
            };
            _queryPointTo = new PointClass {
                SpatialReference = SpatialReference
            };

            if (spatialReference != null)
            {
                double xMax, yMax;
                spatialReference.GetDomain(out _originX, out xMax, out _originY, out yMax);

                _resolution = SpatialReferenceUtils.GetXyResolution(spatialReference);
            }

            NodeIndexesByNode = new Dictionary <Node, int>();

            EdgeReferences = new List <GdbObjectReference>();

            // Two lists with corresponding indexes: The nodes and the list of connections for each node:
            Nodes       = new List <Node>();
            Connections = new List <List <AdjacentNode> >();

            EdgeInteriorNodesByEdge = new Dictionary <GdbObjectReference, List <int> >();
        }
Exemplo n.º 24
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));
        }
Exemplo n.º 25
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.º 26
0
        private static ISpatialReference GetSpatialReferenceAtMaximumResolution(
            [NotNull] IEnumerable <IFeatureClass> featureClasses,
            out double maxResolution)
        {
            Assert.ArgumentNotNull(featureClasses, nameof(featureClasses));

            ISpatialReference result = null;

            maxResolution = 0;
            foreach (IFeatureClass featureClass in featureClasses)
            {
                var geoDataset = (IGeoDataset)featureClass;
                ISpatialReference spatialReference = geoDataset.SpatialReference;
                Assert.NotNull(spatialReference, "Dataset without spatial reference");

                if (result == null)
                {
                    result = Clone(spatialReference);
                }

                double xyResolution = SpatialReferenceUtils.GetXyResolution(spatialReference);

                maxResolution = Math.Max(xyResolution, maxResolution);
            }

            Assert.NotNull(result, "no spatial reference found");

            ((ISpatialReferenceTolerance)result).XYTolerance = maxResolution;

            return(result);
        }
Exemplo n.º 27
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.º 28
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.º 29
0
        private static ISpatialReference CreateSpatialReference()
        {
            ISpatialReference sref =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95, true);

            ((ISpatialReferenceResolution)sref).set_XYResolution(true, 0.01);
            return(sref);
        }
Exemplo n.º 30
0
 public WKSPointZComparer([NotNull] ISpatialReference spatialReference, bool compare3D)
     : this(SpatialReferenceUtils.GetXyResolution(spatialReference),
            compare3D
                                ? GeometryUtils.GetZResolution(spatialReference)
                                : double.NaN,
            spatialReference)
 {
 }