AnsweredAssumed Answered

CSV with XYZ to ArcScene layer

Question asked by asingh6 on Apr 9, 2018

I am getting a csv file created through arcmap addin and when I am calling this below class it is opening the arcscene but taking alot time to draw on arcscene but through Arcscene addin it is not taking any time. custom developmentdeveloper program

 

 

public class SceneViewer
{
ESRI.ArcGIS.Analyst3D.IScene pfg;
private ESRI.ArcGIS.Framework.IApplication mScene_application;
private int m_appHWnd = 0;
ESRI.ArcGIS.Framework.IDocument doc = null;
ESRI.ArcGIS.ArcScene.ISxDocument pSceneDoc;

public SceneViewer(string workspacepath, IEnvelope curExtent)
{
doc = new ESRI.ArcGIS.ArcScene.SxDocumentClass();
mScene_application = doc.Parent;
mScene_application.Visible = true;
m_appHWnd = mScene_application.hWnd;
pSceneDoc = (ESRI.ArcGIS.ArcScene.ISxDocument)mScene_application.Document;
pfg = pSceneDoc.Scene;
}
private ITable OpenCSVAsTable(string csvPath)
{
IWorkspaceFactory wsFactory = new ESRI.ArcGIS.DataSourcesOleDB.TextFileWorkspaceFactoryClass();
FileInfo fileInfo = new FileInfo(csvPath);
IWorkspace workspace = wsFactory.OpenFromFile(fileInfo.DirectoryName, 0);
IFeatureWorkspace featWork = workspace as IFeatureWorkspace;
ITable table = featWork.OpenTable(fileInfo.Name);
return table;

}


public void CreateXYLayer(string csvPath)
{
try
{
ESRI.ArcGIS.ArcMapUI.IMxDocument pMxDoc;
IMap pMap;
pMxDoc = (ESRI.ArcGIS.ArcMapUI.IMxDocument)ArcMap.Application.Document;
pMap = pMxDoc.FocusMap;
ESRI.ArcGIS.Framework.IObjectFactory objFactory = mScene_application as ESRI.ArcGIS.Framework.IObjectFactory;
IStandaloneTableCollection pStTabCol;
IStandaloneTable pStandaloneTable;
ITable pTable = null;
pStTabCol = (IStandaloneTableCollection)pMap;
pTable = OpenCSVAsTable(csvPath);
if (pTable == null)
{
MessageBox.Show("The table was not found");
return;
}

IDataset pDataSet;
IName pTableName;
pDataSet = (IDataset)pTable;
pTableName = pDataSet.FullName;

IXYEvent2FieldsProperties pXYEvent2FieldsProperties;
pXYEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass();
pXYEvent2FieldsProperties.XFieldName = "x";
pXYEvent2FieldsProperties.YFieldName = "y";
pXYEvent2FieldsProperties.ZFieldName = "z";

ISpatialReferenceFactory pSpatialReferenceFactory;
pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
IProjectedCoordinateSystem pProjectedCoordinateSystem;
pProjectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem(28232);
IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass();
IName pXYName;
IXYEventSource pXYEventSource;
pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties;
pXYEventSourceName.SpatialReference = pProjectedCoordinateSystem;
pXYEventSourceName.EventTableName = pTableName;
pXYName = (IName)pXYEventSourceName;
pXYEventSource = (IXYEventSource)pXYName.Open();

ESRI.ArcGIS.ArcMapUI.IBasicDocument document = (ESRI.ArcGIS.ArcMapUI.IBasicDocument)mScene_application.Document;

 

IFeatureLayer pFLayer = new FeatureLayerClass();
pFLayer.FeatureClass = (IFeatureClass)pXYEventSource;
pFLayer.Name = System.IO.Path.GetFileNameWithoutExtension(csvPath); ;
ILayer layer = (ILayer)pFLayer;
pSceneDoc.AddLayer(layer);
}
catch (COMException COMEx)
{
MessageBox.Show(COMEx.Message, "COM Error: " + COMEx.ErrorCode.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (System.Exception SysEx)
{
MessageBox.Show(SysEx.Message, ".NET Error: ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}


}

Outcomes