Sunday, February 22, 2015

Load Projected Coordinate System from file Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Load Geographic Coordinate System from file



 // load Projected projected system from file  
 static IProjectedCoordinateSystem loadProjectedCoordinateSystem()  
           throws Exception {  
      ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();  
      IProjectedCoordinateSystem projectedCoordinateSystem = (IProjectedCoordinateSystem) spatialReferenceFactory  
                .createESRISpatialReferenceFromPRJFile("D:/work/WGS1984UTMZone43N.prj");  
      return projectedCoordinateSystem;  
 }  




This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Load Geographic Coordinate System from file Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Load Geographic Coordinate System from file


 // load Geographic cordinate system from file  
 static IGeographicCoordinateSystem loadGeographicCoordinateSystem()  
           throws Exception {  
      ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();  
      IGeographicCoordinateSystem geographicCoordinateSystem = (IGeographicCoordinateSystem) spatialReferenceFactory  
                .createESRISpatialReferenceFromPRJFile("D:/work/WGS1984.prj");  
      return geographicCoordinateSystem;  
 }  





This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Create Fields Collection Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Fields Collection



 // create field collection for table  
 public IFields createFieldsCollectionForTable() throws Exception {  
      // Create a new fields collection.  
      IFields fields = new Fields();  
      // Cast for IFieldsEdit to modify the properties of the fields  
      // collection.  
      IFieldsEdit fieldsEdit = (IFieldsEdit) fields;  
      // Set the FieldCount to the total number of fields to be created.  
      fieldsEdit.setFieldCount(2);  
      // Create the ObjectID field.  
      IField fieldUserDefined = new Field();  
      // Cast for IFieldEdit to modify the properties of the new field.  
      IFieldEdit fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setAliasName("FID");  
      fieldEdit.setName("ObjectID");  
      fieldEdit.setType(esriFieldType.esriFieldTypeOID);  
      // Add the new field to the fields collection.  
      fieldsEdit.setFieldByRef(0, fieldUserDefined);  
      // Create the text field.  
      fieldUserDefined = new Field();  
      fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setLength(30); // Only string fields require that you set the  
                                         // length.  
      fieldEdit.setName("Owner");  
      fieldEdit.setType(esriFieldType.esriFieldTypeString);  
      // Add the new field to the fields collection.  
      fieldsEdit.setFieldByRef(1, fieldUserDefined);  
      return fields;  
 }  




This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Saturday, February 21, 2015

Create Feature Class Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Feature Class


 // Create Feature Class  
 static IFeatureClass createFeatureClass(IFeatureDataset featureDataset,  
           String nameOfFeatureClass) throws Exception {  
      // This function creates a new feature class in a supplied feature  
      // dataset by creating all fields from scratch. IFeatureClassDescription (or  
      // IObjectClassDescription if the table is  
      // created at the workspace level) can be used to get the required  
      // fields and are used to  
      // get the InstanceClassID and ExtensionClassID.  
      // Create new fields collection with the number of fields you plan to  
      // add. Must add at least two fields  
      // for a feature class: Object ID and Shape field.  
      IFields fields = new Fields();  
      IFieldsEdit fieldsEdit = (IFieldsEdit) fields;  
      fieldsEdit.setFieldCount(3);  
      // Create Object ID field.  
      IField fieldUserDefined = new Field();  
      IFieldEdit fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setName("OBJECTID");  
      fieldEdit.setAliasName("OBJECT ID");  
      fieldEdit.setType(esriFieldType.esriFieldTypeOID);  
      fieldsEdit.setFieldByRef(0, fieldUserDefined);  
      // Create Shape field.  
      fieldUserDefined = new Field();  
      fieldEdit = (IFieldEdit) fieldUserDefined;  
      // Set up geometry definition for the Shape field.  
      // You do not have to set the spatial reference, as it is inherited from  
      // the feature dataset.  
      IGeometryDef geometryDef = new GeometryDef();  
      IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit) geometryDef;  
      geometryDefEdit.setGeometryType(esriGeometryType.esriGeometryPolyline);  
      // By setting the grid size to 0, you are allowing ArcGIS to determine  
      // the appropriate grid sizes for the feature class.  
      // If in a personal geodatabase, the grid size is 1,000. If in a file or  
      // ArcSDE geodatabase, the grid size  
      // is based on the initial loading or inserting of features.  
      geometryDefEdit.setGridCount(1);  
      geometryDefEdit.setGridSize(0, 0);  
      geometryDefEdit.setHasM(false);  
      geometryDefEdit.setHasZ(false);  
      // Set standard field properties.  
      fieldEdit.setName("SHAPE");  
      fieldEdit.setType(esriFieldType.esriFieldTypeGeometry);  
      fieldEdit.setGeometryDefByRef(geometryDef);  
      fieldEdit.setIsNullable(true);  
      fieldEdit.setRequired(true);  
      fieldsEdit.setFieldByRef(1, fieldUserDefined);  
      // Create a field of type double to hold some information for the  
      // features.  
      fieldUserDefined = new Field();  
      fieldEdit = (IFieldEdit) fieldUserDefined;  
      fieldEdit.setName("Avg_income");  
      fieldEdit.setAliasName("Average income for 1999-2000");  
      fieldEdit.setEditable(true);  
      fieldEdit.setIsNullable(false);  
      fieldEdit.setPrecision(2);  
      fieldEdit.setScale(5);  
      fieldEdit.setType(esriFieldType.esriFieldTypeDouble);  
      fieldsEdit.setFieldByRef(2, fieldUserDefined);  
      // Create a feature class description object to use for specifying the  
      // CLSID and EXTCLSID.  
      IFeatureClassDescription fcDesc = new FeatureClassDescription();  
      IObjectClassDescription ocDesc = (IObjectClassDescription) fcDesc;  
      return featureDataset.createFeatureClass(nameOfFeatureClass, fields,  
                ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(),  
                esriFeatureType.esriFTSimple, "SHAPE", "");  
 }  



This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Create Feature Data Set Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Feature Dataset



 // Create feature dataset  
 static IFeatureDataset createFeatureDataset(IWorkspace workspace,  
           String fdsName, ISpatialReference fdsSR) throws Exception {  
      IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(  
                workspace);  
      return featureWorkspace.createFeatureDataset(fdsName, fdsSR);  
 }  




This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Create Workspace Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Workspace


 // Create Workspace  
 IWorkspace openFromString_fGDB_Workspace(String connectionString)  
           throws Exception {  
      IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactory();  
      return workspaceFactory.openFromString(connectionString, 0);  
 }  


This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

Create Database Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Create Database



 // Create Database
 public void createdatabase() {  
      String file = "D:\\work\\PAKdatabase";  
      // ***Create Database  
      try {  
           // Create a FileGDB workspace factory  
           IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();  
           // Create a new File geodatabase  
           IWorkspaceName workspaceName = workspaceFactory  
                     .create("D:\\work\\", "MyFGDB.gdb", null, 0);  
           System.out.println("workspaceName = " + workspaceName.toString());  
           // Cast for IName  
           IName name = (IName) workspaceName;  
           System.out.println("name = " + name.toString());  
           // Open a reference to the access workspace through the name object  
           IWorkspace workspace = new IWorkspaceProxy(name.open());  
      } catch (Exception e) {  
           e.printStackTrace();  
      }  
 }  

This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.