How to use the @bentley/imodeljs-backend.SpatialCategory.insert function in @bentley/imodeljs-backend

To help you get started, we’ve selected a few @bentley/imodeljs-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / test-apps / agent-test-app / src / changeSetUtility / ChangesetGenerationHarness.ts View on Github external
private _createStandalone(): string {
        const pathname: string = path.join(this._localIModelDbPath, this._iModelName + ".bim");
        if (fs.existsSync(pathname))
            fs.unlinkSync(pathname);

        this._iModelDb = IModelDb.createStandalone(pathname, { rootSubject: { name: this._iModelName } });

        const definitionModelId: Id64String = IModel.dictionaryId;
        this._physicalModelId = PhysicalModel.insert(this._iModelDb, IModel.rootSubjectId, "TestModel");
        this._codeSpecId = this._iModelDb.codeSpecs.insert("TestCodeSpec", CodeScopeSpec.Type.Model);
        this._categoryId = SpatialCategory.insert(this._iModelDb, definitionModelId, "TestCategory", { color: new ColorDef("blanchedAlmond") });

        // Insert a ViewDefinition for the PhysicalModel
        const viewName = "Physical View";
        const modelSelectorId: Id64String = ModelSelector.insert(this._iModelDb, definitionModelId, viewName, [this._physicalModelId]);
        const categorySelectorId: Id64String = CategorySelector.insert(this._iModelDb, definitionModelId, viewName, [this._categoryId]);
        const displayStyleId: Id64String = DisplayStyle3d.insert(this._iModelDb, definitionModelId, viewName);
        const viewRange = new Range3d(0, 0, 0, 50, 50, 50);
        OrthographicViewDefinition.insert(this._iModelDb, definitionModelId, viewName, modelSelectorId, categorySelectorId, displayStyleId, viewRange);

        this._iModelDb.updateProjectExtents(new Range3d(-1000, -1000, -1000, 1000, 1000, 1000));
        this._iModelDb.saveChanges("Setup new iModel");
        this._iModelDb.closeStandalone();
        this._iModelDb = undefined;

        return pathname;
    }
github imodeljs / imodeljs / example-code / app / src / backend / RobotWorldSchema.ts View on Github external
public static bootStrapDefinitions(iModelDb: IModelDb) {
    // Insert some pre-defined categories
    if (true) {
      SpatialCategory.insert(iModelDb, IModelDb.dictionaryId, _schemaNames.Class.Robot, new SubCategoryAppearance({ color: ColorByName.silver }));
    }
    if (true) {
      SpatialCategory.insert(iModelDb, IModelDb.dictionaryId, _schemaNames.Class.Barrier, new SubCategoryAppearance({ color: ColorByName.brown }));
    }
  }
github imodeljs / imodeljs / example-code / app / src / backend / RobotWorldSchema.ts View on Github external
public static bootStrapDefinitions(iModelDb: IModelDb) {
    // Insert some pre-defined categories
    if (true) {
      SpatialCategory.insert(iModelDb, IModelDb.dictionaryId, _schemaNames.Class.Robot, new SubCategoryAppearance({ color: ColorByName.silver }));
    }
    if (true) {
      SpatialCategory.insert(iModelDb, IModelDb.dictionaryId, _schemaNames.Class.Barrier, new SubCategoryAppearance({ color: ColorByName.brown }));
    }
  }
github imodeljs / imodeljs / test-apps / imodel-from-geojson / src / GeoJsonImporter.ts View on Github external
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);
      this.iModelDb.updateProjectExtents(featureModelExtents);
github imodeljs / imodeljs / test-apps / imodel-from-geojson / src / GeoJsonImporter.ts View on Github external
private addCategoryToExistingDb(categoryName: string) {
    const categoryId = SpatialCategory.insert(this.iModelDb, IModel.dictionaryId, categoryName, { color: ColorDef.white });
    this.iModelDb.views.iterateViews({ from: "BisCore.SpatialViewDefinition" }, ((view: ViewDefinition) => {
      const categorySelector = this.iModelDb.elements.getElement(view.categorySelectorId);
      categorySelector.categories.push(categoryId);
      this.iModelDb.elements.updateElement(categorySelector);

      return true;
    }));

    return categoryId;
  }
  /** Iterate through and accumulate the GeoJSON FeatureCollection range. */
github imodeljs / imodeljs / test-apps / analysis-importer / src / AnalysisImporter.ts View on Github external
public import() {
    this.definitionModelId = DefinitionModel.insert(this.iModelDb, IModelDb.rootSubjectId, "Analysis Definitions");

    /** Create category for analytical polyfaces */
    const categoryId = SpatialCategory.insert(this.iModelDb, this.definitionModelId, "GeoJSON Feature", { color: ColorDef.white });

    /** import a polyface representing a cantilever beam with stress and displacement data. */
    const importedPolyface = this.importPolyfaceFromJson("Cantilever.json");
    /** create a model containing the imported data (with display styles, views etc.) */
    const cantileverViewId = this.createAnalysisModel(importedPolyface, categoryId, "Cantilever", 100.0);
    this.iModelDb.views.setDefaultViewId(cantileverViewId);

    /** demonstrate creation of a polyface with analytical data by creating a flat mesh and then superimposing "wave" data */
    const flatWaveMesh = this.createFlatMeshWithWaves();
    /** create a model containing the wave data (with display styles, views etc.) */
    this.createAnalysisModel(flatWaveMesh, categoryId, "Waves");

    this.iModelDb.saveChanges();
  }
}