Exemplo n.º 1
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.º 2
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.º 3
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");
        }
        /// <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.º 5
0
 public WKSPointZComparer([NotNull] ISpatialReference spatialReference, bool compare3D)
     : this(SpatialReferenceUtils.GetXyResolution(spatialReference),
            compare3D
                                ? GeometryUtils.GetZResolution(spatialReference)
                                : double.NaN,
            spatialReference)
 {
 }
Exemplo n.º 6
0
        private static ISpatialReference GetBoxSpatialReference(
            [NotNull] ISpatialReference sref,
            double xMin, double yMin,
            double xMax, double yMax)
        {
            double domainXMin;
            double domainYMin;
            double domainXMax;
            double domainYMax;

            sref.GetDomain(out domainXMin, out domainXMax,
                           out domainYMin, out domainYMax);
            double xyResolution = SpatialReferenceUtils.GetXyResolution(sref);

            var    outOfBounds = false;
            double epsilon     = xyResolution * 10;

            if (xMin < domainXMin + epsilon)
            {
                domainXMin  = xMin - epsilon;
                outOfBounds = true;
            }

            if (yMin < domainYMin + epsilon)
            {
                domainYMin  = yMin - epsilon;
                outOfBounds = true;
            }

            if (xMax > domainXMax - epsilon)
            {
                domainXMax  = xMax + epsilon;
                outOfBounds = true;
            }

            if (yMax > domainYMax - epsilon)
            {
                domainYMax  = yMax + epsilon;
                outOfBounds = true;
            }

            if (!outOfBounds)
            {
                return(sref);
            }

            var copy = (ISpatialReference)((IClone)sref).Clone();

            // TODO round to resolution --> no odd grid origins
            copy.SetDomain(domainXMin, domainXMax, domainYMin, domainYMax);
            return(copy);
        }
Exemplo n.º 7
0
        public void CanCreateSpatialFilterWithSubResolutionEnvelope()
        {
            IFeatureWorkspace ws = OpenTestWorkspace();
            IFeatureClass     fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE");

            IEnvelope subResolutionEnv = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                        2600000.0001,
                                                                        1200000.0001);

            ISpatialReference spatialReference = DatasetUtils.GetSpatialReference(fc);

            subResolutionEnv.SpatialReference = spatialReference;

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

            IGeometry validGeometry;
            string    message;

            Assert.False(GdbQueryUtils.IsValidFilterGeometry(
                             subResolutionEnv, xyResolution, out validGeometry, out message),
                         "Sub-resolution polygon should not be valid");
            Assert.NotNull(validGeometry);
            Assert.False(subResolutionEnv == validGeometry,
                         "Corrected geometry must be different to input");

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

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

            IFeatureCursor cursor = fc.Search(filter, true);

            Marshal.ReleaseComObject(cursor);

            IEnvelope linearEnv = GeometryFactory.CreateEnvelope(2600000, 1200000,
                                                                 2600000.0001, 1201010);

            linearEnv.SpatialReference = ((IGeoDataset)fc).SpatialReference;

            filter = GdbQueryUtils.CreateSpatialFilter(
                fc, linearEnv, esriSpatialRelEnum.esriSpatialRelIntersects, true,
                null);

            cursor = fc.Search(filter, true);

            Marshal.ReleaseComObject(cursor);
        }
Exemplo n.º 8
0
        public Node(double x, double y, ISpatialReference spatialReference)
        {
            Assert.ArgumentNotNull(spatialReference, nameof(spatialReference));

            double originX, originY;
            double xMax, yMax;

            spatialReference.GetDomain(out originX, out xMax, out originY, out yMax);

            double scale = 1 / SpatialReferenceUtils.GetXyResolution(spatialReference);

            X = SnapCoordinate(x, originX, scale);
            Y = SnapCoordinate(y, originY, scale);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Determines if the provided vertex is the start or end of a closed path
        /// </summary>
        /// <param name="vertexIndex">The vertex</param>
        /// <param name="lowLevelGeometry">The path</param>
        /// <param name="spatialReference">The spatial reference. Cannot use the SR of the lowLevelGeometry
        /// because that is sometimes (when edited in stereo) null.</param>
        /// <returns></returns>
        private static bool IsClosedPathStartOrEnd(
            int vertexIndex,
            [NotNull] IGeometry lowLevelGeometry,
            [NotNull] ISpatialReference spatialReference)
        {
            Assert.ArgumentNotNull(lowLevelGeometry, nameof(lowLevelGeometry));
            Assert.ArgumentNotNull(spatialReference, nameof(spatialReference));

            int pointCount = ((IPointCollection)lowLevelGeometry).PointCount;

            if (pointCount <= 2)
            {
                // RemoveClosedPathNullPoint() cannot deal with degenerate parts
                return(false);
            }

            int lastIndex = pointCount - 1;

            var path = lowLevelGeometry as IPath;

            if (vertexIndex != 0 && vertexIndex != lastIndex)
            {
                return(false);
            }

            if (path != null && path.IsClosed)
            {
                // NOTE: path.IsClosed returns an incorrect value if the part / geometry is very small (below tolerance)
                double xyTolerance = ((ISpatialReferenceTolerance)spatialReference).XYTolerance;

                if (path.Length < xyTolerance)
                {
                    // TODO: test with non-z aware data, move to geometry utils
                    double xyResolution = SpatialReferenceUtils.GetXyResolution(spatialReference);
                    double zResolution  = GeometryUtils.GetZResolution(spatialReference);

                    WKSPointZ fromPoint = CreateWksPointZ(path.FromPoint);
                    WKSPointZ toPoint   = CreateWksPointZ(path.ToPoint);

                    return(GeometryUtils.IsSamePoint(fromPoint, toPoint, xyResolution, zResolution));
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public QaSimpleGeometry(
            [Doc(nameof(DocStrings.QaSimpleGeometry_featureClass))] IFeatureClass featureClass,
            [Doc(nameof(DocStrings.QaSimpleGeometry_allowNonPlanarLines))]
            bool allowNonPlanarLines,
            [Doc(nameof(DocStrings.QaSimpleGeometry_toleranceFactor))]
            double toleranceFactor)
            : base((ITable)featureClass)
        {
            Assert.ArgumentNotNull(featureClass, nameof(featureClass));
            Assert.ArgumentCondition(toleranceFactor >= _minimumToleranceFactor &&
                                     toleranceFactor <= _maximumToleranceFactor,
                                     "Invalid tolerance factor: {0}; value must be between {1} and {2}",
                                     toleranceFactor,
                                     _minimumToleranceFactor,
                                     _maximumToleranceFactor);

            _shapeType           = featureClass.ShapeType;
            _allowNonPlanarLines = allowNonPlanarLines;
            _spatialReference    = ((IGeoDataset)featureClass).SpatialReference;
            _shapeFieldName      = featureClass.ShapeFieldName;

            Assert.ArgumentCondition(_spatialReference != null,
                                     "feature class has no spatial reference");

            _xyResolution = SpatialReferenceUtils.GetXyResolution(_spatialReference);

            _zResolution = DatasetUtils.HasZ(featureClass)
                                               ? GeometryUtils.GetZResolution(_spatialReference)
                                               : double.NaN;

            _xyTolerance = ((ISpatialReferenceTolerance)_spatialReference).XYTolerance;

            if (toleranceFactor.Equals(_noChangeToleranceFactor))
            {
                _reducedToleranceSpatialReference = _spatialReference;
                _usesReducedSimplifyTolerance     = false;
            }
            else
            {
                _reducedToleranceSpatialReference = GetReducedToleranceSpatialReference(
                    _spatialReference, toleranceFactor);
                _usesReducedSimplifyTolerance = true;
            }
        }
        private static bool IsCoplanar([NotNull] SegmentsPlane segmentsPlane,
                                       [NotNull] IFeature planarFeature,
                                       double coplanarityTolerance,
                                       out double maximumOffset)
        {
            maximumOffset = GetMaximumOffset(segmentsPlane);
            if (maximumOffset <= coplanarityTolerance)
            {
                return(true);
            }

            var sref = Assert.NotNull(DatasetUtils.GetSpatialReference(planarFeature));

            var xyResolution = SpatialReferenceUtils.GetXyResolution(sref);
            var zResolution  = SpatialReferenceUtils.GetZResolution(sref);

            return(maximumOffset <= GeomUtils.AdjustCoplanarityTolerance(
                       segmentsPlane.Plane, coplanarityTolerance, zResolution,
                       xyResolution));
        }
Exemplo n.º 12
0
        private static bool IsPointEnvelope([NotNull] IEnvelope envelope,
                                            [NotNull] ISpatialReference spatialReference)
        {
            if (envelope.IsEmpty)
            {
                return(false);
            }

            double width  = envelope.Width;
            double height = envelope.Height;

            if (width < double.Epsilon &&
                height < double.Epsilon)
            {
                return(true);
            }

            double xyResolution = SpatialReferenceUtils.GetXyResolution(spatialReference);

            return(width < xyResolution &&
                   height < xyResolution);
        }
Exemplo n.º 13
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.");
        }
Exemplo n.º 14
0
        public static ISpatialReference GetUniqueSpatialReference(
            [NotNull] IEnumerable <ISpatialReference> spatialReferences,
            bool requireEqualVerticalCoordinateSystems)
        {
            Assert.ArgumentNotNull(spatialReferences, nameof(spatialReferences));

            IVerticalCoordinateSystem uniqueVcs  = null;
            ISpatialReference         uniqueSref = null;
            double bestResolution = double.MaxValue;

            foreach (ISpatialReference sref in spatialReferences)
            {
                if (uniqueSref == null)
                {
                    uniqueSref     = sref;
                    bestResolution = SpatialReferenceUtils.GetXyResolution(uniqueSref);
                }
                else
                {
                    if (requireEqualVerticalCoordinateSystems)
                    {
                        IVerticalCoordinateSystem vcs =
                            SpatialReferenceUtils.GetVerticalCoordinateSystem(sref);

                        if (vcs != null)
                        {
                            if (uniqueVcs == null)
                            {
                                uniqueVcs = vcs;
                            }
                            else
                            {
                                if (vcs != uniqueVcs &&
                                    !((IClone)uniqueVcs).IsEqual((IClone)vcs))
                                {
                                    throw new ArgumentException(
                                              string.Format(
                                                  "Defined vertical coordinate systems are not equal: {0}, {1}",
                                                  vcs.Name, uniqueVcs.Name));
                                }
                            }
                        }
                    }

                    if (uniqueSref != sref)
                    {
                        var compareSpatialReferences =
                            (ICompareCoordinateSystems)uniqueSref;

                        if (!compareSpatialReferences.IsEqualNoVCS(sref))
                        {
                            throw new ArgumentException(
                                      string.Format(
                                          "Coordinate systems are not equal: {0}, {1}",
                                          sref.Name, uniqueSref.Name));
                        }

                        // if the resolution is higher --> use as new unique
                        double resolution = SpatialReferenceUtils.GetXyResolution(sref);

                        if (resolution < bestResolution)
                        {
                            bestResolution = resolution;
                            uniqueSref     = sref;
                        }
                    }
                }
            }

            return(uniqueSref);
        }