How to set spatial reference to a schematic diagram class with Arcobjects?

5044
10
Jump to solution
01-27-2015 02:35 AM
KevinLECOCQ
New Contributor III

I used ArcObjects for .NET to create a schematic dataset, then a schematic diagram class (aka "schematic template" in the UI) wherein I load feature classes.

To do that, I followed the sample: "Create A Standard Builder Schematic Diagram Class From Scratch".

But when I generate diagrams, I get from ArcMap a "missing spatial reference" warning.

So how to set the spatial reference?

In ArcMap, it's possible in the properties of the schematic template. But using ArcObjects, I can't find an interface of the class SchematicDiagramClass to set the ISpatialReference.

I would appreciate any help on that.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor
0 Kudos
10 Replies
nicogis
MVP Frequent Contributor

SchematicDiagramClass implements IGeoDataset ArcObjects Help for .NET developers  that has SpatialReference ArcObjects Help for .NET developers

0 Kudos
KevinLECOCQ
New Contributor III

Yes, but the spatial reference property of IGeoDataset is read-only: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0025000003n0000000

There is only a "get" to the spatial reference object.

0 Kudos
nicogis
MVP Frequent Contributor

see IGeoDatasetSchemaEdit ArcObjects Help for .NET developers

0 Kudos
KevinLECOCQ
New Contributor III

It works casting the ISchematicDiagramClass object to this IGeoDatasetSchemaEdit, then using AlterSpatialReference, thanks.

Now I still have a 'missing spatial reference' error adding a diagram to a map, because the schematic element classes still don't have spatial reference. I create these object as ISchematicElementClass. What interface could I use to set their spatial reference?

0 Kudos
nicogis
MVP Frequent Contributor

You can get SchematicDataset and then alter spatial reference

0 Kudos
KevinLECOCQ
New Contributor III

OK, I got the ISchematicDataset object and am looking for an interface like IGeoDatasetSchemaEdit to change the spatial reference. The available interfaces are in this list: ArcObjects 10 .NET SDK Help

IGeoDatasetSchemaEdit isn't available for this object because I get a cast error.

Which interface could I use ?

0 Kudos
nicogis
MVP Frequent Contributor

Can you post part of source code ?

0 Kudos
KevinLECOCQ
New Contributor III

I can't cast the SchematicDataset to IGeoDatasetSchemaEdit because I get an InvalidCastException. Here is my code:

I create a schematicWorkspace from a IWorkspace like this:

[...]

ISchematicWorkspaceFactory schematicWorkspaceFactory = new SchematicWorkspaceFactoryClass();
ISchematicWorkspace schematicWorkspace = schematicWorkspaceFactory.Open(workspace);

Then, I create the schematic dataset:

schematicDataset = schematicWorkspace.CreateSchematicDataset(SCHEMATIC_DATASET_NAME);
schematicDataset.DesignMode = true;
Type objectType = Type.GetTypeFromProgID("esriSchematic.SchematicStandardBuilder");
ISchematicStandardBuilder schematicStandardBuilder = Activator.CreateInstance(objectType) as ISchematicStandardBuilder;
schematicStandardBuilder.AddConnectedNodes = true;
schematicStandardBuilder.InitializeLinksVertices = true;
schematicStandardBuilder.AutoCreateElementClasses = true;

schematicDiagramClass = schematicDataset.CreateSchematicDiagramClass(SCHEMATIC_DIAGRAM_CLASS_NAME);
schematicDiagramClass.SchematicBuilder = schematicStandardBuilder as ISchematicBuilder;
schematicDiagramClass.SchematicDataSource = schematicDataset.DefaultSchematicDataSource;
schematicDiagramClass.ExternalQueryEvaluationMode = esriSchematicExternalQueryEvaluationMode.esriSchematicNoQuery;
schematicDiagramClass.AlwaysLoadDiagrams = true;

Then, I define the spatial reference:

ISpatialReference spatialReference = gdbDataset.getSpatialReference();
IGeoDatasetSchemaEdit geoDataset = (IGeoDatasetSchemaEdit)schematicDataset; // here I get an InvalidCastException
geoDataset.AlterSpatialReference(spatialReference);
IGeoDatasetSchemaEdit geoDiagramClass = (IGeoDatasetSchemaEdit)schematicDiagramClass;
geoDiagramClass.AlterSpatialReference(spatialReference);
0 Kudos
nicogis
MVP Frequent Contributor

Excuse me but before I have seen old help because now schematic has changed ( ArcObjects Help for .NET developers ). See these snippets: http://www.arcgis.com/home/item.html?id=a8be26357b944dfdbbd69a55818dcc88

0 Kudos