IGeographicCoordinateSystem m_geographicCoordinateSystem = (new SpatialReferenceEnvironment()) .createGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984); IWorkspaceFactory m_workspaceFactory = new FileGDBWorkspaceFactory(); IWorkspaceName workspaceName = m_workspaceFactory.create(workspacePath, gdbfileName, null, 0); Workspace m_workspace = new Workspace(m_workspaceFactory.openFromFile(workspaceName.getPathName(), 0)); FeatureDataset featureDataset = new FeatureDataset(m_workspace.createFeatureDataset(name, m_geographicCoordinateSystem));
IGeographicCoordinateSystem m_geographicCoordinateSystem = new SpatialReferenceEnvironment().CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984); IWorkspaceFactory m_workspaceFactory = new FileGDBWorkspaceFactory(); IName workspaceName = m_workspaceFactory.create(workspacePath, gdbfileName, null, 0) as IName; IFeatureWorkspace m_workspace = workspaceName.Open() as IFeatureWorkspace; IFeatureDataset featureDataset = m_workspace.createFeatureDataset(name, m_geographicCoordinateSystem);
IName workspaceName = (IName) m_workspaceFactory.create(workspacePath, gdbfileName, null, 0); Workspace m_workspace = new Workspace(workspaceName.open());
Workspace m_workspace = (Workspace) m_workspaceFactory.openFromFile(workspaceName.getPathName(), 0);
public Workspace(Object obj) throws IOException Construct a Workspace using a reference to such an object returned from ArcGIS Engine or Server. This is semantically equivalent to casting obj to Workspace. Casting to this class from the return value of a method will not work, as this class represents an abstract class in ArcObjects. * Workspace o = (Workspace)obj; // will not work Workspace o = new Workspace(obj); // Use this constructor instead * @param obj an object returned from ArcGIS Engine or Server Throws: IOException - if there are interop problems Workspace theWorkspace = (Workspace) obj;
Timothy,
You were using the wrong workspace. I don't know if this will help you or not.
import java.io.IOException;
import java.net.UnknownHostException;
import com.esri.arcgis.datasourcesGDB.FileGDBWorkspaceFactory;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geodatabase.IFeatureWorkspaceProxy;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.geodatabase.IWorkspaceFactory;
import com.esri.arcgis.geodatabase.IWorkspaceName;
import com.esri.arcgis.geodatabase.IWorkspaceProxy;
import com.esri.arcgis.geometry.ISpatialReference;
import com.esri.arcgis.geometry.SpatialReferenceEnvironment;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.IName;
public class FGDBDemo {
private static IWorkspace workspace;
public static void main(String[] args) {
// code generated from the File|New|ESRI Templates|ArcObjects Project|Console wizard
EngineInitializer.initializeEngine();
initializeArcGISLicenses();
// create the File Geodatbase and Workspace stuff... code copied more or less directly from the help
createFGDBStuff();
// create the feature dataset... code copied more or less directly from the help
createFeatureDataset();
}
static void initializeArcGISLicenses() {
try {
com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize();
if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);
else if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createFGDBStuff(){
try {
//Create a FileGDB workspace factory
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
//Create a new File geodatabase
IWorkspaceName workspaceName = workspaceFactory.create("C:\\GIS\\", "MyFGDB.gdb", null, 0);
//Cast for IName
// ... there are different ways to do this, it was the first sample I copied from the help.
// ... alot of people like opening the opening the FGDB using a path name, there are samples in the help for that.
IName name = (IName)workspaceName;
//Open a reference to the FGDB workspace through the name object
workspace = new IWorkspaceProxy(name.open());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void createFeatureDataset(){
try {
// variable to hold the named constant value for this spatial reference
int wgs84 = com.esri.arcgis.geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984;
// Create a SpatialReferenceEnvironment and ISpatialReference
SpatialReferenceEnvironment spatialRef = new SpatialReferenceEnvironment();
ISpatialReference gcswgs84 = spatialRef.createGeographicCoordinateSystem(wgs84);
// create the feature workspace
IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(workspace);
// create the featureDataset (the name, the featureDataset spatial reference)
featureWorkspace.createFeatureDataset("MyFDS", gcswgs84);
} catch (AutomationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}