Exemplo n.º 1
0
        public static FederatedModelInfo getFederatedModelByID(int FedID)
        {
            FederatedModelInfo fedModel = new FederatedModelInfo();
            string             currStep = "Getting federated ID";

            // Create separate connection with a short duration

            string           SqlStmt = "Select FEDERATEDID federatedID, ModelName, ProjectNumber, ProjectName, WORLDBBOX, MAXOCTREELEVEL, LastUpdateDate, Owner, DBConnection from BIMRL_FEDERATEDMODEL where FederatedID=" + FedID.ToString();
            OracleCommand    command = new OracleCommand(SqlStmt, DBConn);
            OracleDataReader reader  = command.ExecuteReader();

            try
            {
                if (!reader.Read())
                {
                    reader.Close();
                    return(null);
                }

                fedModel.FederatedID   = reader.GetInt32(0);
                fedModel.ModelName     = reader.GetString(1);
                fedModel.ProjectNumber = reader.GetString(2);
                fedModel.ProjectName   = reader.GetString(3);
                if (!reader.IsDBNull(4))
                {
                    SdoGeometry worldBB = reader.GetValue(4) as SdoGeometry;
                    Point3D     LLB     = new Point3D(worldBB.OrdinatesArrayOfDoubles[0], worldBB.OrdinatesArrayOfDoubles[1], worldBB.OrdinatesArrayOfDoubles[2]);
                    Point3D     URT     = new Point3D(worldBB.OrdinatesArrayOfDoubles[3], worldBB.OrdinatesArrayOfDoubles[4], worldBB.OrdinatesArrayOfDoubles[5]);
                    fedModel.WorldBoundingBox = LLB.ToString() + " " + URT.ToString();
                }
                if (!reader.IsDBNull(5))
                {
                    fedModel.OctreeMaxDepth = reader.GetInt16(5);
                }
                if (!reader.IsDBNull(6))
                {
                    fedModel.LastUpdateDate = reader.GetDateTime(6);
                }
                if (!reader.IsDBNull(7))
                {
                    fedModel.Owner = reader.GetString(7);
                }
                if (!reader.IsDBNull(8))
                {
                    fedModel.DBConnection = reader.GetString(8);
                }

                reader.Close();
            }
            catch (OracleException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                refBIMRLCommon.StackPushError(excStr);
                command.Dispose();
                throw;
            }

            command.Dispose();
            return(fedModel);
        }
Exemplo n.º 2
0
        public void generateUndirectedGraph(int FedID, string networkName)
        {
            string sqlStmt = "SELECT a.node_id, b.elementid, b.elementtype, b.name, b.body_major_axis_centroid from " + DBOperation.formatTabName(networkName) + "_node$ a, "
                             + "bimrl_element_" + FedID.ToString("X4") + " b where a.node_name = b.elementid";
            OracleCommand command = new OracleCommand(sqlStmt, DBOperation.DBConn);

            try
            {
                // Populate Dict with node information (with basic information from BIMRL_ELEMENT)
                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    int    nodeID   = reader.GetInt32(0);
                    string elemID   = reader.GetString(1);
                    string elemType = reader.GetString(2);
                    string name     = string.Empty;
                    if (!reader.IsDBNull(3))
                    {
                        name = reader.GetString(3);
                    }
                    Point3D centroid = null;
                    if (!reader.IsDBNull(4))
                    {
                        SdoGeometry sdogeom = reader.GetValue(4) as SdoGeometry;
                        centroid = new Point3D(sdogeom.SdoPoint.XD.Value, sdogeom.SdoPoint.YD.Value, sdogeom.SdoPoint.ZD.Value);
                    }
                    NodeDict.Add(nodeID, new Tuple <string, string, string, Point3D>(elemID, elemType, name, centroid));
                    ElemIDToNodeIDDict.Add(elemID, nodeID);
                }
                reader.Dispose();

                // generate the graph
                sqlStmt             = "Select link_id, start_node_id, end_node_id from " + DBOperation.formatTabName(networkName) + "_link$ where active='Y'";
                command.CommandText = sqlStmt;
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    int linkID    = reader.GetInt32(0);
                    int startNode = reader.GetInt32(1);
                    int endNode   = reader.GetInt32(2);

                    var edge = new TaggedEdge <int, int>(startNode, endNode, linkID);
                    graph.AddVerticesAndEdge(edge);
                }
                reader.Dispose();
                command.Dispose();
            }
            catch (OracleException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + sqlStmt;
                refBimrlCommon.StackPushError(excStr);
                command.Dispose();
            }
            catch (SystemException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + sqlStmt;
                refBimrlCommon.StackPushError(excStr);
                throw;
            }
        }
Exemplo n.º 3
0
 public SdoGeometry(SdoGeometry obj)
 {
     if (obj != null && this != obj)
     {
         SdoGType     = obj.SdoGType;
         SdoSrid      = obj.SdoSrid;
         SdoPoint     = (SdoPoint)obj.SdoPoint.Clone();
         SdoElemInfo  = (SdoElemInfo)obj.SdoElemInfo.Clone();
         SdoOrdinates = (SdoOrdinates)obj.SdoOrdinates.Clone();
     }
 }
Exemplo n.º 4
0
        public void createFacesFromBIMRLElement(int federatedId, string whereCond)
        {
            DBOperation.beginTransaction();
            string           currStep = string.Empty;
            OracleCommand    command  = new OracleCommand(" ", DBOperation.DBConn);
            OracleDataReader reader;

            try
            {
                SdoGeometry sdoGeomData = new SdoGeometry();

                string sqlStmt = "select elementid, geometrybody from " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                if (!string.IsNullOrEmpty(whereCond))
                {
                    sqlStmt += " and " + whereCond;
                }
                currStep = sqlStmt;

                command.CommandText = sqlStmt;
                command.FetchSize   = 20;

                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string elemID = reader.GetString(0);
                    sdoGeomData = reader.GetValue(1) as SdoGeometry;

                    Polyhedron geom;
                    if (!SDOGeomUtils.generate_Polyhedron(sdoGeomData, out geom))
                    {
                        continue;                                       // if there is something not right, skip the geometry
                    }
                    // - Process face information and create consolidated faces and store them into BIMRL_TOPO_FACE table
                    BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elemID, geom, _refBIMRLCommon, federatedId, null);
                    processFaces.simplifyAndMergeFaces();
                    processFaces.insertIntoDB(false);
                }
                reader.Dispose();
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                throw;
            }

            command.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generate Bounding Box that is optimized using only 2 coordinates
        /// </summary>
        /// <param name="geom">the geometry</param>
        /// <param name="bbox">output boundingbox</param>
        /// <returns></returns>
        public static bool generate_BoundingBox(SdoGeometry geom, out BoundingBox3D bbox)
        {
            int[]    elInfo   = geom.ElemArrayOfInts;
            double[] ordArray = geom.OrdinatesArrayOfDoubles;

            Point3D LLB = new Point3D(ordArray[0], ordArray[1], ordArray[2]);
            Point3D URT = new Point3D(ordArray[3], ordArray[4], ordArray[5]);

            bbox = new BoundingBox3D(LLB, URT);

            return(true);
        }
        private SdoGeometry WritePoint(IGeometry geometry)
        {
            int dimension = GetGeometryDimension(geometry);
            double[] coord = ConvertCoordinates(geometry.Coordinates, dimension);

            SdoGeometry sdoGeometry = new SdoGeometry();
            sdoGeometry.GeometryType = (int)SdoGeometryTypes.GTYPE.POINT;
            sdoGeometry.Dimensionality = dimension;
            sdoGeometry.LRS = 0;
            sdoGeometry.Sdo_Srid = geometry.SRID;
            sdoGeometry.ElemArrayOfInts = new [] { 1, (int)SdoGeometryTypes.ETYPE_SIMPLE.POINT, 1 };
            sdoGeometry.OrdinatesArrayOfDoubles = coord;
            sdoGeometry.PropertiesToGTYPE();
            return sdoGeometry;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generate a single line only
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public static bool generate_Line(SdoGeometry geom, out List <LineSegment3D> lineList)
        {
            int[]    elInfo   = geom.ElemArrayOfInts;
            double[] ordArray = geom.OrdinatesArrayOfDoubles;

            lineList = new List <LineSegment3D>();
            for (int oCount = 0; oCount < ordArray.Count() / 6; oCount++)
            {
                Point3D       startP = new Point3D(ordArray[(oCount * 6) + 0], ordArray[(oCount * 6) + 1], ordArray[(oCount * 6) + 2]);
                Point3D       endP   = new Point3D(ordArray[(oCount * 6) + 3], ordArray[(oCount * 6) + 4], ordArray[(oCount * 6) + 5]);
                LineSegment3D line   = new LineSegment3D(startP, endP);
                lineList.Add(line);
            }
            return(true);
        }
Exemplo n.º 8
0
        public static SdoGeometryTypes.GTYPE generateGeometryFromSDO(SdoGeometry sdoGeomData, out object geomOut)
        {
            SdoGeometryTypes.GTYPE sdoGtype;
            int gtype   = sdoGeomData.PropertiesFromGTYPE();
            int geomtyp = sdoGeomData.GeometryType;

            if (geomtyp == (int)SdoGeometryTypes.GTYPE.SOLID || geomtyp == (int)SdoGeometryTypes.GTYPE.MULTISOLID)
            {
                Polyhedron geomOutPH;
                generate_Polyhedron(sdoGeomData, out geomOutPH);
                geomOut  = geomOutPH;
                sdoGtype = SdoGeometryTypes.GTYPE.SOLID;
            }
            else if (geomtyp == (int)SdoGeometryTypes.GTYPE.POLYGON && sdoGeomData.OrdinatesArrayOfDoubles.Count() == 6)
            {  // Bounding Box
                BoundingBox3D bbox;
                generate_BoundingBox(sdoGeomData, out bbox);
                geomOut  = bbox;
                sdoGtype = SdoGeometryTypes.GTYPE.POLYGON;
            }
            else if (geomtyp == (int)SdoGeometryTypes.GTYPE.POLYGON || geomtyp == (int)SdoGeometryTypes.GTYPE.MULTIPOLYGON)
            {
                Face3D geomOutF3D;
                generate_Face3D(sdoGeomData, out geomOutF3D);
                geomOut  = geomOutF3D;
                sdoGtype = SdoGeometryTypes.GTYPE.POLYGON;
            }
            else if (geomtyp == (int)SdoGeometryTypes.GTYPE.LINE || geomtyp == (int)SdoGeometryTypes.GTYPE.MULTILINE)
            {
                List <LineSegment3D> geomOutLS;
                generate_Line(sdoGeomData, out geomOutLS);
                geomOut  = geomOutLS;
                sdoGtype = SdoGeometryTypes.GTYPE.LINE;
            }
            else if (geomtyp == (int)SdoGeometryTypes.GTYPE.POINT || geomtyp == (int)SdoGeometryTypes.GTYPE.MULTIPOINT)
            {
                List <Point3D> geomOutP;
                generate_Point(sdoGeomData, out geomOutP);
                geomOut  = geomOutP;
                sdoGtype = SdoGeometryTypes.GTYPE.POINT;
            }
            else
            {
                throw new Exception("Geometry not supported!");
            }

            return(sdoGtype);
        }
		private SdoGeometry WritePoint(IGeometry geometry)
		{
			int dim = GetCoordDimension(geometry);
			int lrsDim = GetCoordinateLrsPosition(geometry);
			bool isLrs = (lrsDim != 0);
			double?[] coord = ConvertCoordinates(geometry.Coordinates, dim, isLrs);
			SdoGeometry sdoGeometry = new SdoGeometry();
			sdoGeometry.Sdo_Gtype = (decimal)SdoGeometryTypes.GTYPE.POINT;
			sdoGeometry.Dimensionality = dim;
			sdoGeometry.LRS = lrsDim;
			sdoGeometry.Sdo_Srid = geometry.SRID;
			//sdoGeometry.Point = new SdoPoint();
			//sdoGeometry.Point.X = 0;
			//sdoGeometry.Point.Y = 0;
			//sdoGeometry.Point.Z = 0;
			sdoGeometry.ElemArray = new decimal[] { 1, (decimal)SdoGeometryTypes.ETYPE_SIMPLE.POINT, 1 };
			sdoGeometry.OrdinatesArrayOfDoubles = coord;
			return sdoGeometry;
		}
Exemplo n.º 10
0
        /// <summary>
        /// This function is to patch data, updating element's major axes and their OBB at the same time
        /// </summary>
        /// <param name="fedID"></param>
        /// <param name="whereCond"></param>
        public static void updateMajorAxesAndOBB(int fedID, string whereCond)
        {
            BIMRLCommon bimrlCommon = new BIMRLCommon();

            string sqlStmt = "SELECT ELEMENTID, GEOMETRYBODY FROM " + DBOperation.formatTabName("BIMRL_ELEMENT", fedID) + " WHERE GEOMETRYBODY IS NOT NULL";

            if (!string.IsNullOrEmpty(whereCond))
            {
                sqlStmt += " AND " + whereCond;
            }

            OracleCommand    cmd    = new OracleCommand(sqlStmt, DBOperation.DBConn);
            OracleDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                string      elementid = reader.GetString(0);
                SdoGeometry geom      = reader.GetValue(1) as SdoGeometry;

                Polyhedron polyH;
                if (!SDOGeomUtils.generate_Polyhedron(geom, out polyH))
                {
                    continue;  // something wrong, unable to get the polyhedron, skip
                }
                BIMRLGeometryPostProcess postProc = new BIMRLGeometryPostProcess(elementid, polyH, bimrlCommon, fedID, null);
                postProc.deriveMajorAxes();
                postProc.trueOBBFaces();
                postProc.projectedFaces();

                //// create OBB topo face information
                //if (postProc.OBB != null)
                //{
                //    Polyhedron obbGeom;
                //    if (SDOGeomUtils.generate_Polyhedron(postProc.OBB, out obbGeom))
                //    {
                //        BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elementid, obbGeom, bimrlCommon, fedID, "OBB");
                //        processFaces.simplifyAndMergeFaces();
                //        processFaces.insertIntoDB(false);
                //    }
                //}
            }
            reader.Close();
        }
Exemplo n.º 11
0
 private void AddPolygon(SdoGeometry sdoGeometry, IPolygon polygon)
 {
     int numInteriorRings = polygon.NumInteriorRings;
     decimal[] info = new decimal[(numInteriorRings + 1) * 3];
     int ordinatesOffset = 1;
     if (sdoGeometry.OrdinatesArray != null)
     {
         ordinatesOffset = sdoGeometry.OrdinatesArray.Length + 1;
     }
     double?[] ordinates = new double?[] { };
     for (int i = 0; i < info.Length; i++)
     {
         ElementType et;
         ICoordinate[] coords;
         if (i == 0)
         {
             et = ElementType.EXTERIOR_RING_STRAIGHT_SEGMENTS;
             coords = polygon.ExteriorRing.Coordinates;
             if (!CGAlgorithms.IsCCW(coords))
             {
                 coords = ReverseRing(coords);
             }
         }
         else
         {
             et = ElementType.INTERIOR_RING_STRAIGHT_SEGMENTS;
             coords = polygon.InteriorRings[i - 1].Coordinates;
             if (CGAlgorithms.IsCCW(coords))
             {
                 coords = ReverseRing(coords);
             }
         }
         //info.setElement(i, ordinatesOffset, et, 0);
         info[i + 0] = ordinatesOffset;
         info[i + 1] = (decimal)et;
         info[i + 2] = 0;
         ordinates = ConvertAddCoordinates(ordinates, coords, sdoGeometry.Dimensionality, sdoGeometry.LRS > 0);
         ordinatesOffset = ordinates.Length + 1;
     }
     sdoGeometry.addElement(info);
     sdoGeometry.AddOrdinates(ordinates);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            var features = new Collection <Geometry>();

            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                //string strSQL = "SELECT AsBinary(" + this.GeometryColumn + ") AS Geom ";
                string strSql = "SELECT g." + GeometryColumn + " as Geom ";
                strSql += " FROM " + Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strBbox;

                using (var command = new OracleCommand(strSql, conn))
                {
                    conn.Open();
                    using (OracleDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                SdoGeometry geom = dr[0] as SdoGeometry;
                                if (geom != null)
                                {
                                    features.Add(geom.AsGeometry());
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
        public IGeometry Read(SdoGeometry geom)
        {

            //Note: Returning null for null Datum
            if (geom == null)
                return null;
            
            Debug.Assert(geom.SdoGtype.HasValue);
            var gType = (int) geom.SdoGtype;
            
            Debug.Assert(geom.Sdo_Srid.HasValue);
            var srid = (int)geom.Sdo_Srid;
            
            var point = geom.Point;
            
            var retVal = Create(gType, point, geom.ElemArray, geom.OrdinatesArray);
            retVal.SRID = srid;
            
            return retVal;
        }
Exemplo n.º 14
0
        public static bool generate_Point(SdoGeometry geom, out List <Point3D> pointList)
        {
            pointList = new List <Point3D>();
            int gtype = geom.PropertiesFromGTYPE();

            if (geom.GeometryType == (int)SdoGeometryTypes.GTYPE.MULTIPOINT)
            {
                int[]    elInfo   = geom.ElemArrayOfInts;
                double[] ordArray = geom.OrdinatesArrayOfDoubles;
                for (int oCount = 0; oCount < elInfo.Count() / 3; oCount++)
                {
                    Point3D point = new Point3D(ordArray[(oCount * 3) + 0], ordArray[(oCount * 3) + 1], ordArray[(oCount * 3) + 2]);
                    pointList.Add(point);
                }
            }
            else
            {
                Point3D point = sdopointToPoint3D(geom.SdoPoint);
                pointList.Add(point);
            }
            return(true);
        }
Exemplo n.º 15
0
        public static bool generate_Face3D(SdoGeometry geom, out Face3D face)
        {
            int[]    elInfo   = geom.ElemArrayOfInts;
            double[] ordArray = geom.OrdinatesArrayOfDoubles;

            int        noLoop      = elInfo.Length / 3; // first loop is the outerloop and the rest will be innerloop
            int        totalVerts  = ordArray.Length / 3;
            List <int> vertsInLoop = new List <int>();

            for (int i = 0; i < noLoop; i++)
            {
                if (i == noLoop - 1)
                {
                    vertsInLoop.Add((totalVerts - (elInfo[i * 3] - 1) / 3));
                }
                else
                {
                    vertsInLoop.Add((elInfo[(i + 1) * 3] - elInfo[i * 3]) / 3);
                }
            }

            int initPos = 0;
            List <List <Point3D> > vertLists = new List <List <Point3D> >();

            for (int i = 0; i < noLoop; i++)
            {
                List <Point3D> vertList = new List <Point3D>();
                for (int v = 0; v < vertsInLoop[i]; v++)
                {
                    initPos = elInfo[i * 3] - 1;
                    int     pos  = initPos + v * 3;
                    Point3D vert = new Point3D(ordArray[pos], ordArray[pos + 1], ordArray[pos + 2]);
                    vertList.Add(vert);
                }
                vertLists.Add(vertList);
            }
            face = new Face3D(vertLists);
            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Reads the geometry.
        /// </summary>
        /// <param name="geom"></param>
        /// <returns></returns>
        public IGeometry Read(SdoGeometry geom)
        {
            //Note: Returning null for null Datum
            if (geom == null)
            {
                return(null);
            }

            Debug.Assert(geom.SdoGtype.HasValue);
            var gType = (int)geom.SdoGtype;

            Debug.Assert(geom.Sdo_Srid.HasValue);
            var srid = (int)geom.Sdo_Srid;

            var point = geom.Point;

            var retVal = Create(gType, point, geom.ElemArray, geom.OrdinatesArray);

            retVal.SRID = srid;

            return(retVal);
        }
        private IGeometry ReadGeometry(SdoGeometry sdoGeom)
        {
            var dim = sdoGeom.Dimensionality;
            var lrsDim = sdoGeom.LRS;

            if (sdoGeom.GeometryType == SDO_GTYPE.POINT)
            {
                return this.ReadPoint(sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.LINE)
            {
                return this.ReadLine(dim, lrsDim, sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.POLYGON)
            {
                return this.ReadPolygon(dim, lrsDim, sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.MULTIPOINT)
            {
                return this.ReadMultiPoint(dim, lrsDim, sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.MULTILINE)
            {
                return this.ReadMultiLine(dim, lrsDim, sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.MULTIPOLYGON)
            {
                return this.ReadMultiPolygon(dim, lrsDim, sdoGeom);
            }
            if (sdoGeom.GeometryType == SDO_GTYPE.COLLECTION)
            {
                return this.ReadGeometryCollection(dim, lrsDim, sdoGeom);
            }

            throw new ArgumentException("Type not supported: " + sdoGeom.Sdo_Gtype);
        }
		private IGeometry ReadGeometry(SdoGeometry sdoGeom)
		{
			int dim = sdoGeom.Dimensionality;
			int lrsDim = sdoGeom.LRS;

			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.POINT)
			{
				return ReadPoint(sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.LINE)
			{
				return ReadLine(dim, lrsDim, sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.POLYGON)
			{
				return ReadPolygon(dim, lrsDim, sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.MULTIPOINT)
			{
				return ReadMultiPoint(dim, lrsDim, sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.MULTILINE)
			{
				return ReadMultiLine(dim, lrsDim, sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.MULTIPOLYGON)
			{
				return ReadMultiPolygon(dim, lrsDim, sdoGeom);
			}
			if (sdoGeom.Sdo_Gtype.Value == (decimal)SdoGeometryTypes.GTYPE.COLLECTION)
			{
				return ReadGeometryCollection(dim, lrsDim, sdoGeom);
			}

			throw new ArgumentException("Type not supported: " + sdoGeom.Sdo_Gtype);
		}
        private IMultiLineString ReadMultiLine(int dim, int lrsDim,
                                                    SdoGeometry sdoGeom)
        {
            bool lrs = sdoGeom.LRS > 0;
            decimal[] info = sdoGeom.ElemArray;
            ILineString[] lines =
                lrs
                    ? new MLineString[sdoGeom.ElemArray.Length]
                    : new LineString[sdoGeom.ElemArray.Length];
            int i = 0;
            while (i < info.Length)
            {
                ICoordinateSequence cs = null;
                //if (info.getElementType(i).isCompound())
                //{
                //    int numCompounds = info.getNumCompounds(i);
                //    cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                //    LineString line =
                //        lrs
                //            ? factory.CreateMultiLineString(cs)
                //            : factory.CreateLineString(cs);
                //    lines[i] = line;
                //    i += 1 + numCompounds;
                //}
                //else
                //{
                cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                //LineString line = lrs ? (LineString)factory.CreateMultiLineString(cs) : factory.CreateLineString(cs);
                ILineString line = factory.CreateLineString(cs);
                lines[i] = line;
                i++;
                //}
            }

            IMultiLineString mls = lrs
                                       ? factory.CreateMultiLineString((MLineString[])lines)
                                       : factory.CreateMultiLineString(lines);

            mls.SRID = (int)sdoGeom.Sdo_Srid;
            return mls;
        }
        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;
        }
Exemplo n.º 21
0
        override protected object ShapeParameterValue(OgcSpatialFeatureclass featureClass, IGeometry shape, int srid, out bool AsSqlParameter)
        {
            AsSqlParameter = false;

            return(SdoGeometry.FromGeometry(shape, srid));
        }
Exemplo n.º 22
0
        public static IGeometry AsGeometry(this SdoGeometry sdoGeometry, IGeometryFactory factory)
        {
            var reader = new OracleGeometryReader(factory);

            return(reader.Read(sdoGeometry));
        }
 public IGeometry Read(SdoGeometry geometry)
 {
     geometry.PropertiesToGTYPE();
     return this.ReadGeometry(geometry);
 }
        private double[] ExtractOrdinatesOfElement(int element, SdoGeometry sdoGeom, bool hasNextSE)
        {
            int start = (int)sdoGeom.ElemArray[element * 3] - 1;
            int end = sdoGeom.OrdinatesArray.Length;

            if (((element + 1) * 3) < sdoGeom.ElemArray.Length - 1)
            {
                end = (int)sdoGeom.ElemArray[(element + 1) * 3];
                // if this is a subelement of a compound geometry,
                // the last point is the first point of
                // the next subelement.
                if (hasNextSE)
                {
                    end += sdoGeom.Dimensionality;
                }
            }
            return sdoGeom.OrdinatesArrayOfDoubles.Skip(start).Take(end - start).ToArray();
        }
 /**
  * Gets the ICoordinateSequence corresponding to a compound element.
  *
  * @param idxFirst
  *            the first sub-element of the compound element
  * @param idxLast
  *            the last sub-element of the compound element
  * @param sdoGeom
  *            the SdoGeometry that holds the compound element.
  * @return
  */
 private ICoordinateSequence GetCompoundCSeq(int idxFirst, int idxLast, SdoGeometry sdoGeom)
 {
     ICoordinateSequence cs = null;
     for (int i = idxFirst; i <= idxLast; i++)
     {
         // pop off the last element as it is added with the next
         // coordinate sequence
         if (cs != null && cs.Count > 0)
         {
             Coordinate[] coordinates = cs.ToCoordinateArray();
             Coordinate[] newCoordinates = new Coordinate[coordinates.Length - 1];
             Array.Copy(coordinates, 0, newCoordinates, 0, coordinates.Length - 1);
             cs = factory.CoordinateSequenceFactory.Create(newCoordinates);
         }
         cs = Add(cs, GetElementCSeq(i, sdoGeom, (i < idxLast)));
     }
     return cs;
 }
 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);
 }
 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;
 }
		/**
	 * Gets the ICoordinateSequence corresponding to an element.
	 * 
	 * @param i
	 * @param sdoGeom
	 * @return
	 */
		private ICoordinateSequence GetElementCSeq(int i, SdoGeometry sdoGeom, bool hasNextSE) {
			ElementType type = (ElementType)sdoGeom.ElemArray[i * 3 + 1];
			Double[] elemOrdinates = ExtractOrdinatesOfElement(i, sdoGeom, hasNextSE);

			ICoordinateSequence cs;

			bool isCircle =
				type == ElementType.INTERIOR_RING_CIRCLE ||
				type == ElementType.EXTERIOR_RING_CIRCLE;

			bool isArcSegment =
				type == ElementType.LINE_ARC_SEGMENTS ||
				type == ElementType.INTERIOR_RING_ARC_SEGMENTS ||
				type == ElementType.EXTERIOR_RING_ARC_SEGMENTS;

			bool isRect =
				type == ElementType.INTERIOR_RING_RECT ||
				type == ElementType.EXTERIOR_RING_RECT;

			bool isExteriorRing =
				type == ElementType.EXTERIOR_RING_STRAIGHT_SEGMENTS ||
				type == ElementType.EXTERIOR_RING_ARC_SEGMENTS ||
				type == ElementType.EXTERIOR_RING_RECT ||
				type == ElementType.EXTERIOR_RING_CIRCLE;


			bool isStraightSegment =
				type == ElementType.POINT ||
				type == ElementType.LINE_STRAITH_SEGMENTS ||
				type == ElementType.INTERIOR_RING_STRAIGHT_SEGMENTS ||
				type == ElementType.EXTERIOR_RING_STRAIGHT_SEGMENTS;

			if (isStraightSegment)
			{
				cs = ConvertOrdinateArray(elemOrdinates, sdoGeom);
			}
			else if ( isArcSegment || isCircle)
			{
				ICoordinate[] linearized = Linearize(elemOrdinates, sdoGeom.Dimensionality, sdoGeom.LRS > 0, isCircle);
				cs = factory.CoordinateSequenceFactory.Create(linearized);
			}
			else if (isRect)
			{
				cs = ConvertOrdinateArray(elemOrdinates, sdoGeom);
				ICoordinate ll = cs.GetCoordinate(0);
				ICoordinate ur = cs.GetCoordinate(1);
				ICoordinate lr = new Coordinate(ur.X, ll.Y);
				ICoordinate ul = new Coordinate(ll.X, ur.Y);
				if (isExteriorRing)
				{
					cs = factory.CoordinateSequenceFactory.Create(new ICoordinate[] {ll, lr, ur, ul, ll});
				}
				else
				{
					cs = factory.CoordinateSequenceFactory.Create(new ICoordinate[] {ll, ul, ur, lr, ll});
				}
			}
			else
			{
				throw new ApplicationException("Unexpected Element type in compound: " + type);
			}
			return cs;
		}
		private IGeometry ReadPolygon(int dim, int lrsDim, SdoGeometry sdoGeom) {
			LinearRing shell = null;
			LinearRing[] holes = new LinearRing[sdoGeom.getNumElements() - 1];
			decimal[] info = sdoGeom.ElemArray;
			int i = 0;
			int idxInteriorRings = 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()) {
					holes[idxInteriorRings] = factory
						.CreateLinearRing(cs);
					holes[idxInteriorRings].SRID = (int)sdoGeom.Sdo_Srid;
					idxInteriorRings++;
				} else {
					shell = factory.CreateLinearRing(cs);
					shell.SRID = (int)sdoGeom.Sdo_Srid;
				}
				i += 1 + numCompounds;
			}
			IPolygon polygon = factory.CreatePolygon(shell, holes);
			polygon.SRID = (int)sdoGeom.Sdo_Srid;
			return polygon;
		}
		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.CreateMultiLineString(cs)
					: factory.CreateLineString(cs);
			ls.SRID = (int)sdoGeom.Sdo_Srid;
			return ls;
		}
Exemplo n.º 31
0
        public BIMRLProcessModel(IModel model, bool update)
        {
            //IfcProject proj = model.IfcProject;
            IfcStore modelStore = model as IfcStore;
            string   currStep   = String.Empty;

            _bimrlCommon.resetAll();

            // Connect to Oracle DB
            DBOperation.refBIMRLCommon = _bimrlCommon;   // important to ensure DBoperation has reference to this object!!

            try
            {
                DBOperation.ExistingOrDefaultConnection();
            }
            catch
            {
                if (DBOperation.UIMode)
                {
                    BIMRLErrorDialog erroDlg = new BIMRLErrorDialog(_bimrlCommon);
                    erroDlg.ShowDialog();
                }
                else
                {
                    Console.Write(_bimrlCommon.ErrorMessages);
                }
                return;
            }

            DBOperation.commitInterval = 5000;

            // Initial Spatial index for later use
            BIMRLSpatialIndex spIdx = new BIMRLSpatialIndex(_bimrlCommon);

            try
            {
                DBOperation.beginTransaction();
                IIfcProject firstProject;
                if (modelStore.IsFederation)
                {
                    IfcStore firstModel = modelStore.ReferencedModels.FirstOrDefault().Model as IfcStore;
                    firstProject = firstModel.Instances.OfType <IIfcProject>().FirstOrDefault();
                }
                else
                {
                    firstProject = modelStore.Instances.OfType <IIfcProject>().FirstOrDefault();
                }
                string projLName;

                // Check whether Model has been defined before
                if (string.IsNullOrEmpty(firstProject.LongName))
                {
                    projLName = firstProject.Name + " - Federated";
                }
                else
                {
                    projLName = firstProject.LongName;
                }

                string modelNameFromFile;
                if (!string.IsNullOrEmpty(modelStore.FileName))
                {
                    modelNameFromFile = Path.GetFileNameWithoutExtension(modelStore.FileName);
                }
                else
                {
                    modelNameFromFile = firstProject.Name + " - " + firstProject.LongName;
                }

                currStep = "Getting Federated ID from BIMRL_FEDERATEDMODEL - Model name, Project name and longname: " + modelNameFromFile + "; " + firstProject.Name + "; " + firstProject.LongName;
                FederatedModelInfo fedModel;
                FedIDStatus        stat = DBOperation.getFederatedModel(modelNameFromFile, projLName, firstProject.Name, out fedModel);
                if (stat == FedIDStatus.FedIDNew)
                {
                    DBOperation.currFedModel = fedModel;
                    // Create new set of tables using the fedID as suffix
                    int retStat = DBOperation.createModelTables(DBOperation.currFedModel.FederatedID);
                }
                else
                {
                    DBOperation.currFedModel = fedModel;
                    if (!fedModel.Owner.Equals(DBOperation.DBUserID))
                    {
                        _bimrlCommon.StackPushError("%Error: Only the Owner (" + fedModel.Owner + ") can delete or override existing model (!" + fedModel.ModelName + ")");
                        throw new Exception("%Error: Unable to overwrite exisitng model");
                    }

                    // Drop and recreate tables
                    currStep = "Dropping existing model tables (ID: " + DBOperation.currFedModel.FederatedID.ToString("X4") + ")";
                    int retStat = DBOperation.dropModelTables(DBOperation.currFedModel.FederatedID);
                    currStep = "Creating model tables (ID: " + DBOperation.currFedModel.FederatedID.ToString("X4") + ")";
                    retStat  = DBOperation.createModelTables(DBOperation.currFedModel.FederatedID);
                }

                DBOperation.currSelFedID = DBOperation.currFedModel.FederatedID;    // set the static variable keeping the selected Fed Id

                if (modelStore.IsFederation)
                {
                    // get all models

                    foreach (IReferencedModel refModel in modelStore.ReferencedModels)
                    {
                        IfcStore m = refModel.Model as IfcStore;
                        currStep = "Getting Model ID for Federated model ID:" + DBOperation.currFedModel.FederatedID.ToString("X4");
                        _bimrlCommon.ClearDicts();

                        _ModelID = DBOperation.getModelID(DBOperation.currFedModel.FederatedID);
                        doModel(m);
                        BIMRLUtils.ResetIfcUnitDicts();
                    }
                }
                else
                {
                    currStep = "Getting Model ID for Federated model ID:" + DBOperation.currFedModel.FederatedID.ToString("X4");
                    _ModelID = DBOperation.getModelID(DBOperation.currFedModel.FederatedID);
                    doModel(modelStore);
                    BIMRLUtils.ResetIfcUnitDicts();
                }
            }
            catch (Exception e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                _bimrlCommon.StackPushError(excStr);
                DBOperation.endTransaction(false); // rollback
            }

            DBOperation.endTransaction(true);  // Commit = true

            try
            {
                DBOperation.beginTransaction();
                OracleCommand cmd = new OracleCommand("", DBOperation.DBConn);

                // Define the spatial index metadata
                double marginX = (_bimrlCommon.URT_X - _bimrlCommon.LLB_X) * 0.2; // 20% margin
                double marginY = (_bimrlCommon.URT_Y - _bimrlCommon.LLB_Y) * 0.2; // 20% margin
                double marginZ = (_bimrlCommon.URT_Z - _bimrlCommon.LLB_Z) * 0.2; // 20% margin
                double lowerX  = _bimrlCommon.LLB_X - marginX;
                double upperX  = _bimrlCommon.URT_X + marginX;
                double lowerY  = _bimrlCommon.LLB_Y - marginY;
                double upperY  = _bimrlCommon.URT_Y + marginY;
                double lowerZ  = _bimrlCommon.LLB_Z - marginZ;
                double upperZ  = _bimrlCommon.URT_Z + marginZ;

                string sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                                 + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','GEOMETRYBODY',"
                                 + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                                 + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                                 + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                                 + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','GEOMETRYBODY_BBOX',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','GEOMETRYBODY_BBOX_CENTROID',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','GEOMETRYFOOTPRINT',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','GEOMETRYAXIS',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','BODY_MAJOR_AXIS1',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', -1.01, 1.01, 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','BODY_MAJOR_AXIS2',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', -1.01, 1.01, 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','BODY_MAJOR_AXIS3',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', -1.01, 1.01, 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_ELEMENT_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','BODY_MAJOR_AXIS_CENTROID',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_TOPO_FACE_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','POLYGON',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_TOPO_FACE_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','NORMAL',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', -1.01, 1.01, 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', -1.01, 1.01, 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                sqlStmt = "insert into USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES "
                          + "('BIMRL_TOPO_FACE_" + DBOperation.currFedModel.FederatedID.ToString("X4") + "','CENTROID',"
                          + "SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', " + lowerX.ToString() + ", " + upperX.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Y', " + lowerY.ToString() + ", " + upperY.ToString() + ", 0.000001),"
                          + "SDO_DIM_ELEMENT('Z', " + lowerZ.ToString() + ", " + upperZ.ToString() + ", 0.000001)),"
                          + "NULL)";
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();


                sqlStmt         = "Update BIMRL_FEDERATEDMODEL SET LastUpdateDate=sysdate WHERE FederatedID=" + DBOperation.currFedModel.FederatedID.ToString();
                currStep        = sqlStmt;
                cmd.CommandText = sqlStmt;
                cmd.ExecuteNonQuery();

                // get the world BBox coordinates and update the BIMRL_FEDERATEDMODEL Table
                SdoGeometry Bbox = new SdoGeometry();
                Bbox.Dimensionality = 3;
                Bbox.LRS            = 0;
                Bbox.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                int gType = Bbox.PropertiesToGTYPE();

                int[] elemInfoArr = { 1, (int)SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_EXTERIOR, 1 };
                Bbox.ElemArrayOfInts = elemInfoArr;

                double[] coordArr = new double[6];
                coordArr[0] = _bimrlCommon.LLB_X;
                coordArr[1] = _bimrlCommon.LLB_Y;
                coordArr[2] = _bimrlCommon.LLB_Z;
                coordArr[3] = _bimrlCommon.URT_X;
                coordArr[4] = _bimrlCommon.URT_Y;
                coordArr[5] = _bimrlCommon.URT_Z;
                Bbox.OrdinatesArrayOfDoubles = coordArr;

                // Create spatial index from the new model (list of triangles are accummulated during processing of geometries)
                sqlStmt  = "update BIMRL_FEDERATEDMODEL SET WORLDBBOX=:1 , MAXOCTREELEVEL=:2 WHERE FEDERATEDID=" + DBOperation.currFedModel.FederatedID.ToString();
                currStep = sqlStmt;
                OracleCommand command = new OracleCommand(" ", DBOperation.DBConn);
                command.CommandText = sqlStmt;

                OracleParameter[] sdoGeom2 = new OracleParameter[3];
                sdoGeom2[0]             = command.Parameters.Add("1", OracleDbType.Object);
                sdoGeom2[0].Direction   = ParameterDirection.Input;
                sdoGeom2[0].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                sdoGeom2[0].Value       = Bbox;
                sdoGeom2[0].Size        = 1;
                sdoGeom2[1]             = command.Parameters.Add("2", OracleDbType.Int16);
                sdoGeom2[1].Direction   = ParameterDirection.Input;
                sdoGeom2[1].Value       = DBOperation.OctreeSubdivLevel;
                sdoGeom2[1].Size        = 1;

                int commandStatus = command.ExecuteNonQuery();

                if (DBOperation.OnepushETL)
                {
                    DBOperation.commitInterval = 10000;
                    int octreeLevel = DBOperation.computeRecomOctreeLevel(DBOperation.currFedModel.FederatedID);

                    // 1. Create Octree spatial indexes and the Brep Topology Faces
                    spIdx.createSpatialIndexFromBIMRLElement(DBOperation.currFedModel.FederatedID, null, true, true);

                    // 2. Update major Axes and OBB
                    BIMRLUtils.updateMajorAxesAndOBB(DBOperation.currFedModel.FederatedID, null);

                    // 3. Enhance Space Boundary
                    EnhanceBRep eBrep = new EnhanceBRep();
                    eBrep.enhanceSpaceBoundary(null);

                    // 4. Process Face orientations. We will procees the normal face first and then after that the spacial ones (OBB, PROJOBB)
                    string whereCond2 = "";
                    BIMRLCommon.appendToString(" TYPE NOT IN ('OBB','PROJOBB')", " AND ", ref whereCond2);
                    eBrep.ProcessOrientation(whereCond2);
                    whereCond2 = "";
                    BIMRLCommon.appendToString(" TYPE='OBB'", " AND ", ref whereCond2);
                    eBrep.ProcessOrientation(whereCond2);
                    whereCond2 = "";
                    BIMRLCommon.appendToString(" TYPE='PROJOBB'", " AND ", ref whereCond2);
                    eBrep.ProcessOrientation(whereCond2);

                    // 5. Create Graph Data
                    BIMRLGraph.GraphData graphData = new BIMRLGraph.GraphData();
                    graphData.createCirculationGraph(DBOperation.currFedModel.FederatedID);
                    graphData.createSpaceAdjacencyGraph(DBOperation.currFedModel.FederatedID);

                    sqlStmt = "UPDATE BIMRL_FEDERATEDMODEL SET LASTUPDATEDATE=sysdate";
                    BIMRLCommon.appendToString("MAXOCTREELEVEL=" + octreeLevel.ToString(), ", ", ref sqlStmt);
                    BIMRLCommon.appendToString("WHERE FEDERATEDID=" + DBOperation.currFedModel.FederatedID.ToString(), " ", ref sqlStmt);
                    DBOperation.executeSingleStmt(sqlStmt);
                }
                else
                {
                    // Minimum (without One-push ETL, create the bounding boxes (AABB)
                    spIdx.createSpatialIndexFromBIMRLElement(DBOperation.currFedModel.FederatedID, null, false, false);
                }

                var    location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
                string exePath  = new FileInfo(location.AbsolutePath).Directory.FullName;

                // (Re)-Create the spatial indexes
                DBOperation.executeScript(Path.Combine(exePath, "script", "BIMRL_Idx_SpatialIndexes.sql"), DBOperation.currFedModel.FederatedID);
                DBOperation.executeScript(Path.Combine(exePath, "script", "BIMRL_Idx_TopoFace.sql"), DBOperation.currFedModel.FederatedID);
                DBOperation.executeScript(Path.Combine(exePath, "script", "BIMRL_Idx_MajorAxes.sql"), DBOperation.currFedModel.FederatedID);

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOM_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (GEOMETRYBODY) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMBB_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (GeometryBody_BBOX) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMBBC_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (GeometryBody_BBOX_CENTROID) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMFP_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (GeometryFootprint) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMAX_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (GeometryAxis) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMMJ1_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (BODY_MAJOR_AXIS1) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMMJ2_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (BODY_MAJOR_AXIS2) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMMJ3_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (BODY_MAJOR_AXIS3) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_BIMRLELEM_GEOMMJC_" + currFedID.ToString("X4") + " on BIMRL_ELEMENT_" + currFedID.ToString("X4")
                //            + " (BODY_MAJOR_AXIS_CENTROID) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_TOPOF_POLYGON_" + currFedID.ToString("X4") + " on BIMRL_TOPO_FACE_" + currFedID.ToString("X4")
                //            + " (POLYGON) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_TOPOF_NORMAL_" + currFedID.ToString("X4") + " on BIMRL_TOPO_FACE_" + currFedID.ToString("X4")
                //            + " (NORMAL) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                //sqlStmt = "Create Index IDX_TOPOF_CENTROID_" + currFedID.ToString("X4") + " on BIMRL_TOPO_FACE_" + currFedID.ToString("X4")
                //            + " (CENTROID) INDEXTYPE is MDSYS.SPATIAL_INDEX PARAMETERS ('sdo_indx_dims=3')";
                //currStep = sqlStmt;
                //cmd.CommandText = sqlStmt;
                //cmd.ExecuteNonQuery();

                DBOperation.commitTransaction();
            }
            catch (Exception e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                _bimrlCommon.StackPushError(excStr);
                if (DBOperation.UIMode)
                {
                    BIMRLErrorDialog errorDlg = new BIMRLErrorDialog(_bimrlCommon);
                    errorDlg.ShowDialog();
                }
                else
                {
                    Console.Write(_bimrlCommon.ErrorMessages);
                }
            }

            // There are entries in the error stack, show them at the end
            if (_bimrlCommon.BIMRLErrorStackCount > 0)
            {
                if (DBOperation.UIMode)
                {
                    BIMRLErrorDialog errorDlg = new BIMRLErrorDialog(_bimrlCommon);
                    errorDlg.ShowDialog();
                }
                else
                {
                    Console.Write(_bimrlCommon.ErrorMessages);
                }
            }
        }
        private void AddPolygon(SdoGeometry sdoGeometry, IPolygon polygon, int dimention)
        {
            int numInteriorRings = polygon.NumInteriorRings;
            int[] elements = new int[(numInteriorRings + 1) * ElementTupleSize];
            int ordinatesOffset = 1;
            ICoordinate[] coords;
            if (sdoGeometry.OrdinatesArray != null && sdoGeometry.OrdinatesArray.Length>0)
            {
                ordinatesOffset = sdoGeometry.OrdinatesArray.Length+1;
            }
            double[] ordinates = new double[] { };

            //addExterior
            elements[0] = ordinatesOffset;
            elements[1] = (int) SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_EXTERIOR;
            elements[2] = 1;
            coords = polygon.ExteriorRing.Coordinates;
            if (!CGAlgorithms.IsCCW(coords))
            {
                coords = ReverseRing(coords);
            }
            ordinates = AppendCoordinates(ordinates, ConvertCoordinates(coords, dimention));
            ordinatesOffset += ordinates.Length ;
            //add holes
            for (int i = 0; i < numInteriorRings; i++)
            {

                coords = polygon.InteriorRings[i].Coordinates;
                if (CGAlgorithms.IsCCW(coords))
                {
                    coords = ReverseRing(coords);
                }


                elements[(i + 1) * ElementTupleSize + 0] = ordinatesOffset;
                elements[(i + 1) * ElementTupleSize + 1] = (int)SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_INTERIOR;
                elements[(i + 1) * ElementTupleSize + 2] = 1;
                ordinates = AppendCoordinates(ordinates, ConvertCoordinates(coords, dimention));
                ordinatesOffset = ordinates.Length + 1;
            }
            sdoGeometry.AddElement(elements);
            sdoGeometry.AddOrdinates(ordinates);
        }
 private IGeometry ReadPolygon(int dim, int lrsDim, SdoGeometry sdoGeom)
 {
     ILinearRing shell = null;
     //ILinearRing[] holes = new LinearRing[sdoGeom.ElemArray.Length - 1];
     ILinearRing[] holes = new LinearRing[0];
     var info = sdoGeom.ElemArray;
     var infoSize = info.Length / 3;
     int i = 0;
     int idxInteriorRings = 0;
     while (i < infoSize)
     {
         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())
         //{
         //    holes[idxInteriorRings] = factory
         //        .CreateLinearRing(cs);
         //    holes[idxInteriorRings].SRID = (int)sdoGeom.Sdo_Srid;
         //    idxInteriorRings++;
         //}
         //else
         //{
         shell = factory.CreateLinearRing(cs);
         shell.SRID = (int)sdoGeom.Sdo_Srid;
         //}
         i += 1 + numCompounds;
     }
     IPolygon polygon = factory.CreatePolygon(shell, holes);
     polygon.SRID = (int)sdoGeom.Sdo_Srid;
     return polygon;
 }
 private IMultiPolygon ReadMultiPolygon(int dim, int lrsDim, SdoGeometry sdoGeom)
 {
     List<ILinearRing> holes = new List<ILinearRing>();
     List<IPolygon> polygons = new List<IPolygon>();
     var 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 SdoGeometry WriteMultiPolygon(IGeometry geometry)
 {
     int dimension = GetGeometryDimension(geometry);
     SdoGeometry sdoGeometry = new SdoGeometry();
     sdoGeometry.GeometryType = (int)SdoGeometryTypes.GTYPE.MULTIPOLYGON;
     sdoGeometry.Dimensionality = dimension;
     sdoGeometry.LRS = 0;
     sdoGeometry.Sdo_Srid = geometry.SRID;
     for (int i = 0; i < geometry.NumGeometries; i++)
     {
         try
         {
             IPolygon pg = (IPolygon)geometry.GetGeometryN(i);
             AddPolygon(sdoGeometry, pg, dimension);
         }
         catch (Exception e)
         {
             throw new ApplicationException(
                 "Found geometry that was not a Polygon in MultiPolygon", e);
         }
     }
     sdoGeometry.PropertiesToGTYPE();
     return sdoGeometry;
 }
        /**
         * Gets the ICoordinateSequence corresponding to an element.
         *
         * @param i
         * @param sdoGeom
         * @return
         */
        private ICoordinateSequence GetElementCSeq(int i, SdoGeometry sdoGeom, bool hasNextSE)
        {
            var eType = sdoGeom.ElemArray[i * 3 + 1];
            var interpretation = sdoGeom.ElemArray[i * 3 + 2];
            var type = ElementTypes.ParseType(eType, interpretation);
            var elemOrdinates = this.ExtractOrdinatesOfElement(i, sdoGeom, hasNextSE);

            ICoordinateSequence cs;

            if (type.IsStraightSegment())
            {
                cs = this.ConvertOrdinateArray(elemOrdinates, sdoGeom);
            }
            else if (type.IsArcSegment() || type.IsCircle())
            {
                var linearized = this.Linearize(elemOrdinates, sdoGeom.Dimensionality, sdoGeom.LRS > 0, type.IsCircle());
                cs = this.factory.CoordinateSequenceFactory.Create(linearized);
            }
            else if (type.IsRect())
            {
                cs = this.ConvertOrdinateArray(elemOrdinates, sdoGeom);
                var ll = cs.GetCoordinate(0);
                var ur = cs.GetCoordinate(1);
                var lr = new Coordinate(ur.X, ll.Y);
                var ul = new Coordinate(ll.X, ur.Y);
                if (type.IsExteriorRing())
                {
                    cs = this.factory.CoordinateSequenceFactory.Create(new[] { ll, lr, ur, ul, ll });
                }
                else
                {
                    cs = this.factory.CoordinateSequenceFactory.Create(new[] { ll, ul, ur, lr, ll });
                }
            }
            else
            {
                throw new ApplicationException("Unexpected Element type in compound: " + type);
            }
            return cs;
        }
Exemplo n.º 37
0
        public static void UpdateElementTransform(IfcStore _model, string projectNumber, string projectName)
        {
            DBOperation.beginTransaction();
            DBOperation.commitInterval = 5000;
            string      currStep        = string.Empty;
            BIMRLCommon _refBIMRLCommon = new BIMRLCommon();

            int commandStatus   = -1;
            int currInsertCount = 0;

            OracleCommand command = new OracleCommand(" ", DBOperation.DBConn);
            XbimMatrix3D  m3D     = new XbimMatrix3D();

            if (string.IsNullOrEmpty(projectName))
            {
                projectName = projectNumber + " - Federated";
            }

            string modelName;

            if (!string.IsNullOrEmpty(_model.FileName))
            {
                modelName = Path.GetFileNameWithoutExtension(_model.FileName);
            }
            else
            {
                modelName = projectNumber + " - " + projectName;
            }

            command.CommandText = "SELECT FEDERATEDID FROM bimrl_federatedmodel WHERE MODELNAME = '" + modelName + "' AND PROJECTNUMBER='" + projectNumber + "' AND PROJECTNAME='" + projectName + "'";
            object oFedID = command.ExecuteScalar();

            if (oFedID == null)
            {
                return;
            }

            int fedID = int.Parse(oFedID.ToString());

            command.CommandText = "SELECT ELEMENTID, LINENO FROM " + DBOperation.formatTabName("bimrl_element", fedID) + " WHERE GEOMETRYBODY IS NOT NULL";
            OracleDataReader reader = command.ExecuteReader();
            SortedDictionary <int, string> elemList = new SortedDictionary <int, string>();

            while (reader.Read())
            {
                string elemid = reader.GetString(0);
                int    lineNo = reader.GetInt32(1);
                elemList.Add(lineNo, elemid);
            }
            reader.Close();

            Xbim3DModelContext context = new Xbim3DModelContext(_model);

            foreach (KeyValuePair <int, string> elemListItem in elemList)
            {
                //IEnumerable<XbimGeometryData> geomDataList = _model.GetGeometryData(elemListItem.Key, XbimGeometryType.TriangulatedMesh);
                IIfcProduct product = _model.Instances[elemListItem.Key] as IIfcProduct;

                IEnumerable <XbimShapeInstance> shapeInstances = context.ShapeInstancesOf(product).Where(x => x.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded);
                if (shapeInstances.Count() == 0)
                {
                    continue;    // SKip if the product has no geometry
                }
                XbimMeshGeometry3D     prodGeom  = new XbimMeshGeometry3D();
                IXbimShapeGeometryData shapeGeom = context.ShapeGeometry(shapeInstances.FirstOrDefault().ShapeGeometryLabel);
                //XbimModelExtensions.Read(prodGeom, shapeGeom.ShapeData, shapeInstances.FirstOrDefault().Transformation);

                //XbimGeometryData sdoGeomData = geomDataList.First();
                //m3D = sdoGeomData.Transform;
                //m3D = XbimMatrix3D.FromArray(sdoGeomData.DataArray2);       // Xbim 3.0 removes Tranform property
                m3D = shapeInstances.FirstOrDefault().Transformation;
                string sqlStmt = "update " + DBOperation.formatTabName("BIMRL_ELEMENT", fedID) + " set TRANSFORM_COL1=:1, TRANSFORM_COL2=:2, TRANSFORM_COL3=:3, TRANSFORM_COL4=:4"
                                 + " Where elementid = '" + elemListItem.Value + "'";
                // int status = DBOperation.updateGeometry(sqlStmt, sdoGeomData);
                currStep            = sqlStmt;
                command.CommandText = sqlStmt;

                try
                {
                    OracleParameter[] sdoGeom = new OracleParameter[4];
                    for (int i = 0; i < sdoGeom.Count(); ++i)
                    {
                        sdoGeom[i]             = command.Parameters.Add((i + 1).ToString(), OracleDbType.Object);
                        sdoGeom[i].Direction   = ParameterDirection.Input;
                        sdoGeom[i].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                        sdoGeom[i].Size        = 1;
                    }

                    SdoGeometry trcol1 = new SdoGeometry();
                    trcol1.Dimensionality = 3;
                    trcol1.LRS            = 0;
                    trcol1.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    int      gType   = trcol1.PropertiesToGTYPE();
                    SdoPoint trcol1V = new SdoPoint();
                    trcol1V.XD       = m3D.M11;
                    trcol1V.YD       = m3D.M12;
                    trcol1V.ZD       = m3D.M13;
                    trcol1.SdoPoint  = trcol1V;
                    sdoGeom[1].Value = trcol1;

                    SdoGeometry trcol2 = new SdoGeometry();
                    trcol2.Dimensionality = 3;
                    trcol2.LRS            = 0;
                    trcol2.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    gType = trcol2.PropertiesToGTYPE();
                    SdoPoint trcol2V = new SdoPoint();
                    trcol2V.XD       = m3D.M21;
                    trcol2V.YD       = m3D.M22;
                    trcol2V.ZD       = m3D.M23;
                    trcol2.SdoPoint  = trcol2V;
                    sdoGeom[2].Value = trcol2;

                    SdoGeometry trcol3 = new SdoGeometry();
                    trcol3.Dimensionality = 3;
                    trcol3.LRS            = 0;
                    trcol3.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    gType = trcol3.PropertiesToGTYPE();
                    SdoPoint trcol3V = new SdoPoint();
                    trcol3V.XD       = m3D.M31;
                    trcol3V.YD       = m3D.M32;
                    trcol3V.ZD       = m3D.M33;
                    trcol3.SdoPoint  = trcol3V;
                    sdoGeom[3].Value = trcol3;

                    SdoGeometry trcol4 = new SdoGeometry();
                    trcol4.Dimensionality = 3;
                    trcol4.LRS            = 0;
                    trcol4.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    gType = trcol4.PropertiesToGTYPE();
                    SdoPoint trcol4V = new SdoPoint();
                    trcol4V.XD       = m3D.OffsetX;
                    trcol4V.YD       = m3D.OffsetY;
                    trcol4V.ZD       = m3D.OffsetZ;
                    trcol4.SdoPoint  = trcol4V;
                    sdoGeom[4].Value = trcol4;

                    commandStatus = command.ExecuteNonQuery();
                    command.Parameters.Clear();

                    currInsertCount++;

                    if (currInsertCount % DBOperation.commitInterval == 0)
                    {
                        //Do commit at interval but keep the long transaction (reopen)
                        DBOperation.commitTransaction();
                    }
                }
                catch (OracleException e)
                {
                    string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                    _refBIMRLCommon.StackPushError(excStr);
                    //command.Dispose();   // Log Oracle error and continue
                    command = new OracleCommand(" ", DBOperation.DBConn);
                    // throw;
                }
                catch (SystemException e)
                {
                    string excStr = "%%Insert Error - " + e.Message + "\n\t" + currStep;
                    _refBIMRLCommon.StackPushError(excStr);
                    throw;
                }

                DBOperation.commitTransaction();
                command.Dispose();
            }
        }
 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);
 }
Exemplo n.º 39
0
        public static FedIDStatus getFederatedModel(string modelName, string projName, string projNumber, out FederatedModelInfo fedModel)
        {
            fedModel = new FederatedModelInfo();
            FedIDStatus stat     = FedIDStatus.FedIDExisting;
            string      currStep = "Getting federated ID";

            // Create separate connection with a short duration

            string           SqlStmt = "Select FEDERATEDID federatedID, ModelName, ProjectNumber, ProjectName, WORLDBBOX, MAXOCTREELEVEL, LastUpdateDate, Owner, DBConnection from BIMRL_FEDERATEDMODEL where MODELNAME = '" + modelName + "' and PROJECTNAME = '" + projName + "' and PROJECTNUMBER = '" + projNumber + "'";
            OracleCommand    command = new OracleCommand(SqlStmt, DBConn);
            OracleDataReader reader  = command.ExecuteReader();

            try
            {
                if (!reader.Read())
                {
                    reader.Close();
                    // Create a new record
                    command.CommandText = "Insert into BIMRL_FEDERATEDMODEL (MODELNAME, PROJECTNAME, PROJECTNUMBER) values ('" + modelName + "', '" + projName + "', '" + projNumber + "')";
                    DBOperation.beginTransaction();
                    command.ExecuteNonQuery();
                    DBOperation.commitTransaction();
                    stat = FedIDStatus.FedIDNew;
                }

                command.CommandText = SqlStmt;
                reader = command.ExecuteReader();
                reader.Read();

                fedModel.FederatedID   = reader.GetInt32(0);
                fedModel.ModelName     = reader.GetString(1);
                fedModel.ProjectNumber = reader.GetString(2);
                fedModel.ProjectName   = reader.GetString(3);
                if (!reader.IsDBNull(4))
                {
                    SdoGeometry worldBB = reader.GetValue(4) as SdoGeometry;
                    Point3D     LLB     = new Point3D(worldBB.OrdinatesArrayOfDoubles[0], worldBB.OrdinatesArrayOfDoubles[1], worldBB.OrdinatesArrayOfDoubles[2]);
                    Point3D     URT     = new Point3D(worldBB.OrdinatesArrayOfDoubles[3], worldBB.OrdinatesArrayOfDoubles[4], worldBB.OrdinatesArrayOfDoubles[5]);
                    fedModel.WorldBoundingBox = LLB.ToString() + " " + URT.ToString();
                }
                if (!reader.IsDBNull(5))
                {
                    fedModel.OctreeMaxDepth = reader.GetInt16(5);
                }
                if (!reader.IsDBNull(6))
                {
                    fedModel.LastUpdateDate = reader.GetDateTime(6);
                }
                if (!reader.IsDBNull(7))
                {
                    fedModel.Owner = reader.GetString(7);
                }
                if (!reader.IsDBNull(8))
                {
                    fedModel.DBConnection = reader.GetString(8);
                }

                reader.Close();
            }
            catch (OracleException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                refBIMRLCommon.StackPushError(excStr);
                command.Dispose();
                throw;
            }
            command.Dispose();

            return(stat);
        }
Exemplo n.º 40
0
        public List <FederatedModelInfo> getFederatedModels()
        {
            List <FederatedModelInfo> fedModels = new List <FederatedModelInfo>();

            DBOperation.beginTransaction();
            string      currStep = string.Empty;
            SdoGeometry worldBB  = new SdoGeometry();

            try
            {
                string           sqlStmt = "select federatedID, ModelName, ProjectNumber, ProjectName, WORLDBBOX, MAXOCTREELEVEL, LastUpdateDate, Owner, DBConnection from BIMRL_FEDERATEDMODEL order by federatedID";
                OracleCommand    command = new OracleCommand(sqlStmt, DBOperation.DBConn);
                OracleDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    FederatedModelInfo fedModel = new FederatedModelInfo();
                    fedModel.FederatedID   = reader.GetInt32(0);
                    fedModel.ModelName     = reader.GetString(1);
                    fedModel.ProjectNumber = reader.GetString(2);
                    fedModel.ProjectName   = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                    {
                        worldBB = reader.GetValue(4) as SdoGeometry;
                        Point3D LLB = new Point3D(worldBB.OrdinatesArrayOfDoubles[0], worldBB.OrdinatesArrayOfDoubles[1], worldBB.OrdinatesArrayOfDoubles[2]);
                        Point3D URT = new Point3D(worldBB.OrdinatesArrayOfDoubles[3], worldBB.OrdinatesArrayOfDoubles[4], worldBB.OrdinatesArrayOfDoubles[5]);
                        fedModel.WorldBoundingBox = LLB.ToString() + " " + URT.ToString();
                    }
                    if (!reader.IsDBNull(5))
                    {
                        fedModel.OctreeMaxDepth = reader.GetInt16(5);
                    }
                    if (!reader.IsDBNull(6))
                    {
                        fedModel.LastUpdateDate = reader.GetDateTime(6);
                    }
                    if (!reader.IsDBNull(7))
                    {
                        fedModel.Owner = reader.GetString(7);
                    }
                    if (!reader.IsDBNull(8))
                    {
                        fedModel.DBConnection = reader.GetString(8);
                    }

                    fedModels.Add(fedModel);
                }
                reader.Close();
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                throw;
            }

            return(fedModels);
        }
Exemplo n.º 41
0
        public void createSpatialIndexFromBIMRLElement(int federatedId, string whereCond, bool createFaces = true, bool createSpIdx = true)
        {
            DBOperation.beginTransaction();
            string           currStep = string.Empty;
            OracleCommand    command  = new OracleCommand(" ", DBOperation.DBConn);
            OracleDataReader reader;
            bool             selectedRegen = false;

            Point3D llb;
            Point3D urt;

            DBOperation.getWorldBB(federatedId, out llb, out urt);
            Octree.WorldBB  = new BoundingBox3D(llb, urt);
            Octree.MaxDepth = DBOperation.OctreeSubdivLevel;

            try
            {
                command.CommandText = "SELECT COUNT(*) FROM " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                object rC            = command.ExecuteScalar();
                int    totalRowCount = Convert.ToInt32(rC.ToString()) * (int)Math.Pow(8, 2);

                string sqlStmt = "select elementid, elementtype, geometrybody from " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                if (!string.IsNullOrEmpty(whereCond))
                {
                    sqlStmt      += " and " + whereCond;
                    selectedRegen = true;
                }
                currStep = sqlStmt;

                command.CommandText = sqlStmt;
                command.FetchSize   = 20;

                // The following is needed to update the element table with Bbox information
                string sqlStmt3 = "UPDATE " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " SET GeometryBody_BBOX = :bbox, "
                                  + "GeometryBody_BBOX_CENTROID = :cent WHERE ELEMENTID = :eid";
                OracleCommand commandUpdBbox = new OracleCommand(" ", DBOperation.DBConn);
                commandUpdBbox.CommandText = sqlStmt3;
                commandUpdBbox.Parameters.Clear();

                OracleParameter[] Bbox = new OracleParameter[3];
                Bbox[0]             = commandUpdBbox.Parameters.Add("bbox", OracleDbType.Object);
                Bbox[0].Direction   = ParameterDirection.Input;
                Bbox[0].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                List <List <SdoGeometry> > bboxListList = new List <List <SdoGeometry> >();
                List <SdoGeometry>         bboxList     = new List <SdoGeometry>();

                Bbox[1]             = commandUpdBbox.Parameters.Add("cent", OracleDbType.Object);
                Bbox[1].Direction   = ParameterDirection.Input;
                Bbox[1].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                List <List <SdoGeometry> > centListList = new List <List <SdoGeometry> >();
                List <SdoGeometry>         centList     = new List <SdoGeometry>();

                Bbox[2]           = commandUpdBbox.Parameters.Add("eid", OracleDbType.Varchar2);
                Bbox[2].Direction = ParameterDirection.Input;
                List <List <string> > eidUpdListList = new List <List <string> >();
                List <string>         eidUpdList     = new List <string>();
                int sublistCnt = 0;

                // end for Bbox

                Octree octreeInstance = null;
                if (selectedRegen)
                {
                    octreeInstance = new Octree(federatedId, totalRowCount, DBOperation.OctreeSubdivLevel);
                }
                else
                {
                    octreeInstance = new Octree(federatedId, totalRowCount, DBOperation.OctreeSubdivLevel, false, true);      // Since it is not selectedRegen, we will rebuild the entire tree, skip Dict regen for this case
                }
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string elemID  = reader.GetString(0);
                    string elemTyp = reader.GetString(1);

                    SdoGeometry sdoGeomData = reader.GetValue(2) as SdoGeometry;

                    Polyhedron geom;
                    if (!SDOGeomUtils.generate_Polyhedron(sdoGeomData, out geom))
                    {
                        continue;                                       // if there is something not right, skip the geometry
                    }
                    // - Update geometry info with BBox information
                    SdoGeometry bbox = new SdoGeometry();
                    bbox.Dimensionality = 3;
                    bbox.LRS            = 0;
                    bbox.GeometryType   = (int)SdoGeometryTypes.GTYPE.POLYGON;
                    int gType = bbox.PropertiesToGTYPE();

                    double[] arrCoord    = new double[6];
                    int[]    elemInfoArr = { 1, (int)SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_EXTERIOR, 1 };
                    arrCoord[0] = geom.boundingBox.LLB.X;
                    arrCoord[1] = geom.boundingBox.LLB.Y;
                    arrCoord[2] = geom.boundingBox.LLB.Z;
                    arrCoord[3] = geom.boundingBox.URT.X;
                    arrCoord[4] = geom.boundingBox.URT.Y;
                    arrCoord[5] = geom.boundingBox.URT.Z;

                    bbox.ElemArrayOfInts         = elemInfoArr;
                    bbox.OrdinatesArrayOfDoubles = arrCoord;
                    bboxList.Add(bbox);

                    SdoGeometry centroid = new SdoGeometry();
                    centroid.Dimensionality = 3;
                    centroid.LRS            = 0;
                    centroid.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    gType = centroid.PropertiesToGTYPE();
                    SdoPoint cent = new SdoPoint();
                    cent.XD           = geom.boundingBox.Center.X;
                    cent.YD           = geom.boundingBox.Center.Y;
                    cent.ZD           = geom.boundingBox.Center.Z;
                    centroid.SdoPoint = cent;
                    centList.Add(centroid);

                    eidUpdList.Add(elemID);

                    sublistCnt++;

                    // Set 1000 records as a threshold for interval commit later on
                    if (sublistCnt >= 500)
                    {
                        bboxListList.Add(bboxList);
                        centListList.Add(centList);
                        eidUpdListList.Add(eidUpdList);

                        sublistCnt = 0;
                        bboxList   = new List <SdoGeometry>();
                        centList   = new List <SdoGeometry>();
                        eidUpdList = new List <string>();
                    }

                    // We will skip large buildinglementproxy that has more than 5000 vertices
                    bool largeMesh = (string.Compare(elemTyp, "IFCBUILDINGELEMENTPROXY", true) == 0) && geom.Vertices.Count > 5000;
                    if ((createFaces && !largeMesh) || (createFaces && selectedRegen))
                    {
                        // - Process face information and create consolidated faces and store them into BIMRL_TOPO_FACE table
                        BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elemID, geom, _refBIMRLCommon, federatedId, null);
                        processFaces.simplifyAndMergeFaces();
                        processFaces.insertIntoDB(false);
                    }

                    if (createSpIdx)
                    {
                        octreeInstance.ComputeOctree(elemID, geom);
                    }
                }

                reader.Dispose();


                if (createSpIdx)
                {
                    // Truncate the table first before reinserting the records
                    FederatedModelInfo fedModel = DBOperation.getFederatedModelByID(federatedId);
                    if (DBOperation.DBUserID.Equals(fedModel.FederatedID))
                    {
                        DBOperation.executeSingleStmt("TRUNCATE TABLE " + DBOperation.formatTabName("BIMRL_SPATIALINDEX", federatedId));
                    }
                    else
                    {
                        DBOperation.executeSingleStmt("DELETE FROM " + DBOperation.formatTabName("BIMRL_SPATIALINDEX"));
                    }

                    collectSpatialIndexAndInsert(octreeInstance, federatedId);
                }

                if (sublistCnt > 0)
                {
                    bboxListList.Add(bboxList);
                    centListList.Add(centList);
                    eidUpdListList.Add(eidUpdList);
                }

                for (int i = 0; i < eidUpdListList.Count; i++)
                {
                    Bbox[0].Value = bboxListList[i].ToArray();
                    Bbox[0].Size  = bboxListList[i].Count;
                    Bbox[1].Value = centListList[i].ToArray();
                    Bbox[1].Size  = centListList[i].Count;
                    Bbox[2].Value = eidUpdListList[i].ToArray();
                    Bbox[2].Size  = eidUpdListList[i].Count;

                    commandUpdBbox.ArrayBindCount = eidUpdListList[i].Count;    // No of values in the array to be inserted
                    int commandStatus = commandUpdBbox.ExecuteNonQuery();
                    DBOperation.commitTransaction();
                }

                if (!string.IsNullOrEmpty(whereCond) && createSpIdx)
                {
                    command.CommandText = "UPDATE BIMRL_FEDERATEDMODEL SET MAXOCTREELEVEL=" + Octree.MaxDepth.ToString() + " WHERE FEDERATEDID=" + federatedId.ToString();
                    command.ExecuteNonQuery();
                    DBOperation.commitTransaction();
                }
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                throw;
            }

            command.Dispose();
        }
 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 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 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 = (decimal)SdoGeometryTypes.GTYPE.LINE;
			sdoGeometry.Dimensionality = dim;
			sdoGeometry.LRS = lrsPos;
			sdoGeometry.Sdo_Srid = geometry.SRID;
			sdoGeometry.ElemArray = new decimal[] { 0, 1, (decimal)ElementType.LINE_STRAITH_SEGMENTS, 0 };
			sdoGeometry.OrdinatesArrayOfDoubles = ordinates;
			return sdoGeometry;
		}
 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());
 }
Exemplo n.º 46
0
        public static bool getWorldBB(int federatedId, out Point3D llb, out Point3D urt)
        {
            Tuple <Point3D, Point3D, int> bbinfo;

            // If the information is already in the dictionary, return the info
            if (worldBBInfo.TryGetValue(federatedId, out bbinfo))
            {
                llb             = bbinfo.Item1;
                urt             = bbinfo.Item2;
                Octree.WorldBB  = new BoundingBox3D(llb, urt);
                Octree.MaxDepth = bbinfo.Item3;
                return(true);
            }

            string        sqlStmt = "select WORLDBBOX, MAXOCTREELEVEL from BIMRL_FEDERATEDMODEL WHERE FEDERATEDID=" + federatedId.ToString();
            OracleCommand command = new OracleCommand(sqlStmt, DBOperation.DBConn);

            command.CommandText = sqlStmt;
            llb = null;
            urt = null;

            try
            {
                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    SdoGeometry sdoGeomData = reader.GetValue(0) as SdoGeometry;
                    int         maxDepth    = reader.GetInt32(1);

                    llb   = new Point3D();
                    llb.X = sdoGeomData.OrdinatesArrayOfDoubles[0];
                    llb.Y = sdoGeomData.OrdinatesArrayOfDoubles[1];
                    llb.Z = sdoGeomData.OrdinatesArrayOfDoubles[2];

                    urt   = new Point3D();
                    urt.X = sdoGeomData.OrdinatesArrayOfDoubles[3];
                    urt.Y = sdoGeomData.OrdinatesArrayOfDoubles[4];
                    urt.Z = sdoGeomData.OrdinatesArrayOfDoubles[5];

                    Octree.WorldBB  = new BoundingBox3D(llb, urt);
                    Octree.MaxDepth = maxDepth;

                    // Add the new info into the dictionary
                    worldBBInfo.Add(federatedId, new Tuple <Point3D, Point3D, int>(llb, urt, maxDepth));

                    return(true);
                }
                reader.Dispose();
                return(false);
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
                refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
                refBIMRLCommon.StackPushError(excStr);
                throw;
            }
            return(false);
        }
        private IPoint ReadPoint(SdoGeometry sdoGeom)
        {
            var ordinates = sdoGeom.OrdinatesArrayOfDoubles;
            if (ordinates.Length == 0)
            {
                if (sdoGeom.Dimensionality == 2)
                {
                    ordinates = new[] { sdoGeom.Point.XD.Value, sdoGeom.Point.YD.Value };
                }
                else
                {
                    ordinates = new[] { sdoGeom.Point.XD.Value, sdoGeom.Point.YD.Value, sdoGeom.Point.ZD.Value };
                }
            }
            ICoordinateSequence cs = ConvertOrdinateArray(ordinates, sdoGeom);
            IPoint point = factory.CreatePoint(cs);

            point.SRID = (int)sdoGeom.Sdo_Srid;
            return point;
        }
		private Double[] ExtractOrdinatesOfElement(int element, SdoGeometry sdoGeom, bool hasNextSE)
		{
			int start = (int)sdoGeom.ElemArray[element * 3];
			if ((element * 3) < sdoGeom.ElemArray.Length - 1)
			{
				int end = (int)sdoGeom.ElemArray[(element + 1) * 3];
				// if this is a subelement of a compound geometry,
				// the last point is the first point of
				// the next subelement.
				if (hasNextSE)
				{
					end += sdoGeom.Dimensionality;
				}
				return sdoGeom.getOrdinates().getOrdinatesArray(start, end);
			}
			else
			{
				return sdoGeom.getOrdinates().getOrdinatesArray(start);
			}
		}
 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;
 }
Exemplo n.º 50
0
        public static bool generate_Polyhedron(SdoGeometry geom, out Polyhedron pH)
        {
            List <double> pointCoordList = new List <double>();
            List <int>    coordIndexList = new List <int>();

            int[]    elInfo   = geom.ElemArrayOfInts;
            double[] ordArray = geom.OrdinatesArrayOfDoubles;

            if (ordArray.Length == 0)
            {
                // An empty data (should not come here, but in some cases it may happen when there is bad data)
                pH = null;
                return(false);
            }

            int        eInfoIdx       = 0; // Index on Element Info array
            int        vertIdx        = 0; // new Index for the index to the vertex coordinate lists
            Point3D    v              = new Point3D();
            Point3D    v1             = new Point3D();
            List <int> noFaceVertList = new List <int>();

            // First loop: loop for lump
            while (eInfoIdx < elInfo.Length)
            {
                // advance to the 6th array in the element info to get the number of faces
                eInfoIdx += 5;
                int noFace = elInfo[eInfoIdx];

                eInfoIdx += 1;      // Advance to the first face offset

                // second loop for the number of faces inside a lump
                for (int f = 0; f < noFace; f++)
                {
                    bool vert   = true;
                    int  vcount = 0;
                    int  fIdx   = elInfo[eInfoIdx];

                    while (vert)
                    {
                        if (vcount == 0)
                        {
                            v1.X = ordArray[fIdx - 1];     // -1 because the index starts at no 1
                            v1.Y = ordArray[fIdx];
                            v1.Z = ordArray[fIdx + 1];

                            pointCoordList.Add(v1.X);
                            pointCoordList.Add(v1.Y);
                            pointCoordList.Add(v1.Z);
                            coordIndexList.Add(vertIdx * 3);
                            vertIdx++;
                            vcount++;
                            fIdx += 3;
                            continue;
                        }
                        v.X = ordArray[fIdx - 1];
                        v.Y = ordArray[fIdx];
                        v.Z = ordArray[fIdx + 1];

                        if (Point3D.Equals(v, v1))
                        {
                            // We are at the end of the vertex list. Oracle SDO repeat the last point as the first point, we can skip this for X3D
                            vert      = false;
                            eInfoIdx += 3;
                            noFaceVertList.Add(vcount);     // List of no of vertices in each individual face
                            continue;
                        }

                        pointCoordList.Add(v.X);
                        pointCoordList.Add(v.Y);
                        pointCoordList.Add(v.Z);
                        coordIndexList.Add(vertIdx * 3);
                        fIdx += 3;
                        vertIdx++;
                        vcount++;
                    }
                }
            }

//            pH = new Polyhedron(PolyhedronFaceTypeEnum.TriangleFaces, true, pointCoordList, coordIndexList, null);
            pH = new Polyhedron(PolyhedronFaceTypeEnum.ArbitraryFaces, true, pointCoordList, coordIndexList, noFaceVertList);
            return(true);
        }
		public IGeometry Read(SdoGeometry geometry)
		{
			return ReadGeometry(geometry);
		}