public SdoGeometry()
 {
     _sdoGTypeIsNull = true;
     _sdoSridIsNull  = true;
     _sdoElemInfo    = SdoElemInfo.Null;
     _sdoOrdinate    = SdoOrdinates.Null;
     _sdoPoint       = SdoPoint.Null;
 }
 public SdoGeometry(
     int gType,
     int srid,
     SdoPoint point,
     SdoElemInfo elemInfo,
     SdoOrdinates ordinate)
 {
     SdoGType     = gType;
     SdoSrid      = srid;
     SdoPoint     = (SdoPoint)point.Clone();
     SdoElemInfo  = (SdoElemInfo)elemInfo.Clone();
     SdoOrdinates = (SdoOrdinates)ordinate.Clone();
 }
Beispiel #3
0
    public void ToCustomObject(OracleConnection con, object pUdt)
    {
        // If the UDT may contain NULL attribute data, enable the following code
        //if (!OracleUdt.IsDBNull(con, pUdt, 0))
        _gtype = (int)OracleUdt.GetValue(con, pUdt, 0);

        // If the UDT may contain NULL attribute data, enable the following code
        //if (!OracleUdt.IsDBNull(con, pUdt, 0))
        _srid        = (int)OracleUdt.GetValue(con, pUdt, 1);
        _point       = (SdoPoint)OracleUdt.GetValue(con, pUdt, 2);
        _elementInfo = (int[])OracleUdt.GetValue(con, pUdt, 3);
        _ordinates   = (double[])OracleUdt.GetValue(con, pUdt, 4);
    }
Beispiel #4
0
 public static Point3D sdopointToPoint3D(SdoPoint sdoP)
 {
     return(new Point3D(sdoP.XD.Value, sdoP.YD.Value, sdoP.ZD.Value));
 }
Beispiel #5
0
    // IOracleCustomTypeFactory Inteface
    public IOracleCustomType CreateObject()
    {
        SdoPoint sdoPoint = new SdoPoint();

        return(sdoPoint);
    }
Beispiel #6
0
        private IGeometry Create(int gType, SdoPoint point, decimal[] elemInfo, decimal[] ordinates)
        {
            var lrs = (gType % 1000) / 100;

            // find the dimension: represented by the smaller of the two dimensions
            int dim;

            if (_dimension != NULL_DIMENSION)
            {
                dim = _dimension;
            }
            else
            {
                dim = Math.Min(gType / 1000, 3);
            }

            if (dim == 0)
            {
                return(null);
            }

            if (dim < 2)
            {
                throw new ArgumentException("Dimension D:" + dim + " is not valid for JTS. " +
                                            "Either specify a dimension or use Oracle Locator Version 9i or later");
            }

            // extract the geometry template type
            // this is represented as the rightmost two digits
            var geomTemplate = gType - (dim * 1000) - (lrs * 100);

            //CoordinateSequence coords = null;
            List <Coordinate> coords;

            if (lrs == 0 && geomTemplate == 1 && point != null && elemInfo == null)
            {
                // Single Coordinate Type Optimization
                Debug.Assert(point.X != null, "point.X != null");
                Debug.Assert(point.Y != null, "point.Y != null");
                //if (dim == 2)
                //{
                coords = Coordinates(dim, lrs, geomTemplate, new[] { point.X.Value, point.Y.Value });
                //}
                //else
                //{
                //    Debug.Assert(point.Z != null, "point.Z != null");
                //    coords = Coordinates(dim, lrs, geomTemplate,
                //                         new[] { point.X.Value, point.Y.Value, point.Z.Value });
                //}
                elemInfo = new decimal[] { 1, (Int32)SdoEType.Coordinate, 1 };
            }
            else
            {
                coords = Coordinates(dim, lrs, geomTemplate, ordinates);
            }

            switch ((SdoGTemplate)geomTemplate)
            {
            case SdoGTemplate.Coordinate:
                return(CreatePoint(dim, lrs, elemInfo, 0, coords));

            case SdoGTemplate.Line:
                return(CreateLine(dim, lrs, elemInfo, 0, coords));

            case SdoGTemplate.Polygon:
                return(CreatePolygon(dim, lrs, elemInfo, 0, coords));

            case SdoGTemplate.MultiPoint:
                return(CreateMultiPoint(dim, lrs, elemInfo, 0, coords));

            case SdoGTemplate.MultiLine:
                return(CreateMultiLine(dim, lrs, elemInfo, 0, coords, -1));

            case SdoGTemplate.MultiPolygon:
                return(CreateMultiPolygon(dim, lrs, elemInfo, 0, coords, -1));

            case SdoGTemplate.Collection:
                return(CreateCollection(dim, lrs, elemInfo, 0, coords, -1));

            default:
                return(null);
            }
        }
Beispiel #7
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 IGeometry Create(int gType, SdoPoint point, Decimal[] elemInfo, Decimal[] ordinates)
        {
            int lrs = (gType%1000)/100;

            // find the dimension: represented by the smaller of the two dimensions
            int dim;
            if (_dimension != NullDimension)
            {
                dim = _dimension;
            }
            else
            {
                dim = Math.Min(gType/1000, 3);
            }

            if (dim == 0)
                return null;

            if (dim < 2)
            {
                throw new ArgumentException("Dimension D:" + dim + " is not valid for JTS. " +
                                            "Either specify a dimension or use Oracle Locator Version 9i or later");
            }

            // extract the geometry template type
            // this is represented as the rightmost two digits
            int geomTemplate = gType - (dim*1000) - (lrs*100);

            //CoordinateSequence coords = null;
            List<Coordinate> coords;

            if (lrs == 0 && geomTemplate == 1 && point != null && elemInfo == null)
            {
                // Single Coordinate Type Optimization
                Debug.Assert(point.X != null, "point.X != null");
                Debug.Assert(point.Y != null, "point.Y != null");
                if (dim == 2)
                {
                    coords = Coordinates(dim, lrs, geomTemplate, new[] { point.X.Value, point.Y.Value });
                }
                else
                {
                    Debug.Assert(point.Z != null, "point.Z != null");
                    coords = Coordinates(dim, lrs, geomTemplate,
                                         new[] {point.X.Value, point.Y.Value, point.Z.Value});
                }
                elemInfo = new Decimal[] {1, (Int32) SdoEType.Coordinate, 1};
            }
            else
            {
                coords = Coordinates(dim, lrs, geomTemplate, ordinates);
            }

            switch ((SdoGTemplate) geomTemplate)
            {
                case SdoGTemplate.Coordinate:
                    return CreatePoint(dim, lrs, elemInfo, 0, coords);

                case SdoGTemplate.Line:
                    return CreateLine(dim, lrs, elemInfo, 0, coords);

                case SdoGTemplate.Polygon:
                    return CreatePolygon(dim, lrs, elemInfo, 0, coords);

                case SdoGTemplate.MultiPoint:
                    return CreateMultiPoint(dim, lrs, elemInfo, 0, coords);

                case SdoGTemplate.MultiLine:
                    return CreateMultiLine(dim, lrs, elemInfo, 0, coords, -1);

                case SdoGTemplate.MultiPolygon:
                    return CreateMultiPolygon(dim, lrs, elemInfo, 0, coords, -1);

                case SdoGTemplate.Collection:
                    return CreateCollection(dim, lrs, elemInfo, 0, coords, -1);

                default:
                    return null;
            }
        }
Beispiel #9
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();
            }
        }