Export XFM features as shapefiles

I am working on a C# addin, which among other formats, must be able to export Esri Shape files and MapinfoTAB files. For now I have got it working sending keyins, but I would like to use the Bentley.Geospatial.DataInterchange API.

I have looked in the GeoDataInterchangeAPI. chm help file, but I as fare as I can see, the help file don't match the API, as I see it referenced from Visual Studio.

Can anyone help me with an example, or some code snippets?

/Peter

  • Greetings Peter,

    Maybe the following code snippets can get you going?

    public static void SHPExportWithCriteria (bool addToExports)
                {
                GDIExplorerExportNode exportNode = new GDIExplorerExportNode("mytown");
                exportNode.AddExportDirectory(GDIExplorerExportNode.FileCreateType.SHP, @"c:\temp\exp");
    
                //we can optionally add the new import to the Imports node in the Interoperability dialog
                if (addToExports)
                    {
                    GDIExplorerExportsNode exportsNode = GDIExplorerAddIn.Instance.ExportsNode;
                    exportsNode.AddExportNode(exportNode);
                    }
    
                ImportWithCriteria(exportNode, false, true);
    
                if (!addToExports)
                    {
                    //we might need to close the storage if we're not adding it to the tree
                    IStorageImportCriteria storageImp = exportNode.StorageImports[0] as IStorageImportCriteria;
                    IECCreateableStorage createableStorage = storageImp.Storage as IECCreateableStorage;
                    if (createableStorage != null && createableStorage.IsOpen)
                        createableStorage.Close();
                    }
                }

    public static void SetupCriteria(IImportCriteria import, bool overrideCriteria) { //Define query/selection criteria at the feature class level for import, export and Oracle Spatial query operations. //Define spatial criteria for import, export and Oracle Spatial query operations. //Select included/excluded feature classes for import/export operations. IStorageImportCriteria storageImp = import.StorageImports[0]; //the following two sections basically accomplish the same thing. if (overrideCriteria) { IClassImportCriteria myLotsClassImp = storageImp.ClassImports["mylots"]; //create some property criteria IECProperty property = myLotsClassImp.Properties["BLOCK"].Property; IECPropertyValue propVal = property.CreateValue(null); propVal.IntValue = 5; ECPrimitivePropertyValueCriteria blockPropValCrit = new ECPrimitivePropertyValueCriteria(property.Name, property.Type, ECPropertyComparisonOperations.PROPCOMP_Equal); blockPropValCrit.ComparisonValue = propVal; property = myLotsClassImp.Properties["FLOODZONE"].Property; propVal = property.CreateValue(null); propVal.IntValue = 13; ECPrimitivePropertyValueCriteria fzPropValCrit = new ECPrimitivePropertyValueCriteria(property.Name, property.Type, ECPropertyComparisonOperations.PROPCOMP_Equal); fzPropValCrit.ComparisonValue = propVal; //combine them using OR ECCompoundCriteria mylotsPropCrit = new ECCompoundCriteria(ECCombinationOperations.COMBO_Or); mylotsPropCrit.CriteriaList.Add(blockPropValCrit); mylotsPropCrit.CriteriaList.Add(fzPropValCrit); //create a compound criteria for the class, property and spatial criteria IECCompoundCriteria classCrit = new ECCompoundCriteria(ECCombinationOperations.COMBO_And); classCrit.CriteriaList.Add(new ECClassCriteria(myLotsClassImp.ClassDefinition)); classCrit.CriteriaList.Add(mylotsPropCrit); //create an overall compound criteria IECCompoundCriteria overallCriteria = new ECCompoundCriteria(ECCombinationOperations.COMBO_Or); overallCriteria.CriteriaList.Add(classCrit); //do the same thing for any other classes we want to query IClassImportCriteria myStreetsClassImp = storageImp.ClassImports["mystreets"]; classCrit = new ECCompoundCriteria(ECCombinationOperations.COMBO_And); classCrit.CriteriaList.Add(new ECClassCriteria(myStreetsClassImp.ClassDefinition)); overallCriteria.CriteriaList.Add(classCrit); storageImp.ECCriteria = overallCriteria; } else { storageImp.ClassImports["mylots"].Selected = true; storageImp.ClassImports["mystreets"].Selected = true; storageImp.ClassImports["mymons"].Selected = false; //add a spatial criteria (view) bool useViewArea = true; if (useViewArea) { import.SpatialArea = SpatialArea.View; import.View = 0; } else { //alternative is to create a polygon and set the Geometry property import.Geometry = CreateRectangle(100, 100, 200, 200); } //add property criteria storageImp.ClassImports["mylots"].WhereClause = "BLOCK=5 OR FLOODZONE=13"; } } public static void ImportWithCriteria(IImportCriteria import, bool isQuery, bool isExport) { //we have the ability to completely specify the criteria ourselves, //or set certain properties to accomplish the same thing. The advantage //of overriding it ourselves is that the settings setup by the user //interactively remain intact, the disadvantage is that it's a bit more work to setup. bool overrideCriteria = false; SetupCriteria(import, overrideCriteria); IStorageImportCriteria storageImp = import.StorageImports[0]; //turning on/off properties and setting mapped names is only supported for import/export, not for queries if (!isQuery) { //select business properties for import/export operations. //turn off a property for another class IClassImportCriteria classImp = storageImp.ClassImports["mylots"]; IPropertyImportCriteria propImp = classImp.Properties["MSLINK"]; propImp.Selected = false; //rename another property (only when importing) propImp = classImp.Properties["BLOCK"]; propImp.MappedName = "BLOCKY"; } try { GDIImportProcessor importProcessor = new GDIImportProcessor(); importProcessor.Cancellable = true; importProcessor.ShowProgress = false; importProcessor.ShowCompleteMessage = false; importProcessor.IsExport = isExport; importProcessor.Update = isQuery && !isExport; //execute import/export importProcessor.Import(import, null); } finally { //null out criteria if (overrideCriteria) storageImp.ECCriteria = null; } }

    Regards,

    Jeff Bielefeld [Bentley]



  • Hi Jeff

    Thanks for your reply, I think i have found a solution. I have come up with the following code, that seems to do what i need at the moment.

    GDIExplorerExportNode ExpNode = new GDIExplorerExportNode("Eksport");

    ExpNode.AddExportDirectory(GDIExplorerExportNode.FileCreateType.SHP, @"c:\temp\shp");

    IStorageImportCriteria StorImpCrit = ExpNode.StorageImports[0];

     

    foreach (IClassImportCriteria currentClassImp in StorImpCrit.ClassImports.Values)

    {

    if (currentClassImp.Name == "Ledninger") currentClassImp.Selected = true;

    else currentClassImp.Selected = false;

    }

    if (RadFence.Checked)  ExpNode.SpatialArea = SpatialArea.Fence;

    else if (RadSelection.Checked)  ExpNode.SpatialArea = SpatialArea.Selection;

    else if (RadView.Checked)  ExpNode.SpatialArea = SpatialArea.View;

    else ExpNode.SpatialArea = SpatialArea.All;

     

    GDIImportProcessor importProcessor = new GDIImportProcessor();

    importProcessor.IsExport = true;

    importProcessor.Import(ExpNode, StorImpCrit);