<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Simple code to create a feature class and a feature in File Geodatabase API Questions</title>
    <link>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342690#M1227</link>
    <description>&lt;P&gt;Thanks but I look for code with geodatabase API that does not need a license&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2023 14:55:32 GMT</pubDate>
    <dc:creator>mody_buchbinder</dc:creator>
    <dc:date>2023-10-27T14:55:32Z</dc:date>
    <item>
      <title>Simple code to create a feature class and a feature</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342521#M1225</link>
      <description>&lt;P&gt;Does anybody have a sample in C# that create a GDB, create a feature class in it and add a point to this feature class.&lt;/P&gt;&lt;P&gt;Without using the XML as the example do?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 07:34:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342521#M1225</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-10-27T07:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Simple code to create a feature class and a feature</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342538#M1226</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hello,&lt;BR /&gt;&lt;SPAN&gt;Make sure to replace &lt;/SPAN&gt;"C:\Path\To\Your\Geodatabase.gdb"&lt;SPAN&gt; with the path where you want to create your file geodatabase. This script creates a file geodatabase, a point feature class, and adds a point feature with attributes to it. I'm not using C, but I guess it should work. Let me know &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesFile;

namespace CreateGeodatabase
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Initialize the license
            IAoInitialize aoInit = new AoInitialize();
            esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);

            if (licStatus != esriLicenseStatus.esriLicenseCheckedOut)
            {
                Console.WriteLine("License initialization failed, exiting.");
                return;
            }

            try
            {
                // Create a file geodatabase
                IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                IWorkspaceName workspaceName = workspaceFactory.Create(@"C:\Path\To\Your\Geodatabase.gdb", "MyGDB", null, 0);
                IName name = (IName)workspaceName;
                IWorkspace workspace = (IWorkspace)name.Open();

                // Create a point feature class
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                IFields fields = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

                IField field = new FieldClass();
                IFieldEdit fieldEdit = (IFieldEdit)field;
                fieldEdit.Name_2 = "Name";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                fieldsEdit.AddField(field);

                IGeometryDef geometryDef = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                fieldsEdit.GeometryDef_2 = geometryDef;

                featureWorkspace.CreateFeatureClass("MyPointFC", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                // Create a point feature and add it to the feature class
                IFeatureClass pointFeatureClass = featureWorkspace.OpenFeatureClass("MyPointFC");
                IFeatureBuffer featureBuffer = pointFeatureClass.CreateFeatureBuffer();
                IFeatureCursor featureCursor = pointFeatureClass.Insert(true);

                // Create a point geometry and set it on the feature
                IPoint point = new PointClass();
                point.PutCoords(100.0, 50.0);
                featureBuffer.Shape = point;

                // Set attribute values
                int nameFieldIndex = featureBuffer.Fields.FindField("Name");
                featureBuffer.set_Value(nameFieldIndex, "FirstPoint");

                featureCursor.InsertFeature(featureBuffer);
                featureCursor.Flush();

                Console.WriteLine("Point feature with attributes created.");

                Marshal.ReleaseComObject(workspace);
                Marshal.ReleaseComObject(workspaceFactory);
                Marshal.ReleaseComObject(aoInit);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
    }
}​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 08:29:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342538#M1226</guid>
      <dc:creator>lmatteo</dc:creator>
      <dc:date>2023-10-27T08:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simple code to create a feature class and a feature</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342690#M1227</link>
      <description>&lt;P&gt;Thanks but I look for code with geodatabase API that does not need a license&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 14:55:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1342690#M1227</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-10-27T14:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Simple code to create a feature class and a feature</title>
      <link>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1343179#M1228</link>
      <description>&lt;P&gt;What about this ?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;using System;
using System.IO;
using Esri.FileGDB;

namespace CreateFileGDB
{
class Program
{
static void Main(string[] args)
{
// Define the path to your file geodatabase
string gdbPath = @"C:\Path\To\Your\Geodatabase.gdb";

try
{
// Create a new File Geodatabase
using (Geodatabase geodatabase = Geodatabase.Open(gdbPath, GeodatabaseOpenMode.Create))
{
// Create a point feature class
using (FeatureClassDescription fcDescription = new FeatureClassDescription())
{
Field[] fields = fcDescription.RequiredFields;
GeometryDef geometryDef = fcDescription.DefaultGeometryDef;
using (FeatureClass featureClass = geodatabase.CreateFeatureClass("MyPointFC", fields, geometryDef))
{
// Create a point feature and add it to the feature class
using (RowBuffer rowBuffer = featureClass.CreateRowBuffer())
{
using (PointShapeBuffer shapeBuffer = new PointShapeBuffer(geometryDef))
{
shapeBuffer.SetPoint(0, 100.0, 50.0);
rowBuffer.SetGeometry(shapeBuffer);

// Set attribute values
rowBuffer["Name"] = "FirstPoint";

using (Row row = featureClass.CreateRow(rowBuffer))
{
Console.WriteLine("Point feature with attributes created.");
}
}
}
}
}
}
}
catch (GdbError e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 30 Oct 2023 08:19:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/file-geodatabase-api-questions/simple-code-to-create-a-feature-class-and-a/m-p/1343179#M1228</guid>
      <dc:creator>lmatteo</dc:creator>
      <dc:date>2023-10-30T08:19:48Z</dc:date>
    </item>
  </channel>
</rss>

