private LineString CreateLine(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int
                     sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            if (etype != SdoEType.Line)
            {
                return(null);
            }

            if (interpretation != 1)
            {
                throw new ArgumentException("ELEM_INFO INTERPRETAION " +
                                            interpretation + " not supported" +
                                            "by JTS LineString.  Straight edges" +
                                            "( ELEM_INFO INTERPRETAION 1) is supported");
            }

            int
                len     = (dim + lrs);
            int start   = (sOffset - 1) / len;
            int eOffset = StartingOffset(elemInfo, elemIndex + 1); // -1 for end
            int end     = (eOffset != -1) ? ((eOffset - 1) / len) : coords.Count;


            var line = _factory.CreateLineString(ToPointArray(SubList(coords, start, end)));

            return(line);
        }
        private MultiPoint CreateMultiPoint(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            if (!(sOffset >= 1) || !(sOffset <= coords.Count))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }
            if (etype != SdoEType.Coordinate)
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POINT");
            }
            if (!(interpretation > 1))
            {
                return(null);
            }

            int len = dim + lrs;

            int start = (sOffset - 1) / len;
            int end   = start + interpretation;

            var points = _factory.CreateMultiPointFromCoords(SubArray(coords, start, end));

            return(points);
        }
        private LinearRing CreateLinearRing(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int
                     sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);
            int      length         = coords.Count * dim;

            if (!(sOffset <= length))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }
            if (etype != SdoEType.Polygon && etype != SdoEType.PolygonExterior &&
                etype != SdoEType.PolygonInterior)
            {
                throw new ArgumentException("ETYPE " + etype +
                                            " inconsistent with expected POLYGON, POLYGON_EXTERIOR or POLYGON_INTERIOR");
            }
            if (interpretation != 1 && interpretation != 3)
            {
                return(null);
            }
            LinearRing ring;

            int len     = (dim + lrs);
            int start   = (sOffset - 1) / len;
            int eOffset = StartingOffset(elemInfo, elemIndex + 1); // -1 for end
            int end     = (eOffset != -1) ? ((eOffset - 1) / len) : coords.Count;

            if (interpretation == 1)
            {
                ring = new LinearRing(ToPointArray(SubList(coords, start, end)));
            }
            else
            {
                // interpretation == 3
                // rectangle does not maintain measures
                List <Coordinate> pts    = new List <Coordinate>(5);
                List <Coordinate> ptssrc = SubList(coords, start, end);
                Coordinate        min    = ptssrc[0];
                Coordinate        max    = ptssrc[1];
                pts.AddRange(new[]
                {
                    min, new Coordinate(max.X, min.Y), max, new Coordinate(min.X, max.Y), min
                });

                ring = _factory.CreateLinearRing(pts.ToArray());
            }

            return(ring);
        }
        private MultiPolygon CreateMultiPolygon(int dim, int lrs, decimal[] elemInfo, int elemIndex,
                                                List <Coordinate> coords, int numGeom)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            int length = coords.Count * dim;

            if (!(sOffset >= 1) || !(sOffset <= length))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }

            if (etype != SdoEType.Polygon && etype != SdoEType.PolygonExterior)
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POLYGON or POLYGON_EXTERIOR");
            }

            if (interpretation != 1 && interpretation != 3)
            {
                return(null);
            }

            int endTriplet = (numGeom != -1) ? elemIndex + numGeom : (elemInfo.Length / 3) + 1;

            var     list = new List <Polygon>();
            Boolean cont = true;

            for (int i = elemIndex; cont && i < endTriplet && (etype = EType(elemInfo, i)) != SdoEType.Unknown; i++)
            {
                if ((etype == SdoEType.Polygon) || (etype == SdoEType.PolygonExterior))
                {
                    var poly = CreatePolygon(dim, lrs, elemInfo, i, coords);
                    i += poly.NumInteriorRings; // skip interior rings
                    list.Add(poly);
                }
                else
                {
                    // not a Polygon - get out here
                    cont = false;
                }
            }

            var polys = _factory.CreateMultiPolygon(list.ToArray());

            return(polys);
        }
        private MultiLineString CreateMultiLine(int dim, int lrs, Decimal[] elemInfo, int elemIndex,
                                                List <Coordinate> coords, int numGeom)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            int length = coords.Count * dim;

            if (!(sOffset >= 1) || !(sOffset <= length))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }
            if (!(etype == SdoEType.Line))
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected LINE");
            }
            if (!(interpretation == 1))
            {
                // we cannot represent INTERPRETATION > 1
                return(null);
            }

            int endTriplet = (numGeom != -1) ? (elemIndex + numGeom) : (elemInfo.Length / 3);

            var list = new List <LineString>();

            Boolean cont = true;

            for (int i = elemIndex; cont && i < endTriplet && (etype = EType(elemInfo, i)) != SdoEType.Unknown; i++)
            {
                if (etype == SdoEType.Line)
                {
                    list.Add(CreateLine(dim, lrs, elemInfo, i, coords));
                }
                else
                {
                    // not a LineString - get out of here
                    cont = false;
                }
            }

            var lines = _factory.CreateMultiLineString(list.ToArray());

            return(lines);
        }
Ejemplo n.º 6
0
        /**
         * Allows specification of <code>INTERPRETATION</code> used to interpret
         * <code>geom</code>.
         *
         * @param geom Geometry to encode
         * @param etype ETYPE value requiring an INTERPREATION
         *
         * @return INTERPRETATION ELEM_INFO entry for geom given etype
         *
         * @throws IllegalArgumentException If asked to encode a curve
         */
        private int ElemInfoInterpretation(IGeometry geom, SdoEType etype)
        {
            switch (etype)
            {
            case SdoEType.Coordinate:

                if (geom is IPoint)
                {
                    return(1);
                }

                if (geom is IMultiPoint)
                {
                    return(geom.NumGeometries);
                }

                break;

            case SdoEType.Line:
                // always straight for jts
                return(1);

            case SdoEType.Polygon:
            case SdoEType.PolygonExterior:
            case SdoEType.PolygonInterior:

                if (geom is IPolygon)
                {
                    var polygon = (IPolygon)geom;
                    // always straight for jts
                    if (IsRectangle(polygon))
                    {
                        return(3);
                    }
                }

                return(1);
            }

            throw new ArgumentException("Cannot encode JTS "
                                        + geom.GeometryType + " as "
                                        + "SDO_INTERPRETATION (Limitied to Point, Line, Polygon, "
                                        + "GeometryCollection, MultiPoint, MultiLineString and MultiPolygon)");
        }
        private Point CreatePoint(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            if (!(sOffset >= 1) || !(sOffset <= coords.Count))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }
            if (etype != SdoEType.Coordinate)
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POINT");
            }
            if (interpretation != 1)
            {
                return(null);
            }

            int len     = (dim + lrs);
            int start   = (sOffset - 1) / len;
            int eOffset = StartingOffset(elemInfo, elemIndex + 1); // -1 for end

            Coordinate point;

            if ((sOffset == 1) && (eOffset == -1))
            {
                // Use all Coordinates
                point = coords[0];
            }
            else
            {
                int end = (eOffset != -1) ? ((eOffset - 1) / len) : coords.Count;
                point = SubList(coords, start, end)[0];
            }

            return(_factory.CreatePoint(point));
        }
    /**
     * Allows specification of <code>INTERPRETATION</code> used to interpret
     * <code>geom</code>.
     * 
     * @param geom Geometry to encode
     * @param etype ETYPE value requiring an INTERPREATION
     *
     * @return INTERPRETATION ELEM_INFO entry for geom given etype
     *
     * @throws IllegalArgumentException If asked to encode a curve
     */
    private int ElemInfoInterpretation(IGeometry geom, SdoEType etype) {
        switch (etype) {

        case SdoEType.Coordinate:

            if (geom is IPoint) {
                return 1;
            }

            if (geom is IMultiPoint) {
                return geom.NumGeometries;
            }

            break;

        case SdoEType.Line:
        	// always straight for jts
            return 1;

        case SdoEType.Polygon:
        case SdoEType.PolygonExterior:
        case SdoEType.PolygonInterior:

            if (geom is IPolygon) {
                var polygon = (IPolygon) geom;
            	// always straight for jts
                if (IsRectangle(polygon)) {
                    return 3;
                }
            }

            return 1;
        }

        throw new ArgumentException("Cannot encode JTS "
            + geom.GeometryType + " as "
            + "SDO_INTERPRETATION (Limitied to Point, Line, Polygon, "
            + "GeometryCollection, MultiPoint, MultiLineString and MultiPolygon)");
    }
        private Polygon CreatePolygon(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            if (!(1 <= sOffset && sOffset <= (coords.Count * dim)))
            {
                throw new ArgumentException(
                          "ELEM_INFO STARTING_OFFSET " + sOffset +
                          "inconsistent with COORDINATES length " + (coords.Count * dim));
            }

            if (etype != SdoEType.Polygon && etype != SdoEType.PolygonExterior)
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POLYGON or POLYGON_EXTERIOR");
            }
            if (interpretation != 1 && interpretation != 3)
            {
                return(null);
            }

            var exteriorRing = CreateLinearRing(dim, lrs, elemInfo, elemIndex, coords);

            var rings = new List <LinearRing>();

            Boolean cont = true;

            for (int i = elemIndex + 1; cont && (etype = EType(elemInfo, i)) != SdoEType.Unknown; i++)
            {
                if (etype == SdoEType.PolygonInterior)
                {
                    rings.Add(CreateLinearRing(dim, lrs, elemInfo, i, coords));
                }
                else if (etype == SdoEType.Polygon)
                {
                    // need to test Clockwiseness of Ring to see if it is
                    // interior or not - (use POLYGON_INTERIOR to avoid pain)

                    var ring = CreateLinearRing(dim, lrs, elemInfo, i, coords);

                    if (Algorithm.Orientation.IsCCW(ring.CoordinateSequence))
                    {
                        // it is an Interior Hole
                        rings.Add(ring);
                    }
                    else
                    {
                        // it is the next Polygon! - get out of here
                        cont = false;
                    }
                }
                else
                {
                    // not a LinearRing - get out of here
                    cont = false;
                }
            }

            var poly = _factory.CreatePolygon(exteriorRing, rings.ToArray());

            return(poly);
        }