Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createAnalysisModel(polyface: any, categoryId: Id64String, modelName: string, displacementScale = 1.0): Id64String {
const modelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, modelName);
/** generate a geometry stream containing the polyface */
const geometry = this.generateGeometryStreamFromPolyface(polyface);
/** generate DisplayStyles to view the PolyfaceAuxData. The display styles contain channel selection and gradient specification for the [[PolyfaceAuxData]]
*/
const analysisStyleProps = this.getPolyfaceAnalysisStyleProps(polyface, displacementScale);
const vf = new ViewFlags();
const bgColor = ColorDef.white; // White background...
vf.renderMode = RenderMode.SolidFill; // SolidFill rendering ... no lighting etc.
/** The [[GeometricElement3dProps]] */
const props: GeometricElement3dProps = {
model: modelId,
code: Code.createEmpty(),
classFullName: "Generic:PhysicalObject",
public async create(): Promise {
this.definitionModelId = DefinitionModel.insert(this.iModelDb, IModelDb.rootSubjectId, "Definitions");
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, "Empty Model");
let geoLocated = false;
const worldRange = new Range3d();
const realityModels: ContextRealityModelProps[] = [];
requestPromise(this.url, { json: true }).then((json: any) => {
if (this.url.endsWith("_AppData.json")) {
const nameIndex = this.url.lastIndexOf("TileSets");
const prefix = this.url.substr(0, nameIndex);
let worldToEcef: Transform | undefined;
for (const modelValue of Object.values(json.models)) {
const model = modelValue as any;
if (model.tilesetUrl !== undefined &&
model.type === "spatial") {
let modelUrl = prefix + model.tilesetUrl.replace(/\/\//g, "/");
modelUrl = modelUrl.replace(/ /g, "%20");
const ecefRange = Range3d.fromJSON(model.extents);
public async import(): Promise {
const categoryName = this._modelName ? this._modelName : "GeoJson Category";
const modelName = this._modelName ? this._modelName : "GeoJson Model";
let featureModelExtents: AxisAlignedBox3d;
if (this._appendToExisting) {
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, modelName);
const foundCategoryId = SpatialCategory.queryCategoryIdByName(this.iModelDb, IModel.dictionaryId, categoryName);
this.featureCategoryId = (foundCategoryId !== undefined) ? foundCategoryId : this.addCategoryToExistingDb(categoryName);
this.convertFeatureCollection();
const featureModel: SpatialModel = this.iModelDb.models.getModel(this.physicalModelId) as SpatialModel;
featureModelExtents = featureModel.queryExtents();
const projectExtents = Range3d.createFrom(this.iModelDb.projectExtents);
projectExtents.extendRange(featureModelExtents);
this.iModelDb.updateProjectExtents(projectExtents);
} else {
this.definitionModelId = DefinitionModel.insert(this.iModelDb, IModelDb.rootSubjectId, "GeoJSON Definitions");
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, modelName);
this.featureCategoryId = SpatialCategory.insert(this.iModelDb, this.definitionModelId, categoryName, { color: ColorDef.white });
/** To geo-locate the project, we need to first scan the GeoJSon and extract range. This would not be required
* if the bounding box was directly available.
*/
const featureMin = new Cartographic(), featureMax = new Cartographic();
public async create(): Promise {
this.definitionModelId = DefinitionModel.insert(this.iModelDb, IModelDb.rootSubjectId, "Definitions");
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, "Empty Model");
let geoLocated = false;
const worldRange = new Range3d();
const realityModels: ContextRealityModelProps[] = [];
requestPromise(this.url, { json: true }).then((json: any) => {
if (this.url.endsWith("_AppData.json")) {
const nameIndex = this.url.lastIndexOf("TileSets");
const prefix = this.url.substr(0, nameIndex);
let worldToEcef: Transform | undefined;
for (const modelValue of Object.values(json.models)) {
const model = modelValue as any;
if (model.tilesetUrl !== undefined &&
model.type === "spatial") {
let modelUrl = prefix + model.tilesetUrl.replace(/\/\//g, "/");
modelUrl = modelUrl.replace(/ /g, "%20");
const modelName = this._modelName ? this._modelName : "GeoJson Model";
let featureModelExtents: AxisAlignedBox3d;
if (this._appendToExisting) {
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, modelName);
const foundCategoryId = SpatialCategory.queryCategoryIdByName(this.iModelDb, IModel.dictionaryId, categoryName);
this.featureCategoryId = (foundCategoryId !== undefined) ? foundCategoryId : this.addCategoryToExistingDb(categoryName);
this.convertFeatureCollection();
const featureModel: SpatialModel = this.iModelDb.models.getModel(this.physicalModelId) as SpatialModel;
featureModelExtents = featureModel.queryExtents();
const projectExtents = Range3d.createFrom(this.iModelDb.projectExtents);
projectExtents.extendRange(featureModelExtents);
this.iModelDb.updateProjectExtents(projectExtents);
} else {
this.definitionModelId = DefinitionModel.insert(this.iModelDb, IModelDb.rootSubjectId, "GeoJSON Definitions");
this.physicalModelId = PhysicalModel.insert(this.iModelDb, IModelDb.rootSubjectId, modelName);
this.featureCategoryId = SpatialCategory.insert(this.iModelDb, this.definitionModelId, categoryName, { color: ColorDef.white });
/** To geo-locate the project, we need to first scan the GeoJSon and extract range. This would not be required
* if the bounding box was directly available.
*/
const featureMin = new Cartographic(), featureMax = new Cartographic();
if (!this.getFeatureRange(featureMin, featureMax))
return;
const featureCenter = new Cartographic((featureMin.longitude + featureMax.longitude) / 2, (featureMin.latitude + featureMax.latitude) / 2);
this.iModelDb.setEcefLocation(EcefLocation.createFromCartographicOrigin(featureCenter));
this.convertFeatureCollection();
const featureModel: SpatialModel = this.iModelDb.models.getModel(this.physicalModelId) as SpatialModel;
featureModelExtents = featureModel.queryExtents();
if (!this._classifiedURL)
this.insertSpatialView("Spatial View", featureModelExtents);