private ICoordinateSequence ConvertOrdinateArray(double[] oordinates, SdoGeometry sdoGeom)
        {
            int dim = sdoGeom.Dimensionality;

            Coordinate[] coordinates = new Coordinate[oordinates.Length / dim];
            int          zDim        = 2; //sdoGeom.getZDimension() - 1;
            int          lrsDim      = sdoGeom.LRS - 1;

            for (int i = 0; i < coordinates.Length; i++)
            {
                if (dim == 2)
                {
                    coordinates[i] = new Coordinate(oordinates[i * dim], oordinates[i * dim + 1]);
                }
                else if (dim == 3)
                {
                    if (sdoGeom.LRS > 0)
                    {
                        coordinates[i] = MCoordinate.Create2dWithMeasure(
                            oordinates[i * dim],
                            // X
                            oordinates[i * dim + 1],
                            // Y
                            oordinates[i * dim + lrsDim]); // M
                    }
                    else
                    {
                        coordinates[i] = new Coordinate(
                            oordinates[i * dim],
                            // X
                            oordinates[i * dim + 1],
                            // Y
                            oordinates[i * dim + zDim]); // Z
                    }
                }
                else if (dim == 4)
                {
                    // This must be an LRS Geometry
                    if (sdoGeom.LRS == 0)
                    {
                        throw new ApplicationException("4 dimensional Geometries must be LRS geometry");
                    }
                    coordinates[i] = MCoordinate.Create3dWithMeasure(
                        oordinates[i * dim],
                        // X
                        oordinates[i * dim + 1],
                        // Y
                        oordinates[i * dim + zDim],
                        // Z
                        oordinates[i * dim + lrsDim]); // M
                }
            }
            return(factory.CoordinateSequenceFactory.Create(coordinates));
        }
Example #2
0
        private ICoordinate[] getCoordinates(Double[] oordinates, SdoGeometry sdoGeom)
        {
            int dimension = sdoGeom.Dimensionality;

            ICoordinate[] coordinates = new ICoordinate[oordinates.Length / dimension];

            int zDim   = sdoGeom.ZDimension - 1;
            int lrsDim = sdoGeom.LRSDimension - 1;

            for (int i = 0; i < coordinates.Length; i++)
            {
                if (dimension == 2)
                {
                    coordinates[i] = new Coordinate(
                        oordinates[i * dimension],
                        oordinates[i * dimension + 1]);
                }
                else if (dimension == 3)
                {
                    if (sdoGeom.IsLrsGeometry)
                    {
                        coordinates[i] = MCoordinate.Create2dWithMeasure(
                            oordinates[i * dimension],
                            oordinates[i * dimension + 1],
                            oordinates[i * dimension + lrsDim]);
                    }
                    else
                    {
                        coordinates[i] = new Coordinate(
                            oordinates[i * dimension],
                            oordinates[i * dimension + 1],
                            oordinates[i * dimension + zDim]);
                    }
                }
                else if (dimension == 4)
                {
                    // This must be an LRS Geometry
                    if (!sdoGeom.IsLrsGeometry)
                    {
                        throw new Exception(
                                  "4 dimensional Geometries must be LRS geometry");
                    }

                    coordinates[i] = MCoordinate.Create3dWithMeasure(
                        oordinates[i * dimension],
                        oordinates[i * dimension + 1],
                        oordinates[i * dimension + zDim],
                        oordinates[i * dimension + lrsDim]);
                }
            }
            return(coordinates);
        }
        /**
         * Linearizes arcs and circles.
         *
         * @param arcOrdinates
         *            arc or circle coordinates
         * @param dim
         *            coordinate dimension
         * @param lrs
         *            whether this is an lrs geometry
         * @param entireCirlce
         *            whether the whole arc should be linearized
         * @return linearized interpolation of arcs or circle
         */
        private Coordinate[] Linearize(double[] arcOrdinates, int dim, bool lrs, bool entireCirlce)
        {
            Coordinate[] linearizedCoords = new Coordinate[0];
            // CoordDim is the dimension that includes only non-measure (X,Y,Z)
            // ordinates in its value
            int coordDim = lrs ? dim - 1 : dim;

            // this only works with 2-Dimensional geometries, since we use
            // JGeometry linearization;
            if (coordDim != 2)
            {
                throw new ArgumentException("Can only linearize 2D arc segments, but geometry is " + dim + "D.");
            }
            int numOrd = dim;

            while (numOrd < arcOrdinates.Length)
            {
                numOrd = numOrd - dim;
                double x1 = arcOrdinates[numOrd++];
                double y1 = arcOrdinates[numOrd++];
                double m1 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x2 = arcOrdinates[numOrd++];
                double y2 = arcOrdinates[numOrd++];
                double m2 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x3 = arcOrdinates[numOrd++];
                double y3 = arcOrdinates[numOrd++];
                double m3 = lrs ? arcOrdinates[numOrd++] : Double.NaN;

                Coordinate[] coords;
                if (entireCirlce)
                {
                    coords = Circle.LinearizeCircle(x1, y1, x2, y2, x3, y3);
                }
                else
                {
                    coords = Circle.LinearizeArc(x1, y1, x2, y2, x3, y3);
                }

                // if this is an LRS geometry, fill the measure values into
                // the linearized array
                if (lrs)
                {
                    Coordinate[] mcoord    = new Coordinate[coords.Length];
                    int          lastIndex = coords.Length - 1;
                    mcoord[0]         = MCoordinate.Create2dWithMeasure(x1, y1, m1);
                    mcoord[lastIndex] = MCoordinate.Create2dWithMeasure(x3, y3, m3);
                    // convert the middle coordinates to MCoordinate
                    for (int i = 1; i < lastIndex; i++)
                    {
                        mcoord[i] = MCoordinate.ConvertCoordinate(coords[i]);
                        // if we happen to split on the middle measure, then
                        // assign it
                        if (mcoord[i].X == x2 && mcoord[i].Y == y2)
                        {
                            ((MCoordinate)mcoord[i]).M = m2;
                        }
                    }
                    coords = mcoord;
                }

                // if this is not the first arcsegment, the first linearized
                // point is already in linearizedArc, so disregard this.
                int resultBegin = 1;
                if (linearizedCoords.Length == 0)
                {
                    resultBegin = 0;
                }

                int          destPos   = linearizedCoords.Length;
                Coordinate[] tmpCoords = new Coordinate[linearizedCoords.Length + coords.Length - resultBegin];
                Array.Copy(linearizedCoords, 0, tmpCoords, 0, linearizedCoords.Length);
                Array.Copy(coords, resultBegin, tmpCoords, destPos, coords.Length - resultBegin);

                linearizedCoords = tmpCoords;
            }
            return(linearizedCoords);
        }