Create Centroids

Land Desktop Map 3D Samples

 
Create Centroids
 
 
 

This method takes four arguments: an MgResourceIdentifier object identifying the feature source, a schema name, a class name, and the name of an ObjectData table. It returns a collection of DatabaseServices.ObjectId objects that identify the centroids added to the database. It does the following:

  1. Use an MgFeatureService object, the MgResourceIdentifier object, the schema name and the class name to select all of the features in the signals.sdf file and put them in an MgFeatureReader object.
  2. Use the MgFeatureReader object to get the MgClassDefinition object and from the latter the default geometry property name.
  3. Creates a layer called “Centroids” in the current project’s Autodesk.AutoCAD.DatabaseServices.LayerTable object. This is described in the topic Create A Layer Using Autodesk.AutoCAD.DatabaseServices.
  4. Uses the layer name to get a reference to the ObjectData.Table object created in the preceding step.
  5. Creates a DatabaseServices.ObjectIdCollection object. This will hold the ObjectId objects of all of the centroids created and stored in the database. This ObjectIdCollection object is returned to the caller.
  6. Uses the geometry property name and the current feature in the MgFeatureReader object to get an MgByteReader containing the feature geometry.
  7. Uses an MgAgfReaderWriter object to convert the MgByteReader object into an MgGeometry object.
  8. Extracts the x and y coordinates for the feature’s centroid from the MgGeomtry object.
    NoteInformally a centroid is the “average” of all points in the geometry. See http://en.wikipedia.org/wiki/Centroid .
  9. Uses centroid coordinates and an Autodesk.AutoCAD.Geometry.Point3d object to create an Autodesk.AutoCAD.DatabaseServices.DBPoint object. The base class of DBPoint is DatabaseServices.Entity.
  10. Uses the Autodesk.AutoCAD.DatabaseServices.Transaction object and the ProjectModel object to get the current project’s Autodesk.AutoCAD.DatabaseServices.BlockTableRecord object, which contains the Model Space entities.
  11. Sets the DBPoint object’s Layer property to be the layer name.
  12. Appends the DBPoint object to the BlockTableRecord object. This operation returns an Autodesk.AutoCAD.DatabaseServices.ObjectId object, which is added to the DatabaseServices.ObjectIdCollection object which will be returned by this method.
  13. Uses the Transaction object to add the DBPoint object to the Autodesk.AutoCAD.DatabaseServices.Database object.
  14. Creates an ObjectData.Record object and uses the ObjectData.Table object to initialize it.
  15. Creates a Utilities.MapValue object for each of the feature’s data properties and adds the MapValue object to the ObjectData.Record object.
  16. Adds the ObjectData.Record object and the Autodesk.AutoCAD.DatabaseServices.ObjectId object, which identifies the DBPoint object in the BlockTableRecord object, to the ObjectData.Table object.