private ILineString ReadLine(SdoGeometry sdoGeom)
        {
            if (sdoGeom.OrdinatesArray.Length == 0)
            {
                return(LineString.Empty);
            }
            int[] elements         = sdoGeom.ElemArrayOfInts;
            ICoordinateSequence cs = null;

            int i = 0;

            while (i < elements.Length / ElementTupleSize)
            {
                if (GetElementType(elements, i) == (int)SdoGeometryTypes.ETYPE_COMPOUND.FOURDIGIT)
                {
                    throw new NotImplementedException("NhibernateSpatial does not support compound Lines");
                }
                else
                {
                    cs = AppendCoordinateSequence(cs, GetElementCoordinateSequence(i, sdoGeom, false));
                    i++;
                }
            }
            ILineString ls = _factory.CreateLineString(cs);

            ls.SRID = (int)sdoGeom.Sdo_Srid;
            return(ls);
        }
        private SdoGeometry WriteMultiLineString(IGeometry geometry)
        {
            int         dim         = GetCoordDimension(geometry);
            int         lrsDim      = GetCoordinateLrsPosition(geometry);
            bool        isLrs       = (lrsDim != 0);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.Sdo_Gtype      = (double)SDO_GTYPE.MULTILINE;
            sdoGeometry.Dimensionality = dim;
            sdoGeometry.LRS            = lrsDim;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            double[] info             = new double[geometry.NumGeometries * 3];
            int      oordinatesOffset = 1;

            double?[] ordinates = new double?[] { };
            for (int i = 0; i < geometry.NumGeometries; i++)
            {
                info[i + 0]      = oordinatesOffset;
                info[i + 1]      = (double)ElementType.LINE_STRAITH_SEGMENTS;
                info[i + 2]      = 0;
                ordinates        = ConvertAddCoordinates(ordinates, geometry.GetGeometryN(i).Coordinates, dim, isLrs);
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArray = info;
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            return(sdoGeometry);
        }
Пример #3
0
        private ILineString ReadLine(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            bool lrs = sdoGeom.LRS > 0;

            decimal[]           info = sdoGeom.ElemArray;
            ICoordinateSequence cs   = null;

            int i = 0;

            while (i < info.Length)
            {
                if (info.getElementType(i).isCompound())
                {
                    int numCompounds = info.getNumCompounds(i);
                    cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                    i += 1 + numCompounds;
                }
                else
                {
                    cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                    i++;
                }
            }

            LineString ls =
                lrs
                                        ? factory.createMLineString(cs)
                                        : factory.CreateLineString(cs);

            ls.SRID = (int)sdoGeom.Sdo_Srid;
            return(ls);
        }
Пример #4
0
        private SdoGeometry WriteMultiPolygon(IGeometry geometry)
        {
            int         dimension   = GetGeometryDimension(geometry);
            int         lrsPos      = GetCoordinateLrsPosition(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.GeometryType   = (int)SdoGeometryTypes.GTYPE.MULTIPOLYGON;
            sdoGeometry.Dimensionality = dimension;
            sdoGeometry.LRS            = lrsPos;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            for (int i = 0; i < geometry.NumGeometries; i++)
            {
                try
                {
                    IPolygon pg = (IPolygon)geometry.GetGeometryN(i);
                    AddPolygon(sdoGeometry, pg, dimension, lrsPos);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(
                              "Found geometry that was not a Polygon in MultiPolygon", e);
                }
            }
            sdoGeometry.PropertiesToGTYPE();
            return(sdoGeometry);
        }
        private SdoGeometry WriteMultiPolygon(IGeometry geometry)
        {
            int         dim         = GetCoordDimension(geometry);
            int         lrsPos      = GetCoordinateLrsPosition(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.Sdo_Gtype      = (double)SDO_GTYPE.MULTIPOLYGON;
            sdoGeometry.Dimensionality = dim;
            sdoGeometry.LRS            = lrsPos;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            for (int i = 0; i < geometry.NumGeometries; i++)
            {
                try
                {
                    IPolygon pg = (IPolygon)geometry.GetGeometryN(i);
                    AddPolygon(sdoGeometry, pg);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(
                              "Found geometry that was not a geometry in MultiPolygon");
                }
            }
            return(sdoGeometry);
        }
        private IMultiLineString ReadMultiLine(SdoGeometry sdoGeom)
        {
            int[]         elements = sdoGeom.ElemArrayOfInts;
            ILineString[] lines    = new ILineString[sdoGeom.ElemArray.Length / ElementTupleSize];
            int           i        = 0;

            while (i < elements.Length / ElementTupleSize)
            {
                ICoordinateSequence cs = null;
                if (GetElementType(elements, i) == (int)SdoGeometryTypes.ETYPE_COMPOUND.FOURDIGIT)
                {
                    int numCompounds = GetNumCompounds(elements, i);
                    cs = AppendCoordinateSequence(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                    ILineString line = _factory.CreateLineString(cs);
                    lines[i] = line;
                    i       += 1 + numCompounds;
                }
                else
                {
                    cs = AppendCoordinateSequence(cs, GetElementCoordinateSequence(i, sdoGeom, false));
                    ILineString line = _factory.CreateLineString(cs);
                    lines[i] = line;
                    i++;
                }
            }

            IMultiLineString mls = _factory.CreateMultiLineString(lines);

            mls.SRID = (int)sdoGeom.Sdo_Srid;
            return(mls);
        }
        /// <summary>
        /// Get coordinate sequence of an element
        /// </summary>
        /// <param name="i"></param>
        /// <param name="sdoGeom"></param>
        /// <param name="hasNextSE"></param>
        /// <returns></returns>
        private ICoordinateSequence GetElementCoordinateSequence(int i, SdoGeometry sdoGeom, bool hasNextSE)
        {
            int type           = sdoGeom.ElemArrayOfInts[i * ElementTupleSize + 1];
            int interpretation = sdoGeom.ElemArrayOfInts[i * ElementTupleSize + 2];

            Double[] elemOrdinates = ExtractOrdinatesOfElement(i, sdoGeom, hasNextSE);

            ICoordinateSequence cs;

            if (interpretation == 1)
            {
                cs = ConvertOrdinateArray(elemOrdinates, sdoGeom.Dimensionality);
            }
            else if (interpretation == 2 || interpretation == 4)
            {
                throw new NotImplementedException("Arc segment elements are not supported");
            }
            else if (interpretation == 3)
            {
                throw new NotImplementedException("Rectancle elements are not supported, use polygon to define the rectangle");
            }
            else
            {
                throw new ApplicationException(String.Format("Unsupportes element interpretation {0} in compound type{1}", interpretation, type));
            }
            return(cs);
        }
        private SdoGeometry WriteMultiPoint(IGeometry geometry)
        {
            int         dim         = GetCoordDimension(geometry);
            int         lrsDim      = GetCoordinateLrsPosition(geometry);
            bool        isLrs       = (lrsDim != 0);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.Sdo_Gtype      = (double)SDO_GTYPE.MULTIPOINT;
            sdoGeometry.Dimensionality = dim;
            sdoGeometry.LRS            = lrsDim;
            sdoGeometry.Sdo_Srid       = geometry.SRID;

            double[] info             = new double[geometry.NumPoints * 3];
            int      oordinatesOffset = 1;

            double?[] ordinates = new double?[0];
            for (int i = 0; i < geometry.NumPoints; i++)
            {
                //info.setElement(i, oordinatesOffset, ElementType.POINT, 0);
                info[i + 0]      = oordinatesOffset;
                info[i + 1]      = (double)ElementType.POINT;
                info[i + 2]      = 0;
                ordinates        = ConvertAddCoordinates(ordinates, geometry.GetGeometryN(i).Coordinates, dim, isLrs);
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArray = info;
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            return(sdoGeometry);
        }
        private SdoGeometry WriteMultiPoint(IGeometry geometry)
        {
            var dim         = this.GetCoordDimension(geometry);
            var lrsDim      = this.GetCoordinateLrsPosition(geometry);
            var isLrs       = (lrsDim != 0);
            var sdoGeometry = new SdoGeometry
            {
                GeometryType   = SDO_GTYPE.MULTIPOINT,
                Dimensionality = dim,
                LRS            = lrsDim,
                Sdo_Srid       = geometry.SRID
            };

            var info             = new decimal[geometry.NumPoints * 3];
            var oordinatesOffset = 1;
            var ordinates        = new decimal[0];
            var elementType      = ElementType.POINT;

            for (int i = 0; i < geometry.NumPoints; i++)
            {
                //info.setElement(i, oordinatesOffset, ElementType.POINT, 0);
                info[i + 0]      = oordinatesOffset;
                info[i + 1]      = elementType.EType();
                info[i + 2]      = elementType.Interpretation();
                ordinates        = this.ConvertAddCoordinates(ordinates, geometry.GetGeometryN(i).Coordinates, dim, isLrs);
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArray      = info;
            sdoGeometry.OrdinatesArray = ordinates;
            return(sdoGeometry);
        }
        private SdoGeometry WriteMultiLineString(IGeometry geometry)
        {
            var dim         = this.GetCoordDimension(geometry);
            var lrsDim      = this.GetCoordinateLrsPosition(geometry);
            var isLrs       = (lrsDim != 0);
            var sdoGeometry = new SdoGeometry
            {
                GeometryType   = SDO_GTYPE.MULTILINE,
                Dimensionality = dim,
                LRS            = lrsDim,
                Sdo_Srid       = geometry.SRID
            };
            var info             = new decimal[geometry.NumGeometries * 3];
            var oordinatesOffset = 1;
            var ordinates        = new decimal[] { };
            var elementType      = ElementType.LINE_STRAITH_SEGMENTS;

            for (var i = 0; i < geometry.NumGeometries; i++)
            {
                info[i + 0]      = oordinatesOffset;
                info[i + 1]      = elementType.EType();
                info[i + 2]      = elementType.Interpretation();
                ordinates        = this.ConvertAddCoordinates(ordinates, geometry.GetGeometryN(i).Coordinates, dim, isLrs);
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArray      = info;
            sdoGeometry.OrdinatesArray = ordinates;
            return(sdoGeometry);
        }
        private SdoGeometry WriteMultiPolygon(IGeometry geometry)
        {
            var dim         = this.GetCoordDimension(geometry);
            var lrsPos      = this.GetCoordinateLrsPosition(geometry);
            var sdoGeometry = new SdoGeometry
            {
                GeometryType   = SDO_GTYPE.MULTIPOLYGON,
                Dimensionality = dim,
                LRS            = lrsPos,
                Sdo_Srid       = geometry.SRID
            };

            for (int i = 0; i < geometry.NumGeometries; i++)
            {
                try
                {
                    var pg = (IPolygon)geometry.GetGeometryN(i);
                    this.AddPolygon(sdoGeometry, pg);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(
                              "Found geometry that was not a geometry in MultiPolygon", e);
                }
            }
            return(sdoGeometry);
        }
Пример #12
0
        private SdoGeometry WriteMultiLineString(IGeometry geometry)
        {
            int         dimension   = GetGeometryDimension(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.GeometryType   = (int)SdoGeometryTypes.GTYPE.MULTILINE;
            sdoGeometry.Dimensionality = dimension;
            sdoGeometry.LRS            = 0;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            int[] elements         = new int[geometry.NumGeometries * ElementTupleSize];
            int   oordinatesOffset = 1;

            double[] ordinates = new double[] { };
            for (int i = 0; i < geometry.NumGeometries; i++)
            {
                elements[i * ElementTupleSize + 0] = oordinatesOffset;
                elements[i * ElementTupleSize + 1] = (int)SdoGeometryTypes.ETYPE_SIMPLE.LINE;
                elements[i * ElementTupleSize + 2] = 1;
                ordinates        = AppendCoordinates(ordinates, ConvertCoordinates(geometry.GetGeometryN(i).Coordinates, dimension));
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArrayOfInts         = elements;
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            sdoGeometry.PropertiesToGTYPE();
            return(sdoGeometry);
        }
Пример #13
0
        private SdoGeometry WriteMultiPoint(IGeometry geometry)
        {
            int         dimension   = GetGeometryDimension(geometry);
            int         lrsPos      = GetCoordinateLrsPosition(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.GeometryType   = (int)SdoGeometryTypes.GTYPE.MULTIPOINT;
            sdoGeometry.Dimensionality = dimension;
            sdoGeometry.LRS            = lrsPos;
            sdoGeometry.Sdo_Srid       = geometry.SRID;

            int[] elements         = new int[geometry.NumPoints * ElementTupleSize];
            int   oordinatesOffset = 1;

            double[] ordinates = new double[0];
            for (int i = 0; i < geometry.NumPoints; i++)
            {
                elements[i * ElementTupleSize + 0] = oordinatesOffset;
                elements[i * ElementTupleSize + 1] = (int)SdoGeometryTypes.ETYPE_SIMPLE.POINT;
                elements[i * ElementTupleSize + 2] = 0;
                ordinates        = AppendCoordinates(ordinates, ConvertCoordinates(geometry.GetGeometryN(i).Coordinates, dimension, HasLRS(lrsPos)));
                oordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.ElemArrayOfInts         = elements;
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            sdoGeometry.PropertiesToGTYPE();
            return(sdoGeometry);
        }
        private ILineString ReadLine(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            bool lrs  = sdoGeom.LRS > 0;
            var  info = sdoGeom.ElemArray;
            ICoordinateSequence cs = null;

            int i = 0;

            while (i < info.Length)
            {
                // NOTE: No compounds yet.
                //if (info.getElementType(i).isCompound())
                //{
                //    int numCompounds = info.getNumCompounds(i);
                //    cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                //    i += 1 + numCompounds;
                //}
                //else
                //{
                cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                i++;
                //}
            }

            //ILineString ls =
            //    lrs
            //        ? (LineString)factory.CreateMultiLineString(cs)
            //        : factory.CreateLineString(cs);
            ILineString ls = factory.CreateLineString(cs);

            ls.SRID = (int)sdoGeom.Sdo_Srid;
            return(ls);
        }
        private IMultiPoint ReadMultiPoint(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            Double[]            ordinates  = sdoGeom.OrdinatesArray.Select(d => Convert.ToDouble(d)).ToArray();
            ICoordinateSequence cs         = ConvertOrdinateArray(ordinates, sdoGeom);
            IMultiPoint         multipoint = factory.CreateMultiPoint(cs);

            multipoint.SRID = (int)sdoGeom.Sdo_Srid;
            return(multipoint);
        }
Пример #16
0
        private IGeometry ReadGeometryCollection(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            List <IGeometry> geometries = new List <IGeometry>();

            foreach (SdoGeometry elemGeom in sdoGeom.getElementGeometries())
            {
                geometries.Add(ReadGeometry(elemGeom));
            }
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
 private IGeometry ReadGeometryCollection(SdoGeometry sdoGeom)
 {
     return(GeometryCollection.Empty);
     //List<IGeometry> geometries = new List<IGeometry>();
     //foreach (SdoGeometry elemGeom in sdoGeom.getElementGeometries())
     //{
     //    geometries.AppendCoordinateSequence(ReadGeometry(elemGeom));
     //}
     //return factory.CreateGeometryCollection(geometries.ToArray());
 }
 private SdoGeometry WriteGeometryCollection(IGeometry geometry)
 {
     SdoGeometry[] sdoElements = new SdoGeometry[geometry.NumGeometries];
     for (int i = 0; i < geometry.NumGeometries; i++)
     {
         IGeometry sdoGeometry = geometry.GetGeometryN(i);
         sdoElements[i] = WriteGeometry(sdoGeometry);
     }
     return(SdoGeometry.Join(sdoElements));
 }
Пример #19
0
        private IMultiPolygon ReadMultiPolygon(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            List <ILinearRing> holes    = new List <ILinearRing>();
            List <IPolygon>    polygons = new List <IPolygon>();

            decimal[]   info  = sdoGeom.ElemArray;
            ILinearRing shell = null;
            int         i     = 0;

            while (i < info.Length)
            {
                ICoordinateSequence cs = null;
                int numCompounds       = 0;
                if (info.getElementType(i).isCompound())
                {
                    numCompounds = info.getNumCompounds(i);
                    cs           = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                }
                else
                {
                    cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                }
                if (info.getElementType(i).isInteriorRing())
                {
                    ILinearRing lr = factory.CreateLinearRing(cs);
                    lr.SRID = (int)sdoGeom.Sdo_Srid;
                    holes.Add(lr);
                }
                else
                {
                    if (shell != null)
                    {
                        IPolygon polygon = factory.CreatePolygon(shell, holes.ToArray());
                        polygon.SRID = (int)sdoGeom.Sdo_Srid;
                        polygons.Add(polygon);
                        shell = null;
                    }
                    shell      = factory.CreateLinearRing(cs);
                    shell.SRID = (int)sdoGeom.Sdo_Srid;
                    holes      = new List <ILinearRing>();
                }
                i += 1 + numCompounds;
            }
            if (shell != null)
            {
                IPolygon polygon = factory.CreatePolygon(shell, holes.ToArray());
                polygon.SRID = (int)sdoGeom.Sdo_Srid;
                polygons.Add(polygon);
            }
            IMultiPolygon multiPolygon = factory.CreateMultiPolygon(polygons.ToArray());

            multiPolygon.SRID = (int)sdoGeom.Sdo_Srid;
            return(multiPolygon);
        }
        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));
        }
Пример #21
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);
        }
Пример #22
0
        private SdoGeometry WritePolygon(IGeometry geometry)
        {
            int         dimension   = GetGeometryDimension(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.GeometryType   = (int)SdoGeometryTypes.GTYPE.POLYGON;
            sdoGeometry.Dimensionality = dimension;
            sdoGeometry.LRS            = 0;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            AddPolygon(sdoGeometry, geometry as IPolygon, dimension);
            sdoGeometry.PropertiesToGTYPE();
            return(sdoGeometry);
        }
        private IMultiPoint ReadMultiPoint(SdoGeometry sdoGeom)
        {
            if (sdoGeom.OrdinatesArray.Length == 0)
            {
                return(MultiPoint.Empty);
            }
            double[]            ordinates  = sdoGeom.OrdinatesArrayOfDoubles;
            ICoordinateSequence cs         = ConvertOrdinateArray(ordinates, sdoGeom.Dimensionality);
            IMultiPoint         multipoint = _factory.CreateMultiPoint(cs);

            multipoint.SRID = (int)sdoGeom.Sdo_Srid;
            return(multipoint);
        }
        private IGeometry ReadGeometryCollection(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            List <IGeometry> geometries = new List <IGeometry>();

            //foreach (SdoGeometry elemGeom in sdoGeom.getElementGeometries())
            //{
            //    geometries.Add(ReadGeometry(elemGeom));
            //}
            // TODO : Check if this will work SdoGeometry does not
            // have a getElementgeometries method anymore
            geometries.Add(ReadGeometry(sdoGeom));
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
        private SdoGeometry WritePolygon(IGeometry geometry)
        {
            int         dim         = GetCoordDimension(geometry);
            int         lrsPos      = GetCoordinateLrsPosition(geometry);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.Sdo_Gtype      = (double)SDO_GTYPE.POLYGON;
            sdoGeometry.Dimensionality = dim;
            sdoGeometry.LRS            = lrsPos;
            sdoGeometry.Sdo_Srid       = geometry.SRID;
            AddPolygon(sdoGeometry, geometry as IPolygon);
            return(sdoGeometry);
        }
        private void AddPolygon(SdoGeometry sdoGeometry, IPolygon polygon)
        {
            int numInteriorRings        = polygon.NumInteriorRings;
            var info                    = new decimal[(numInteriorRings + 1) * 3];
            int ordinatesPreviousOffset = 0;

            if (sdoGeometry.OrdinatesArray != null)
            {
                ordinatesPreviousOffset = sdoGeometry.OrdinatesArray.Length;
            }
            int ordinatesOffset = ordinatesPreviousOffset + 1;
            var ordinates       = new decimal[] { };

            for (int i = 0; i < info.Length; i = i + 3)
            {
                ElementType  et;
                Coordinate[] coords;
                if (i == 0)
                {
                    et     = ElementType.EXTERIOR_RING_STRAIGHT_SEGMENTS;
                    coords = polygon.ExteriorRing.Coordinates;

                    // 1003: exterior polygon ring (must be specified in counterclockwise order)
                    if (!CGAlgorithms.IsCCW(coords))
                    {
                        coords = this.ReverseRing(coords);
                    }
                }
                else
                {
                    et     = ElementType.INTERIOR_RING_STRAIGHT_SEGMENTS;
                    coords = polygon.InteriorRings[i - 1].Coordinates;

                    // 2003: interior polygon ring (must be specified in clockwise order)
                    if (CGAlgorithms.IsCCW(coords))
                    {
                        coords = this.ReverseRing(coords);
                    }
                }
                //info.setElement(i, ordinatesOffset, et, 0);
                info[i + 0]     = ordinatesOffset;
                info[i + 1]     = et.EType();
                info[i + 2]     = et.Interpretation();
                ordinates       = this.ConvertAddCoordinates(ordinates, coords, sdoGeometry.Dimensionality, sdoGeometry.LRS > 0);
                ordinatesOffset = ordinatesPreviousOffset + ordinates.Length + 1;
            }
            sdoGeometry.addElement(info);
            sdoGeometry.AddOrdinates(ordinates);
        }
        private SdoGeometry WritePolygon(IGeometry geometry)
        {
            var dim         = this.GetCoordDimension(geometry);
            var lrsPos      = this.GetCoordinateLrsPosition(geometry);
            var sdoGeometry = new SdoGeometry
            {
                GeometryType   = SDO_GTYPE.POLYGON,
                Dimensionality = dim,
                LRS            = lrsPos,
                Sdo_Srid       = geometry.SRID
            };

            this.AddPolygon(sdoGeometry, geometry as IPolygon);
            return(sdoGeometry);
        }
Пример #28
0
        private SdoGeometry WriteLineString(IGeometry geometry)
        {
            int dimension = GetGeometryDimension(geometry);

            double[]    ordinates   = ConvertCoordinates(geometry.Coordinates, dimension);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.GeometryType            = (int)SdoGeometryTypes.GTYPE.LINE;
            sdoGeometry.Dimensionality          = dimension;
            sdoGeometry.LRS                     = 0;
            sdoGeometry.Sdo_Srid                = geometry.SRID;
            sdoGeometry.ElemArrayOfInts         = new[] { 1, (int)SdoGeometryTypes.ETYPE_SIMPLE.LINE, 1 };
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            sdoGeometry.PropertiesToGTYPE();
            return(sdoGeometry);
        }
        private IGeometry ReadPolygon(SdoGeometry sdoGeom)
        {
            if (sdoGeom.OrdinatesArray.Length == 0)
            {
                return(Polygon.Empty);
            }
            ILinearRing shell = null;

            ILinearRing[] holes            = new LinearRing[sdoGeom.NumElements - 1];
            int[]         info             = sdoGeom.ElemArrayOfInts;
            int           i                = 0;
            int           idxInteriorRings = 0;

            while (i < info.Length / ElementTupleSize)
            {
                ICoordinateSequence coordinates = null;
                int numCompounds = 0;
                int elementType  = GetElementType(info, i);
                if (elementType == (int)SdoGeometryTypes.ETYPE_COMPOUND.POLYGON_EXTERIOR ||
                    elementType == (int)SdoGeometryTypes.ETYPE_COMPOUND.POLYGON_INTERIOR)
                {
                    numCompounds = GetNumCompounds(info, i);
                    coordinates  = AppendCoordinateSequence(coordinates, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                }
                else
                {
                    coordinates = AppendCoordinateSequence(coordinates, GetElementCoordinateSequence(i, sdoGeom, false));
                }
                if (elementType == (int)SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_INTERIOR ||
                    elementType == (int)SdoGeometryTypes.ETYPE_COMPOUND.POLYGON_INTERIOR)
                {
                    holes[idxInteriorRings]      = _factory.CreateLinearRing(coordinates);
                    holes[idxInteriorRings].SRID = (int)sdoGeom.Sdo_Srid;
                    idxInteriorRings++;
                }
                else
                {
                    shell      = _factory.CreateLinearRing(coordinates);
                    shell.SRID = (int)sdoGeom.Sdo_Srid;
                }
                i += 1 + numCompounds;
            }
            IPolygon polygon = _factory.CreatePolygon(shell, holes);

            polygon.SRID = (int)sdoGeom.Sdo_Srid;
            return(polygon);
        }
        private SdoGeometry WriteLineString(IGeometry geometry)
        {
            int  dim    = GetCoordDimension(geometry);
            int  lrsPos = GetCoordinateLrsPosition(geometry);
            bool isLrs  = lrsPos > 0;

            double?[]   ordinates   = ConvertCoordinates(geometry.Coordinates, dim, isLrs);
            SdoGeometry sdoGeometry = new SdoGeometry();

            sdoGeometry.Sdo_Gtype               = (double)SDO_GTYPE.LINE;
            sdoGeometry.Dimensionality          = dim;
            sdoGeometry.LRS                     = lrsPos;
            sdoGeometry.Sdo_Srid                = geometry.SRID;
            sdoGeometry.ElemArray               = new double[] { 0, 1, (double)ElementType.LINE_STRAITH_SEGMENTS, 0 };
            sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
            return(sdoGeometry);
        }