Esempio n. 1
0
        public MLineString UnionM(MLineString l)
        {
            if (!this.monotone || !l.monotone)
            {
                throw new ApplicationException("MGeometryException.OPERATION_REQUIRES_MONOTONE");
            }
            ICoordinate[] linecoar = l.Coordinates;
            if (l.GetMeasureDirection() == MGeometryType.Decreasing)
            {
                CoordinateArrays.Reverse(linecoar);
            }
            ICoordinate[] thiscoar = this.Coordinates;
            if (this.GetMeasureDirection() == MGeometryType.Decreasing)
            {
                CoordinateArrays.Reverse(thiscoar);
            }

            // either the last coordinate in thiscoar Equals the first in linecoar;
            // or the last in linecoar Equals the first in thiscoar;
            MCoordinate lasttco  = (MCoordinate)thiscoar[thiscoar.Length - 1];
            MCoordinate firsttco = (MCoordinate)thiscoar[0];
            MCoordinate lastlco  = (MCoordinate)linecoar[linecoar.Length - 1];
            MCoordinate firstlco = (MCoordinate)linecoar[0];

            MCoordinate[] newcoar = new MCoordinate[thiscoar.Length
                                                    + linecoar.Length - 1];
            if (lasttco.Equals2D(firstlco) &&
                DoubleComparator.Equals(lasttco.M, firstlco.M))
            {
                Array.Copy(thiscoar, 0, newcoar, 0, thiscoar.Length);
                Array.Copy(linecoar, 1, newcoar, thiscoar.Length,
                           linecoar.Length - 1);
            }
            else if (lastlco.Equals2D(firsttco) &&
                     DoubleComparator.Equals(lastlco.M, firsttco.M))
            {
                Array.Copy(linecoar, 0, newcoar, 0, linecoar.Length);
                Array.Copy(thiscoar, 1, newcoar, linecoar.Length,
                           thiscoar.Length - 1);
            }
            else
            {
                throw new ApplicationException("MGeometryException.UNIONM_ON_DISJOINT_MLINESTRINGS");
            }

            ICoordinateSequence mcs = this.Factory.CoordinateSequenceFactory.Create(newcoar);
            MLineString         returnmlinestring = new MLineString(mcs, this.Factory);

            Debug.Assert(returnmlinestring.IsMonotone(false), "new UnionM-ed MLineString is not monotone");
            return(returnmlinestring);
        }
Esempio n. 2
0
        /**
         * TODO Improve this, and add more unit tests
         */
        private void DetermineMonotone()
        {
            this.monotone       = true;
            this.strictMonotone = true;
            if (this.IsEmpty)
            {
                return;
            }
            MGeometryType mdir = ((MLineString)this.geometries[0]).GetMeasureDirection();

            for (int i = 0; i < this.geometries.Length; i++)
            {
                MLineString ml = (MLineString)this.geometries[i];
                // check whether mlinestrings are all pointing in same direction,
                // and
                // are monotone
                if (!ml.IsMonotone(false) ||
                    (ml.GetMeasureDirection() != mdir && !(ml
                                                           .GetMeasureDirection() == MGeometryType.Constant)))
                {
                    this.monotone = false;
                    break;
                }

                if (!ml.IsMonotone(true) || (ml.GetMeasureDirection() != mdir))
                {
                    this.strictMonotone = false;
                    break;
                }

                // check whether the geometry measures do not overlap or
                // are inconsistent with previous parts
                if (i > 0)
                {
                    MLineString mlp = (MLineString)this.geometries[i - 1];
                    if (mdir == MGeometryType.Increasing)
                    {
                        if (mlp.GetMaxM() > ml.GetMinM())
                        {
                            monotone = false;
                        }
                        else if (mlp.GetMaxM() >= ml.GetMinM())
                        {
                            strictMonotone = false;
                        }
                    }
                    else
                    {
                        if (mlp.GetMinM() < ml.GetMaxM())
                        {
                            monotone = false;
                        }
                        else if (mlp.GetMinM() <= ml.GetMaxM())
                        {
                            strictMonotone = false;
                        }
                    }
                }
            }
            if (!monotone)
            {
                this.strictMonotone = false;
            }
        }
Esempio n. 3
0
		public MLineString UnionM(MLineString l)
		{

			if (!this.monotone || !l.monotone)
			{
				throw new ApplicationException("MGeometryException.OPERATION_REQUIRES_MONOTONE");
			}
			ICoordinate[] linecoar = l.Coordinates;
			if (l.GetMeasureDirection() == MGeometryType.Decreasing)
			{
				CoordinateArrays.Reverse(linecoar);
			}
			ICoordinate[] thiscoar = this.Coordinates;
			if (this.GetMeasureDirection() == MGeometryType.Decreasing)
			{
				CoordinateArrays.Reverse(thiscoar);
			}

			// either the last coordinate in thiscoar Equals the first in linecoar;
			// or the last in linecoar Equals the first in thiscoar;
			MCoordinate lasttco = (MCoordinate)thiscoar[thiscoar.Length - 1];
			MCoordinate firsttco = (MCoordinate)thiscoar[0];
			MCoordinate lastlco = (MCoordinate)linecoar[linecoar.Length - 1];
			MCoordinate firstlco = (MCoordinate)linecoar[0];

			MCoordinate[] newcoar = new MCoordinate[thiscoar.Length
					+ linecoar.Length - 1];
			if (lasttco.Equals2D(firstlco)
					&& DoubleComparator.Equals(lasttco.M, firstlco.M))
			{
				Array.Copy(thiscoar, 0, newcoar, 0, thiscoar.Length);
				Array.Copy(linecoar, 1, newcoar, thiscoar.Length,
						linecoar.Length - 1);
			}
			else if (lastlco.Equals2D(firsttco)
					&& DoubleComparator.Equals(lastlco.M, firsttco.M))
			{
				Array.Copy(linecoar, 0, newcoar, 0, linecoar.Length);
				Array.Copy(thiscoar, 1, newcoar, linecoar.Length,
						thiscoar.Length - 1);
			}
			else
			{
				throw new ApplicationException("MGeometryException.UNIONM_ON_DISJOINT_MLINESTRINGS");
			}

			ICoordinateSequence mcs = this.Factory.CoordinateSequenceFactory.Create(newcoar);
			MLineString returnmlinestring = new MLineString(mcs, this.Factory);
			Debug.Assert(returnmlinestring.IsMonotone(false), "new UnionM-ed MLineString is not monotone");
			return returnmlinestring;
		}