Пример #1
0
        /// <summary>
        /// Ensures that a CoordinateSequence forms a valid ring,
        /// returning a new closed sequence of the correct length if required.
        /// If the input sequence is already a valid ring, it is returned
        /// without modification.
        /// If the input sequence is too short or is not closed,
        /// it is extended with one or more copies of the start point.
        /// </summary>
        /// <param name="fact">The CoordinateSequenceFactory to use to create the new sequence</param>
        /// <param name="seq">The sequence to test</param>
        /// <returns>The original sequence, if it was a valid ring, or a new sequence which is valid.</returns>
        public static CoordinateSequence EnsureValidRing(CoordinateSequenceFactory fact, CoordinateSequence seq)
        {
            int n = seq.Count;

            // empty sequence is valid
            if (n == 0)
            {
                return(seq);
            }
            // too short - make a new one
            if (n <= 3)
            {
                return(CreateClosedRing(fact, seq, 4));
            }

            bool isClosed = seq.GetOrdinate(0, 0) == seq.GetOrdinate(n - 1, 0) &&
                            seq.GetOrdinate(0, 1) == seq.GetOrdinate(n - 1, 1);

            if (isClosed)
            {
                return(seq);
            }
            // make a new closed ring
            return(CreateClosedRing(fact, seq, n + 1));
        }
Пример #2
0
        private static CoordinateSequence CreateClosedRing(CoordinateSequenceFactory fact, CoordinateSequence seq, int size)
        {
            var newseq = fact.Create(size, seq.Dimension);
            int n      = seq.Count;

            Copy(seq, 0, newseq, 0, n);
            // fill remaining coordinates with start point
            for (int i = n; i < size; i++)
            {
                Copy(seq, 0, newseq, i, 1);
            }
            return(newseq);
        }
Пример #3
0
        public static CoordinateSequence Extend(CoordinateSequenceFactory fact, CoordinateSequence seq, int size)
        {
            var newseq = fact.Create(size, seq.Ordinates);
            int n      = seq.Count;

            Copy(seq, 0, newseq, 0, n);
            // fill remaining coordinates with end point, if it exists
            if (n > 0)
            {
                for (int i = n; i < size; i++)
                {
                    Copy(seq, n - 1, newseq, i, 1);
                }
            }
            return(newseq);
        }
Пример #4
0
 /// <summary>
 /// Constructs a GeometryFactory that generates Geometries having the given
 /// CoordinateSequence implementation, a double-precision floating PrecisionModel and a
 /// spatial-reference ID of 0.
 /// </summary>
 public GeometryFactory(CoordinateSequenceFactory coordinateSequenceFactory) :
     this(new PrecisionModel(), 0, coordinateSequenceFactory)
 {
 }
Пример #5
0
 /// <summary>
 /// Constructs a GeometryFactory that generates Geometries having the given
 /// PrecisionModel, spatial-reference ID, and CoordinateSequence implementation.
 /// </summary>
 public GeometryFactory(PrecisionModel precisionModel, int srid, CoordinateSequenceFactory coordinateSequenceFactory)
 {
     _precisionModel            = precisionModel;
     _coordinateSequenceFactory = coordinateSequenceFactory;
     _srid = srid;
 }
 public OgcCompliantGeometryFactory(PrecisionModel pm, int srid, CoordinateSequenceFactory factory)
     : base(pm, srid, factory)
 {
 }
 /// <summary>
 /// Creates an instance of this class using the default
 /// values for <see cref="GeometryFactory.SRID"/>,
 /// <see cref="GeometryFactory.PrecisionModel"/>,
 /// but the specified <paramref name="factory"/>.
 /// </summary>
 public OgcCompliantGeometryFactory(CoordinateSequenceFactory factory)
     : base(factory)
 {
 }