<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GISGP on Medium]]></title>
        <description><![CDATA[Stories by GISGP on Medium]]></description>
        <link>https://medium.com/@kalin_85212?source=rss-f0eea8eb30d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pkAhR3HFkjyKv7rh6AqJMQ.png</url>
            <title>Stories by GISGP on Medium</title>
            <link>https://medium.com/@kalin_85212?source=rss-f0eea8eb30d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:37:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kalin_85212/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[2 ways to import excel to database with python]]></title>
            <link>https://medium.com/@kalin_85212/2-ways-to-import-excel-to-database-with-python-ebd50e7d65a7?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebd50e7d65a7</guid>
            <category><![CDATA[arcgis-pro]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Sun, 04 Feb 2024 09:27:25 GMT</pubDate>
            <atom:updated>2026-05-28T14:53:20.063Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we explore the process of creating a table in a file geodatabase using ArcGIS Pro. <br> To achieve this, we will utilize a notebook within ArcGIS Pro. Follow these steps to complete the task: <br> Open a new notebook in ArcGIS Pro. Add the necessary libraries. We will demonstrate two examples. <br> In the first case, we will utilize the built-in options — namely, arcpy and pandas.</p><ol><li>ExcelToTable</li><li>Pandas</li></ol><p>After presenting both methods, we will compare their pros and cons.</p><p><a href="https://medium.com/@kalin_85212/3-ways-to-export-geodatabase-to-excel-with-python-34dd21477913">3 ways to export geodatabase to excel with python</a></p><p>Let’s begin with the Excel file that we aim to process, containing attribute information about roads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*UsPOuZtkV-7xEpuiX1UO9w.png" /><figcaption>This is how the sample excel that we will import looks like</figcaption></figure><p>The name of the Sheet is important to us. This name is a parameter that we set in the code. In our case, the name <strong>“Sheet”</strong> is the default. Let’s review and the total number of records in excel it is <strong>56602</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*jS_y2m9dpfzpYOaBv4Tt6A.png" /><figcaption>Excel contains 56602 records</figcaption></figure><p>The first row of the Excel file contains the names of our new fields. <br> To successfully create a table in a relational database, these names must not contain special characters, be in English, and have no spaces. <br> Additionally, multiple cells should not be merged; otherwise, preprocessing is required before importing.</p><p><strong>1. First way to import a table into a geographic database with ExcelToTable.</strong></p><p>Let’s examine the code, and later we’ll break it down to understand each part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*n9hNnjnZZ03sGkQxMgyslw.png" /></figure><p>A message is printed after table processing is complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*EkUfffCbBJumEb4aPgNn2A.png" /></figure><p>In ArcGIS Pro, we go to the Catalog tab and open Databases. <br> Let’s check the result, we open the geographic database and look for the newly created table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*Kb6jtJiXum3LoL1EN7IxGA.png" /></figure><p>We select the content layer and press ctrl+T to open the attribute table to look at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*XKpgt7H6hUZ1w6Zb1ZGptA.png" /><figcaption>RoadsTable attributes</figcaption></figure><p>If you remember in the excel file we had 56602 rows. In the attribute table, we will always get one row at a time because this row contains the names of the fields we added.</p><p>At the beginning, it is necessary to specify the libraries that we will use. These are <br> <strong>import arcpy <br> import os</strong> <br> We’ll pass in a path to the geodatabase and set it to be the workspace for the post-processing. <br> <strong>output_gdb = r’C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb’ <br> arcpy.env.workspace = output_gdb </strong><br> We add a path to an excel file <br> <strong>input_excel = r’C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\RoadsExcel.xlsx’</strong> <br> We name the new table in file geodatabase <br> <strong>output_fc_name = ‘RoadsTable’ </strong><br> We concatenate the name and path into one variable. <br> <strong>output_fc = os.path.join(output_gdb, output_fc_name) </strong><br> Since we are doing the import repeatedly we want to check if a table with that name exists in the file geodatabase. <br> If there is such a table, we delete it.</p><p><strong>if arcpy.Exists(output_fc):</strong></p><p><strong>arcpy.Delete_management(output_fc)</strong></p><p>We create a table in gdb <strong>arcpy.CreateTable_management(output_gdb, output_fc_name)</strong></p><p>We set the sheet name from excel as a parameter <strong>input_sheet = ‘Sheet’</strong></p><p>We create an object to store the names of our fields</p><p><strong>field_mappings = arcpy.FieldMappings()</strong></p><p>We convert our excel file into a table by specifying all the parameters, these are the name of the input file, a table from gdb, the name of the sheet from excel (if there are several sheets in excel, specify the correct one), we also have an additional parameter that we do not use in our case.</p><p>This is the <strong>field_names_row parameter</strong>, if the names of our fields are, for example, on the second row, and not on the first as it is by default, we can set the row number.</p><p><strong>arcpy.conversion.ExcelToTable( Input_Excel_File=input_excel, Output_Table=output_fc, Sheet=input_sheet, #field_names_row=1 )</strong></p><p>Let’s take a look at the full code we used:</p><pre>import arcpy<br>import os<br><br># Set the workspace (output file geodatabase)<br>output_gdb =<br>r&#39;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb&#39;<br>arcpy.env.workspace = output_gdb<br><br># Set the input Excel file<br>input_excel =<br>r&#39;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\RoadsExcel.xlsx&#39;<br><br># Set the output feature class or table name<br>output_fc_name = &#39;RoadsTable&#39;<br><br># Create a feature class or table in the file geodatabase<br>output_fc = os.path.join(output_gdb, output_fc_name)<br><br><br># Check if the feature class or table already exists and delete if it does<br>if arcpy.Exists(output_fc):<br>    arcpy.Delete_management(output_fc)<br><br># Create a new feature class or table<br>arcpy.CreateTable_management(output_gdb, output_fc_name)<br><br><br># Set up Excel to Table conversion options<br>input_sheet = &#39;Sheet&#39;<br># Specify the sheet name or range<br><br># Create a FieldMappings object<br>field_mappings = arcpy.FieldMappings()<br><br># Use Excel to Table conversion tool<br>arcpy.conversion.ExcelToTable(<br>    Input_Excel_File=input_excel,<br>    Output_Table=output_fc,<br>    Sheet=input_sheet,<br>    #field_names_row=1<br>)<br><br>print(&quot;Data imported successfully with ExcelToTable to File Geodatabase.&quot;)</pre><p><strong>2. Second way of importing a table into a geographic database with pd.read_excel and InsertCursor.</strong></p><p>Let’s see how this code works, and later we’ll break it down to see how each part of it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*EVKeWx0JpGZAQt4OvvSBJQ.png" /></figure><p>A successful code execution message is printed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*rdaAa_3NQhK6I8m3tzrP3w.png" /></figure><p>In ArcGIS Pro, we go to the Catalog tab and open Databases. Let’s review the file geographic database to see if it contains the table we take from Excel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*OeGP4K-mDNam_E-ZPZfuZw.png" /></figure><p>Let’s review the attribute table in ArcGIS Pro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*s91nIBVGX32iYEm9OikrlQ.png" /></figure><p>As you can see the result tables are exactly the same. At the end of the article, we will compare the two methods. At the beginning, it is necessary to specify the libraries that we will use. These are <br> <strong>import arcpy <br> import os <br> import pandas as pd </strong><br> We’ll pass in a path to the geodatabase and set it to be the workspace for the post-processing <strong>output_gdb = r’C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb’ arcpy.env.workspace = output_gdb </strong><br> We add a path to an excel file <br> <strong>input_excel = r’C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\RoadsExcel.xlsx’ </strong><br> We name the new table in file geodatabase <br> <strong>output_fc_name = ‘RoadsTablePandas’ </strong><br> We concatenate the name and path into one variable <br> <strong>output_fc = os.path.join(output_gdb, output_fc_name) </strong><br> Since we are doing the import repeatedly we want to check if a table with that name exists in the file geodatabase. <br> If there is such a table, we delete it.</p><p><strong>if arcpy.Exists(output_fc): <br> arcpy.Delete_management(output_fc)</strong></p><p>We create a table in gdb with</p><p><strong>arcpy.CreateTable_management(output_gdb, output_fc_name)</strong></p><p>We create an object to store the names of our fields</p><p><strong>for field_name in field_names: <br> arcpy.AddField_management(output_fc, field_name, “TEXT”)</strong></p><p>We use arcpy’s built-in crawl option, it’s InsertCursor.</p><p>As parameters in this function we set the reading of the excel file</p><p><strong>pd.read_excel(input_excel, sheet_name=’Sheet’)</strong> , this method looks for the name and the path to the excel as well as the name of the corresponding sheet.</p><p>We create a tuple with the names of the fields from excel which we will set as field names in the new table in gdb</p><p><strong>row_values = tuple(row[field] for field in field_names)</strong></p><p>And finally we load all the values from the rows in excel row by row into the new table <strong>cursor.insertRow(row_values)</strong>.</p><p>with arcpy.da.InsertCursor(output_fc, field_names) as cursor:</p><p>for _, row in pd.read_excel(input_excel, sheet_name=’Sheet’).iterrows():</p><p># Convert Pandas Series to tuple</p><p>row_values = tuple(row[field] for field in field_names)</p><p># Insert row into the geodatabase table</p><p>cursor.insertRow(row_values)</p><p><strong>Let’s take a look at the full code we used:</strong></p><pre>import arcpy<br>import os<br>import pandas as pd<br><br># Set the workspace (output file geodatabase)<br>output_gdb =<br>r&#39;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb&#39;<br><br>arcpy.env.workspace = output_gdb<br><br># Set the input Excel file<br>input_excel =<br>r&#39;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\RoadsExcel.xlsx&#39;<br><br># Set the output feature class or table name<br>output_fc_name = &#39;RoadsTablePandas&#39;<br><br># Read the first row from Excel to get field names<br>df_field_names = pd.read_excel(input_excel, sheet_name=&#39;Sheet&#39;, nrows=0)<br><br># Extract field names as a list<br>field_names = df_field_names.columns.tolist()<br><br># Create a new feature class or table in the file geodatabase<br>output_fc = os.path.join(output_gdb, output_fc_name)<br><br># Check if the feature class or table already exists and delete if it does<br>if arcpy.Exists(output_fc):<br>    arcpy.Delete_management(output_fc)<br><br># Create a new feature class or table with the extracted field names<br>arcpy.CreateTable_management(output_gdb, output_fc_name)<br><br># Add fields to the table based on the extracted field names<br>for field_name in field_names:<br>    arcpy.AddField_management(output_fc, field_name, &quot;TEXT&quot;)<br>    # You may need to adjust the field type<br><br># Insert rows from Pandas DataFrame into the geodatabase table<br>with arcpy.da.InsertCursor(output_fc, field_names) as cursor:<br>    for _, row in pd.read_excel(input_excel, sheet_name=&#39;Sheet&#39;).iterrows():<br>        # Convert Pandas Series to tuple<br>        row_values = tuple(row[field] for field in field_names)<br>        # Insert row into the geodatabase table<br>        cursor.insertRow(row_values)<br><br>print(&quot;Data imported successfully with pandas to File Geodatabase.&quot;)</pre><p>Finally, let’s compare the two methods: <br> Both methods, arcpy.conversion.ExcelToTable and using Pandas to insert rows into a geodatabase table, have their own pros and cons. <br> The choice between them depends on your specific requirements and preferences.</p><p>Here’s a comparison:</p><p><strong>ExcelToTable:</strong></p><p><strong>Pros:</strong></p><p><strong>Simplicity:</strong> The ExcelToTable tool is specifically designed for converting Excel files to tables in a geodatabase. It’s a one-step process. Geodatabase Compatibility: Directly creates tables in a geodatabase, ensuring compatibility with the ArcGIS environment.</p><p><strong>Cons:</strong> <strong>Limited Data Manipulation:</strong> Limited in terms of data manipulation or transformations during the import process. <strong>Field Mapping Limitations:</strong> May encounter limitations in field mapping, especially if your Excel file structure is complex.</p><p><strong>Using Pandas:</strong></p><p><strong>Pros:</strong></p><p><strong>Flexibility:</strong> Pandas offers a high level of flexibility and control over the data manipulation process.</p><p>You can perform various data cleaning and transformation tasks before inserting into the geodatabase.</p><p><strong>Extensive Data Analysis:</strong> Pandas is a powerful library for data analysis, providing tools for handling missing data, merging datasets, etc.</p><p><strong>Pythonic Workflow:</strong> If you are already working with Python and have other data processing tasks, using Pandas fits well into a Pythonic workflow.</p><p><strong>Cons:</strong></p><p><strong>Two-Step Process:</strong> Involves creating an empty table and then inserting rows, which might be seen as a two-step process.</p><p><strong>Considerations:</strong></p><p><strong>Data Complexity:</strong> If your Excel data is straightforward and doesn’t require extensive data cleaning or transformation, using <strong>arcpy.conversion.ExcelToTable</strong> might be more straightforward.</p><p><strong>Data Analysis:</strong> If you need to perform complex data analysis or manipulation before inserting into the geodatabase, using Pandas provides a more flexible solution.</p><p><strong>Workflow Integration:</strong> Consider how this data import fits into your overall workflow.</p><p>If you are already working extensively with Python and Pandas, it might be more convenient to use Pandas for consistency.</p><p><strong>Geodatabase Structure:</strong> If you have a predefined geodatabase structure and want to ensure a direct mapping, arcpy.conversion.ExcelToTable can be more straightforward.</p><p>In summary, both methods are valid, and the choice depends on your specific needs and workflow preferences.</p><p>If you have a simple Excel-to-table conversion with minimal data manipulation, arcpy.conversion.</p><p>ExcelToTable might be more straightforward.</p><p>If you need more flexibility and control over the data processing, Pandas could be a better choice.</p><p><a href="https://gisgp.com/blog/2_ways_to_import_excel_to_database_with_python_in_arcgispro-9.html">2 ways to import excel to database with python in ArcGIS Pro</a></p><p>You can discover my new project at <a href="http://www.gisgp.com/">www.gisgp.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebd50e7d65a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 ways to export geodatabase to excel with python]]></title>
            <link>https://medium.com/@kalin_85212/3-ways-to-export-geodatabase-to-excel-with-python-34dd21477913?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/34dd21477913</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Wed, 31 Jan 2024 15:35:09 GMT</pubDate>
            <atom:updated>2026-05-28T14:54:48.961Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will explore how to export to Excel using Python. This will greatly help us to automate repetitive tasks especially in data processing. We’ll examine three methods along with their corresponding libraries, and finally, we’ll make comparisons between them.</p><ol><li>TableToExcel</li><li>Pandas</li><li>Openpyxl</li></ol><p>To prepare our project in ArcGIS Pro, we will start a new notebook. To start a new notebook, I select the ‘import’ tab and choose ‘new notebook. For the example, we will use paths for the entire world. We can look at the roads on the map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PD5kbySh0ZrUNY88TMrIkA.png" /><figcaption>Map of roads around the world</figcaption></figure><p>In the output excel file, we will save the complete attribute information to the roads layer. We open the attribute table, and it appears as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*ucdbnqyDKnxDGNQ2sziYfQ.png" /><figcaption>Attribute table of the road layer</figcaption></figure><p><a href="https://medium.com/@kalin_85212/2-ways-to-import-excel-to-database-with-python-ebd50e7d65a7">2 ways to import excel to database with python</a></p><ol><li><strong>The first method we will use to make an excel file is TableToExcel.</strong></li></ol><p>We add the arcpy module to use the built-in Excel export function TableToExcel_conversion.</p><p>Let’s set a workspace to the file database from which we will read arcpy.env.workspace.</p><p>We name the feature class or table <strong>table_name = “Roads”</strong>.</p><p>We set the path to the workspace where we will save the output excel <strong>excel_output = r”C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx”.format(table_name)</strong>.</p><p>We convert the attribute table to excel with <strong>arcpy.TableToExcel_conversion(table_name, excel_output)</strong>.</p><p>For <strong>TableToExcel_conversion</strong> to work we need to pass two parameters, a class or table to be exported and an output path with the name of the new excel file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*2K7xhi9F2vk7EMBKIBIrUw.png" /></figure><p>Our excel file is ready let’s take a look at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*j4flRzHfPz1cBArNjkxjuw.png" /></figure><p>The code we used to export to Excel.</p><pre>import arcpy<br><br># Set the workspace (folder where your geodatabase is located)<br>arcpy.env.workspace =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb&quot;<br><br># Specify the table you want to export<br>table_name = &quot;Roads&quot;<br><br># Specify the output Excel file path<br>excel_output =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx&quot;.format(table_name)<br><br># Use the TableToExcel_conversion tool<br>arcpy.TableToExcel_conversion(table_name, excel_output)<br><br>print(&quot;Finish&quot;)</pre><p><strong>2. The second way of exporting to Excel is to use the pandas library.</strong></p><p>It is part of the built-in Python libraries that comes with ArcGIS Pro.</p><p>We import the libraries we will use.<br> <strong>import arcpy<br> import pandas as pd</strong></p><p>Let’s set a workspace to the file database from which we will read arcpy.env.workspace.<br> We name the feature class or table <strong>table_name = “Roads”</strong>.<br> We read the names of the fields that will be saved in Excel <strong>fields = [field.name for field in arcpy.ListFields(table_name)]</strong>.<br> We loop through the fields to get their values with <strong>data = [row for row in arcpy.da.SearchCursor(table_name, fields)]</strong>.<br> We create a data frame in a format read by the pandas library <strong>df = pd.DataFrame(data, columns=fields)</strong>.<br> We set the path to the workspace where we will save the output excel <strong>excel_output = r”C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx”.format(table_name)</strong>.<br> We save the pandas data frame in an excel file <strong>df.to_excel(excel_output, index=False)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2yT2YKJyBnm5wLXm-k7sEw.png" /></figure><p>Let’s execute the code and examine the results.<br>We get an Excel file. As you can see the output excel differs from the previous example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*AybtQ1dLKPQa8xA9DgzmvQ.png" /></figure><p>In addition to the main attribute fields, there is also an additional field containing the geometry of the objects.<br>Since the path class represents linear objects, the result is the center of the path described by coordinates.<br>Let’s take a look at the full code we used to do the export.</p><pre>import arcpy<br>import pandas as pd<br><br># Set the workspace (folder where your geodatabase is located)<br>arcpy.env.workspace =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb&quot;<br><br># Specify the table you want to export<br>table_name = &quot;Roads&quot;<br><br># Get the field names<br>fields = [field.name for field in arcpy.ListFields(table_name)]<br><br># Use a cursor to get the data<br>data = [row for row in arcpy.da.SearchCursor(table_name, fields)]<br><br># Convert the data to a pandas DataFrame<br>df = pd.DataFrame(data, columns=fields)<br><br># Specify the output Excel file path<br>excel_output =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx&quot;.format(table_name)<br><br># Export the DataFrame to an Excel file<br>df.to_excel(excel_output, index=False)<br><br>print(&quot;Finish&quot;)</pre><p><strong>3. The third way is to use the openpyxl library</strong></p><p>This module is part of the standard Python package openpyxl, included with ArcGIS Pro. The openpyxl module for working with excel files has great possibilities for modifying excel. Let’s add the openpyxl module.<br> Let’s set up a workspace to the geodatabase from which we will export with <strong>arcpy.env.workspace</strong>.<br> Let’s name the feature class or table with <strong>table_name = “Roads”</strong>.<br> Let’s get the names of all the fields <strong>fields = [field.name for field in arcpy.ListFields(table_name)]</strong>.<br> Let’s loop through the values of these fields <strong>data = [row for row in arcpy.da.SearchCursor(table_name, fields)]</strong>.<br> Let’s create a new excel worksheet and activate it <strong>workbook = Workbook()<br> sheet = workbook.active</strong>. Let’s write the names of the fields in columns:</p><pre>for col_num, field_name in enumerate(fields, 1):<br>   sheet.cell(row=1, column=col_num, value=field_name)</pre><p>and in the rows the corresponding values</p><pre>for row_num, row_data in enumerate(data, 2):<br> for col_num, value in enumerate(row_data, 1):<br>     formatted_value = str(value) if isinstance(value, tuple) else value<br>     sheet.cell(row=row_num, column=col_num, value=formatted_value).</pre><p>Let’s save the path to the workspace</p><p><strong>excel_output = r”C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx”.format(table_name)</strong>.</p><p>Let’s save the changes in the Excel file <strong>workbook.save(excel_output)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*D2p0rrjcUoMrecmdYKdttQ.png" /></figure><p>The output in excel looks the same as with the pandas module. Here again names information about the geometry stored by coordinates in the Shape fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*wT-bg_Lwca4oSRtXmKbKGw.png" /></figure><p>And the full code we used.</p><pre>import arcpy<br>from openpyxl import Workbook<br><br># Set the workspace (folder where your geodatabase is located)<br>arcpy.env.workspace =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\GDB_to_Excel.gdb&quot;<br><br><br># Specify the table you want to export<br>table_name = &quot;Roads&quot;<br><br># Get the field names<br>fields = [field.name for field in arcpy.ListFields(table_name)]<br><br># Use a cursor to get the data<br>data = [row for row in arcpy.da.SearchCursor(table_name, fields)]<br><br># Create a new Excel workbook and get the active sheet<br>workbook = Workbook()<br>sheet = workbook.active<br><br># Write the field names as headers<br>for col_num, field_name in enumerate(fields, 1):<br>    sheet.cell(row=1, column=col_num, value=field_name)<br><br># Write the data to the Excel sheet<br>for row_num, row_data in enumerate(data, 2):<br>    for col_num, value in enumerate(row_data, 1):<br>        formatted_value = str(value) if isinstance(value, tuple) else value<br>        sheet.cell(row=row_num, column=col_num, value=formatted_value)<br><br><br># Specify the output Excel file path<br>excel_output =<br>r&quot;C:\GISProject\GISBlog\Tools_Projects\GDB_to_Excel\{}.xlsx&quot;.format(table_name)<br><br># Save the workbook to the specified Excel file<br>workbook.save(excel_output)<br>print(&quot;Finish&quot;)</pre><p><a href="https://medium.com/@kalin_85212/2-ways-to-import-excel-to-database-with-python-ebd50e7d65a7">2 ways to import excel to database with python</a></p><h4>Conclusions</h4><p>The choice between pandas and openpyxl depends on the specific requirements of your task.<br> If your goal is primarily data manipulation, analysis, and you are dealing with large datasets, pandas is often the preferred choice.<br> If you need to focus on Excel file I/O and formatting within an ArcGIS environment or for simpler tasks, openpyxl may be more suitable.<br> In some cases, you may even use both libraries together for their respective strengths.</p><p>For more, please visit our blog dedicated to automation at АrcGIS Pro.</p><p><a href="https://gisgp.com/blog/3_ways_to_export_geodatabase_to_excel_with_python_in_arcgispro-8.html">3 ways to export geodatabase to excel with python in ArcGIS Pro</a></p><p>You can discover my new project at <a href="http://www.gisgp.com/">www.gisgp.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34dd21477913" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add custom message with python to modelbuilder?]]></title>
            <link>https://medium.com/@kalin_85212/how-to-add-custom-message-with-python-to-modelbuilder-eccb62e84514?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/eccb62e84514</guid>
            <category><![CDATA[geoprocessing]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <category><![CDATA[model-builder]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 12:26:56 GMT</pubDate>
            <atom:updated>2026-05-28T14:56:48.110Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, model builders do not provide all the necessary information about the processes they perform. Let’s explore how to add useful information for the user and modify the messages output from geoprocessing. This way, we will be able to extract information from each instrument performed separately. In this post, we’ll explore the process.</p><p>In the first step to star ArcGIS Pro and create a new Python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*nVbGc1SgycaQ7nA9aRz_ng.png" /></figure><p>Add a name to the script by right-clicking and selecting ‘Properties,’ similar to ModelBuilder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*PsrI3MTYB_NZamvIqyEesA.png" /></figure><p>Now, select the ‘Execution’ button. There is pre-created code in the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*lkslRS5SlM14YgmoWO6sJw.png" /></figure><p>Since we are going to create our logic, highlight and delete all the code in this window.</p><p>It’s time to write some code.</p><pre>import arcpy<br>mb_message = arcpy.GetParameterAsText(0)<br>my_text = arcpy.GetParameterAsText(1)</pre><p>Now, let’s add them as messages to the geoprocessing window.</p><pre>arcpy.AddMessage(mb_message)<br>arcpy.AddMessage(my_text)</pre><p>To save the changes, select ‘OK.’ <br>Open the window again and go to the parameters. There, set the two parameters that you want to display in the user interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*4n_Q55Gw2X6FI7WdV7T2jw.png" /></figure><p>Now, it’s time to set the parameter types and whether they are required to be entered. Configure them as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*jpTkISE1uPoltTGxv2lVAQ.png" /></figure><p>Close the window with ‘OK,’ and it’s time for a test.</p><p>Open geoprocessing and enter an example text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*kBiqe0_8OW9MXXYEVvZLRw.png" /></figure><p>Choose ‘RUN’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*L1tI0HzgZg_mD0ZEVY5Eig.png" /></figure><p>Open ‘View Details’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*WzbFtDRSX3vLzBknQObcmw.png" /></figure><p>You will see the correctly entered text. Now, it’s time to embed our tool in ModelBuilder. <br> For this purpose, I will use already made models.</p><p>For more info:</p><p><a href="https://medium.com/@kalin_85212/how-to-automatically-add-a-field-to-all-classes-in-gdb-with-the-ability-to-change-parameters-in-1e24f1e20ffa">How to automatically add a field to all classes in gdb with the ability to change parameters in…</a></p><p>Pull in the model ‘Add multiple fields to DB’ and ‘Add Messages’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*34KzeAzKmdadeH4msn8YEQ.png" /></figure><p>Link to the rest of the model elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*ZwWnrQoD8NtO8M4ekNjFvQ.png" /></figure><p>Similar to ‘my_text,’ add an additional annotation, such as ‘File named %Name% has been read and added to GDB’.</p><p>Validate and save the model, then run it. <br> The output should display each added element along with our custom message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*ga63rxApGa2RSo2HTFvzOQ.png" /></figure><p>For greater clarity, add the message output to one more model. This is the pattern to delete a field from all layers in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*Jt78oL3NG9I5gCdbFJot9Q.png" /></figure><p>For more info:</p><p><a href="https://medium.com/@kalin_85212/how-to-automatically-remove-a-field-by-name-for-all-classes-in-gdb-with-arcgis-pro-and-modelbuilder-f316e2aa0e2b">How to automatically remove a field by name for all classes in gdb with ArcGIS Pro and modelbuilder?</a></p><p>The messages of this model are rather vague and do not contain information about the operation performed. They currently look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*sI3Vrm33k1Gqa4sBJ0tRQQ.png" /></figure><p>With the addition of our script, we will add more clarity to them. Add our custom block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*bkO9iYe9PmUTIVHqslVkIQ.png" /></figure><p>Connect it to the output of the delete operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*rIiCSoPoD4rf-ER0anWCBA.png" /></figure><p>Also, add the ‘my_text’ parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*eB-N2QGk4zngGZszEwmhSQ.png" /></figure><p>Edit the text so that it carries more information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*0_Hp5nJB_mk_C0-755ShmA.png" /></figure><p>Validate, save, and run our model.</p><p>Review the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*u-TDsOLvYiMoLxCs3yosgw.png" /></figure><p>Much more information about the user is now displayed. <br>In the following posts, we will see how to save this information in a log file locally on the computer.</p><p>You can discover my new project at <a href="http://www.gisgp.com/">www.gisgp.com</a></p><p><a href="https://gisgp.com/blog/blogIndex.html">GISGP</a></p><p>Thanks for your attention, for more posts subscribe to our newsletter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eccb62e84514" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up a workspace programmatically with python?]]></title>
            <link>https://medium.com/@kalin_85212/how-to-set-up-a-workspace-programmatically-with-python-bb7ce6988dfe?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb7ce6988dfe</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 12:21:36 GMT</pubDate>
            <atom:updated>2026-05-28T14:57:09.487Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is arcgis pro Workspace and when to use it?</h3><p>In ArcGIS Pro, a workspace refers to the location or environment where you store and manage your geographic data. There are several types of workspaces in ArcGIS Pro, each serving a specific purpose. Here are some common types of workspaces:</p><ol><li>File Geodatabase Workspace.</li><li>Enterprise Geodatabase Workspace.</li><li>Folder Workspace.</li><li>Raster Workspace.</li><li>Toolbox Workspace.</li><li>Catalog View Workspace.</li><li>Database Connection Workspace.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*iMAWYjiQfuo6akmWy8PVOQ.png" /></figure><p><strong>File Geodatabase Workspace:</strong> <br> <strong>Description:</strong> A file geodatabase is a folder on disk that can store various types of geographic data, such as feature classes, tables, and raster datasets. <br> <strong>Use Case:</strong> Suppose you are working on a city planning project. You can create a file geodatabase to store various datasets such as streets (feature class), zoning information (table), and satellite imagery (raster dataset) in an organized manner. This allows you to maintain relationships between different types of data within the geodatabase.</p><pre>  import arcpy<br><br>  # Set the path to the file geodatabase<br>  fgdb_path = r&#39;C:\Path\To\Your\FileGeodatabase.gdb&#39;<br><br>  # List all feature classes in the file geodatabase<br>  feature_classes = arcpy.ListFeatureClasses(&#39;&#39;, &#39;&#39;, fgdb_path)<br>  for fc in feature_classes:<br>      print(fc)</pre><p><strong>Enterprise Geodatabase Workspace:</strong> <br> <strong>Description:</strong> An enterprise geodatabase is a multiuser geodatabase stored in a relational database management system (RDBMS) like Oracle, SQL Server, or PostgreSQL. <br> <strong>Use Case:</strong> In a large organization, multiple users need to collaborate on editing a city’s infrastructure data simultaneously. An enterprise geodatabase, hosted on a database server like SQL Server, can provide a shared environment for users to edit and manage data while maintaining data integrity.</p><pre>import arcpy<br><br># Create a connection to the enterprise geodatabase<br>arcpy.env.workspace = &#39;Database Connections\YourEnterprise.sde&#39;<br><br># List all feature classes in the enterprise geodatabase<br>feature_classes = arcpy.ListFeatureClasses()<br>for fc in feature_classes:<br>    print(fc)</pre><p><strong>Folder Workspace:</strong> <br> <strong>Description:</strong> A regular folder on disk that can store shapefiles, raster datasets, and other types of GIS files. <br> <strong>Use Case:</strong> For a small research project, you might have shapefiles representing different species distributions, stored in a simple folder structure. A folder workspace is an easy way to manage and organize these files without the need for a geodatabase.</p><pre>import arcpy<br><br># Set the path to the folder<br>folder_path = r&#39;C:\Path\To\Your\Folder&#39;<br><br># List all shapefiles in the folder<br>shapefiles = arcpy.ListFeatureClasses(&#39;*.shp&#39;, &#39;&#39;, folder_path)<br>for shp in shapefiles:<br>    print(shp)</pre><p><strong>Raster Workspace:</strong> <br> <strong>Description:</strong> A location where raster datasets are stored. Raster workspaces can point to folders, geodatabases, or cloud-based storage. <br> <strong>Use Case:</strong> Let’s say you’re working on a project that involves analyzing satellite imagery for land cover change detection. You can create a raster workspace to organize and manage the various raster datasets representing different time periods or spectral bands.</p><pre> import arcpy<br><br># Set the path to the raster workspace<br>raster_workspace = r&#39;C:\Path\To\Your\RasterWorkspace&#39;<br><br># List all raster datasets in the workspace<br>raster_datasets = arcpy.ListRasters(&#39;&#39;, &#39;ALL&#39;, raster_workspace)<br>for raster in raster_datasets:<br>    print(raster)</pre><p><strong>Toolbox Workspace:</strong> <br> <strong>Description:</strong> A workspace associated with a toolbox, which is a collection of geoprocessing tools and models. <br> <strong>Use Case:</strong> You have developed a set of custom geoprocessing tools and models to automate a series of spatial analyses. By creating a toolbox workspace, you can organize and store these tools in a way that is easily accessible within ArcGIS Pro, streamlining your workflow.</p><pre>import arcpy<br><br># Set the path to the toolbox<br>toolbox_path = r&#39;C:\Path\To\Your\Toolbox.tbx&#39;<br><br># List all tools in the toolbox<br>tools = arcpy.ListTools(&#39;*_*&#39;, toolbox_path)<br>for tool in tools:<br>    print(tool)</pre><p><strong>Catalog View Workspace:</strong> <br> <strong>Description:</strong> The Catalog view in ArcGIS Pro allows you to browse, manage, and organize your data, and it operates as a workspace when you interact with it. <br> <strong>Use Case:</strong> When working on a regional analysis project, you can use the Catalog view to navigate through your data, add layers to your map, and manage connections to various workspaces. The Catalog view acts as a workspace within the ArcGIS Pro interface, facilitating data exploration and management.</p><pre>import arcpy<br><br># No specific code for Catalog View as it is part of the ArcGIS Pro interface.<br><br># You can use the Catalog view interactively within ArcGIS Pro.</pre><p><strong>Database Connection Workspace:</strong> <br> <strong>Description:</strong> A connection to a database system, such as SQL Server or Oracle, allowing you to access and work with data stored in that database. <br> <strong>Use Case:</strong> Your organization stores its infrastructure data in an external Oracle database. By creating a database connection workspace, you can seamlessly access and work with this data in ArcGIS Pro without the need to import it into the project. This ensures that you are always working with the most up-to-date information.</p><pre>    import arcpy<br><br>    # Create a connection to the database<br>    arcpy.env.workspace = &#39;Database Connections\YourDatabase.sde&#39;<br><br>    # List all feature classes in the database<br>    feature_classes = arcpy.ListFeatureClasses()<br>    for fc in feature_classes:<br>        print(fc)</pre><p>These examples showcase how different types of workspaces in ArcGIS Pro can be applied to various scenarios, providing users with the flexibility to choose the most appropriate workspace for their specific GIS projects. <br> These code snippets demonstrate basic operations such as listing datasets within each workspace type. You can further customize these examples based on your specific requirements, such as data analysis, editing, or data management tasks.</p><p>The geoprocessing environment settings in ArcGIS provide a way to control the behavior of geoprocessing tools and functions. These settings influence how tools execute and how they interact with the data. Here’s an overview of some key geoprocessing environment settings:</p><p><strong>Current Workspace (arcpy.env.workspace):</strong></p><p><strong>Purpose:</strong> Specifies the default workspace for geoprocessing tools. The workspace can be a folder, file geodatabase, or enterprise geodatabase.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.workspace = r&#39;C:\Path\To\Your\Workspace&#39;</pre><p><strong>Output Coordinate System (arcpy.env.outputCoordinateSystem):</strong></p><p><strong>Purpose:</strong> Defines the coordinate system for output datasets. Ensures consistency in spatial reference among output datasets.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(4326)<br># WGS 1984</pre><p><strong>Scratch Workspace (arcpy.env.scratchWorkspace):</strong></p><p><strong>Purpose:</strong> Specifies the location where temporary data is stored during geoprocessing. Useful for managing intermediate data.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.scratchWorkspace = r&#39;C:\Path\To\Your\ScratchWorkspace&#39;</pre><p><strong>Extent (arcpy.env.extent):</strong></p><p><strong>Purpose:</strong> Defines the processing extent for geoprocessing tools. Limits the analysis to a specific geographic area.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.extent = &#39;MAXOF&#39;<br># Use the maximum extent of input datasets</pre><p><strong>Cell Size (arcpy.env.cellSize):</strong></p><p><strong>Purpose:</strong> Sets the default cell size for raster analysis. Controls the granularity of raster output.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.cellSize = 30<br># Set cell size to 30 meters</pre><p><strong>Mask (arcpy.env.mask):</strong></p><p><strong>Purpose:</strong> Limits the processing extent of tools to a specific area defined by a mask. Useful for focusing analyses on specific regions.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.mask = r&#39;C:\Path\To\Your\Mask.shp&#39;</pre><p><strong>Output Coordinate Format (arcpy.env.outputCoordinateFormat):</strong></p><p><strong>Purpose:</strong> Specifies the coordinate format for output feature classes and tables.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.outputCoordinateFormat = &#39;DMS&#39;<br># Degrees, Minutes, Seconds</pre><p><strong>Output M Resolution (arcpy.env.outputMResolution) and Output Z Resolution (arcpy.env.outputZResolution):</strong></p><p><strong>Purpose:</strong> Sets the resolution for M (measure) and Z (elevation) values in output feature classes.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.outputMResolution = 0.01<br># Set M resolution to 0.01</pre><p><strong>Output Coordinate Precision (arcpy.env.outputCoordinatePrecision):</strong></p><p><strong>Purpose:</strong> Specifies the number of decimal places for coordinates in output datasets.</p><p><strong>Example:</strong></p><pre>import arcpy<br>arcpy.env.outputCoordinatePrecision = 6<br># Set coordinate precision to 6 decimal places</pre><p>These geoprocessing environment settings allow you to customize the behavior of tools to suit the specific requirements of your GIS analysis. They are particularly useful when you want to ensure consistency in data processing, manage temporary data effectively, and control the spatial characteristics of your output datasets.</p><p>You can discover my new project at <a href="http://www.gisgp.com/">www.gisgp.com</a></p><p><a href="https://gisgp.com/blog/blogIndex.html">GISGP</a></p><p>Thanks for your attention, for more posts subscribe to our newsletter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb7ce6988dfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check with python if a field is available in geodatabase (gdb)?]]></title>
            <link>https://medium.com/@kalin_85212/how-to-check-with-python-if-a-field-is-available-in-gdb-ae317802c5c4?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae317802c5c4</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 14:53:54 GMT</pubDate>
            <atom:updated>2024-02-04T08:10:07.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to check with python if a field is available in geodatabase (gdb)?<br>Which classes have a field and which ones don’t?</h4><p>ESRI has provided a tool that generates a file database description.</p><p>The description itself is extremely useful and we will look at it in more detail in one of the following posts. Now, we’ll use it to answer our questions.</p><p>The tool is called Generate Excel From Geodatabase.</p><p>We attach a link to <a href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/topographic-production/generate-excel-from-geodatabase.htm">help</a></p><p>In the Excel table generated by this tool, descriptions of classes and their fields, as well as a set of additional information, are available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*PcWICU_T67QAVCXhdUGSbA.png" /><figcaption>Since an additional license is required, which in my case is not available, we will have to make our own tool that returns the necessary information</figcaption></figure><p>Let’s start at the first step, we will create a new notebook. This is done by selecting the Analysis tab from the Python button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*wv5egGaTroKQRtp2L2ncKw.png" /></figure><p>We will use the arcpy.ListFields function from the ESRI library. In the window we add the following code. Which returns all the fields of a particular feature class.</p><pre>import arcpy<br><br>              featureclass = r&quot;C:\GISProject\GISBlog\Tools_Projects\MD_add_fields\AddFields.gdb\ne_10m_admin_0_map_units&quot;<br><br>              field_names = [f.name for f in arcpy.ListFields(featureclass)]<br><br>              print(field_names)</pre><p>The result of our code is a list of fields <br> [‘OBJECTID’, ‘Shape’, ‘scalerank’, ‘featurecla’, ‘Shape_Length’, ‘Shape_Area’, ‘Name_EN’] in this list. <br> The output fields are only for one feature class and that is the „ne_10m_admin_0_map_units“ class. <br> Now we need a list of all feature classes. <br> For this purpose, we will use arcpy‘s ListFeatureClasses function in the following code.</p><pre><br>                import arcpy<br>                import os<br><br>                arcpy.env.workspace = r“..\AddFields.gdb“<br>                datasets = arcpy.ListDatasets(feature_type=‘feature‘)<br>                datasets = [‚‘] + datasets if datasets is not None else []<br><br>                for ds in datasets:<br>                  for fc in arcpy.ListFeatureClasses(feature_dataset=ds):<br>                    path = os.path.join(arcpy.env.workspace, ds, fc)<br>                    print(path)</pre><p>We‘ve flagged the code from the previous step to not run. The output of this code is to print a list of all the classpaths available in the database. <em>..\AddFields.gdb\ne_10m_admin_0_antarctic_claim_limit_lines ..\AddFields.gdb\ne_10m_admin_0_antarctic_claims ..\AddFields.gdb\ne_10m_admin_0_boundary_lines_disputed_areas ..\AddFields.gdb\ne_10m_admin_0_boundary_lines_land ..\AddFields.gdb\ne_10m_admin_0_boundary_lines_map_units ..\AddFields.gdb\ne_10m_admin_0_boundary_lines_maritime_indicator ..\AddFields.gdb\ne_10m_admin_0_countries</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*qJIH2m_ZFSlDkEJ7ikO2Dw.png" /></figure><p>Now we need to merge the two pieces of code, the part that reads the fields in a class and the part that reads all available classes from GDB.</p><p>This is done by using the output from the ListFeatureClasses traversal of feature class names and making it input to ListFields.</p><pre>   import arcpy<br>            import os<br><br>            arcpy.env.workspace = r“..\AddFields.gdb“<br><br>            datasets = arcpy.ListDatasets(feature_type=‘feature‘)<br>            datasets = [‚‘] + datasets if datasets is not None else []<br><br>            for ds in datasets:<br>              for fc in arcpy.ListFeatureClasses(feature_dataset=ds):<br>                path = os.path.join(arcpy.env.workspace, ds, fc)<br>                print(path)<br>                field_names = [f.name for f in arcpy.ListFields(path)]<br>                print(field_names)</pre><p>Let‘s see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*MeXkyKbSpVNgWPir3JZlsA.png" /></figure><p>As you can see this list returns all the fields but we are looking for a specific field by name. The question remains, how to display only feature classes in which the field “Name_EN.</p><p>For this purpose, we will add a check.</p><h4>If search_feeld_name in field_names:</h4><p>This check, we will combine it with the rest of the functions. We will also add an explanatory text for the name of the field we are looking for as well as the class in which it is located.</p><pre> import arcpy<br> import os<br><br>search_feeld_name = &#39;Name_EN&#39;<br>arcpy.env.workspace = r&quot;..AddFields.gdb&quot;<br><br>datasets = arcpy.ListDatasets(feature_type=&#39;feature&#39;)<br>datasets = [&#39;&#39;] + datasets if datasets is not None else []<br><br>for ds in datasets:<br>    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):<br>        path = os.path.join(arcpy.env.workspace, ds, fc)<br>#         print(path)<br>        field_names = [f.name for f in arcpy.ListFields(path)]<br>#         print(field_names)<br>        if search_feeld_name in field_names:<br>            print(f&quot;field {search_feeld_name} <br>exist in feature class: {path}&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*axvZBKXaVZdVtdU1af2NFw.png" /></figure><p>If we want to check the classes in which a field is missing, then this is quite easy.</p><pre>import arcpy<br>import os<br><br>search_feeld_name = &#39;Name_EN&#39;<br>arcpy.env.workspace = r&quot;..\AddFields.gdb&quot;<br><br>datasets = arcpy.ListDatasets(feature_type=&#39;feature&#39;)<br>datasets = [&#39;&#39;] + datasets if datasets is not None else []<br><br>for ds in datasets:<br>    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):<br>        path = os.path.join(arcpy.env.workspace, ds, fc)<br>#         print(path)<br>        field_names = [f.name for f in arcpy.ListFields(path)]<br>#         print(field_names)<br>        if search_feeld_name in field_names:<br>#           print(f&quot;field {search_feeld_name} exist in feature class: {path}&quot;)<br>             pass<br>        else:<br>            print(f&quot;field {search_feeld_name} <br>don&#39;t exist in feature class: {path}&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*mV383zQ35WEtRfzhzq78ew.png" /></figure><p>If we want to save this information in an additional file, we can do so. We use the built-in functionality in python f.write, where f is a parameter for the file path and the reading mode in which it is used.</p><p>This is all the code we created.</p><pre>import arcpy<br>import os<br><br>search_feeld_name = &#39;Name_EN&#39;<br>f = open(r&quot;C:\GISProject\GISBlog\checkfieldname.txt&quot;, &quot;a&quot;)<br>arcpy.env.workspace = r&quot;..\AddFields.gdb&quot;<br><br>datasets = arcpy.ListDatasets(feature_type=&#39;feature&#39;)<br>datasets = [&#39;&#39;] + datasets if datasets is not None else []<br><br>for ds in datasets:<br>    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):<br>        path = os.path.join(arcpy.env.workspace, ds, fc)<br>#         print(path)<br>        field_names = [f.name for f in arcpy.ListFields(path)]<br>#         print(field_names)<br>        if search_feeld_name in field_names:<br>#           print(f&quot;field {search_feeld_name} exist in feature class: {path}&quot;)<br>             pass<br>        else:<br>            print(f&quot;field {search_feeld_name} don&#39;t exist in feature class: {path}&quot;)<br>            f.write(f&quot;field {search_feeld_name} don&#39;t exist in feature class: {path}&quot;)<br>            f.write(&quot;\n&quot;)<br>f.close()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*NcLhFdzcuSgsTlPWm7r9ww.png" /></figure><p>Here is what the text file we created contains, or is it a list of all layers in which our field is not present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*Dnr-DBHz5gKbNqGlGjZEWg.png" /></figure><p>If we want to display a list of all layers in which the field is available, we must use it.</p><h4>if search_feeld_name in field_names:</h4><p>Let‘s do it by setting a new file name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*KnKCkF6ZWWVZZWu2etiq-Q.png" /></figure><p>Let’s review the result file, as these are all feature classes in which the field with the given name is present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*WX6V3RBRnFFv22eJhVTXyA.png" /></figure><p>That’s what this post is for in the future, we’ll look at how we can build on this functionality and use it in custom tools.</p><p>Thanks for your attention, for more posts subscribe to our newsletter.</p><p>For more, please visit our blog dedicated to automation at АrcGIS Pro.</p><p><a href="https://gisgp.com/blog/How-to-check-if-a-field-is-available-in-GDB-5.html">In which classes is a field present and in which classes is it missing?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae317802c5c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automatically remove a field by name for all classes in gdb with ArcGIS Pro and modelbuilder?]]></title>
            <link>https://medium.com/@kalin_85212/how-to-automatically-remove-a-field-by-name-for-all-classes-in-gdb-with-arcgis-pro-and-modelbuilder-f316e2aa0e2b?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f316e2aa0e2b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[geoprocessing]]></category>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Thu, 18 Jan 2024 10:21:34 GMT</pubDate>
            <atom:updated>2024-02-04T08:11:32.217Z</atom:updated>
            <content:encoded><![CDATA[<p>Database management work can sometimes feel like navigating a maze, especially when faced with the challenge of removing or modifying fields.</p><p>Have you ever had to add the wrong field to a database? Or do you need to clean additional information from the classes in the DB? Now, let’s see how to delete a particular field from the database.</p><p>We are adding a new model to the toolbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*v4wiCkRVK0POobLfSv8ASA.png" /></figure><p>Select the properties of the new model and fill in a name and caption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*nKiWNHtAM2MNHH1bJguVZA.png" /></figure><p>We save the model to reflect the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*UqYfGmpGZkpHCkoV290OGQ.png" /></figure><p>Now, we need to add class traversal to the model. We will use the same tool that helped us in the model to create the ‘Iterate Feature Classes’ field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*73E1zLchbDw4ZHaybbzxXA.png" /></figure><p>The tool has been added to the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*O0lmZMJuVUwEZgzbSnYlEQ.png" /></figure><p>We will also look for an option to delete a field. From the geoprocessing window, search for ‘Delete field.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*hRO6BMVdBaZfGfuJrD1Mzg.png" /></figure><p>Drag and drop it to add it to the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*l6zCeI-nxquFY_uhDMpHiA.png" /></figure><p>From the catalog pane, find the database we are working with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*bnyaqG85SX15bWPNx6OAEA.png" /></figure><p>Use drag and drop to add our working database to the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*oKozA348cBXeiXJqnGaHJA.png" /></figure><p>Now, it’s time to add the parameters and connect the elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*m5hZ1pU8lRPygdd3uOnuJA.png" /></figure><p>Add the output of ‘Iterate with Delete field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*tY4kUZAIqNNL6IawdWtyqQ.png" /></figure><p>Double click to open the options for deleting a field. Highlight the ‘Name’ field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*2AoquLzEe1GQ5QFbeiSNvA.png" /></figure><p>Validate and save the model, and it’s time to run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*As2j3j6SvFCS0QnzzdYSqw.png" /><figcaption>Before running the model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*TrHUrW3THgTHaiViJvYLzA.png" /><figcaption>After running the model</figcaption></figure><p>We have seen that our model works successfully. Now it’s time to add parameters to it with the help of which we will be able to reuse it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*QESjXdcFNf95SoaM35g2oA.png" /></figure><p>Also, add a field name as a parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*wvXJ-_Ec-udTaXxzXhU2Qw.png" /></figure><p>I used the create field pattern to re-add the fields we deleted a while ago.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*1Phgo2DsmM_On2OLNMtKTg.png" /></figure><p>Let’s open it from the catalog and review the parameters. This is necessary so that we can see the name of the field that we are actually deleting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*kztQGvTWS4yJEALt0e1bmw.png" /></figure><p>Let’s run it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*FBh3ZOnzlmR9Yo_KYegKNg.png" /></figure><p>After the field is deleted, geoprocessing automatically displays a warning that this field is not available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*5uND4EK1UjfVATbkpTbr6Q.png" /></figure><p>In the following tutorials, we will build on the tools with additional features. For this purpose, we will use Python.</p><p>Thank you for your attention.</p><p>For more, please visit our blog dedicated to automation at АrcGIS pro.</p><p><a href="https://gisgp.com/blog/blogIndex.html">GISGP</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f316e2aa0e2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automatically add a field to all classes in gdb with the ability to change parameters in…]]></title>
            <link>https://medium.com/@kalin_85212/how-to-automatically-add-a-field-to-all-classes-in-gdb-with-the-ability-to-change-parameters-in-1e24f1e20ffa?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e24f1e20ffa</guid>
            <category><![CDATA[gis]]></category>
            <category><![CDATA[model-builder]]></category>
            <category><![CDATA[geoprocessing]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Wed, 17 Jan 2024 12:22:14 GMT</pubDate>
            <atom:updated>2024-01-17T12:22:14.282Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to automatically add a field to all classes in gdb with the ability to change parameters in ArcGIS Pro and modelbuilder.</h3><p>Let’s expand the capabilities of your database with geodata! Imagine effortlessly adding a field to all geodatabase objects with just a few clicks. In this blog post, we dive into the world of Model Builder, revealing the secrets of automating this process. Learn how to systematically integrate a field, along with the correct name, type, and description, into every layer in your database. As we create an empty model and navigate the geoprocessing window, you’ll discover the power of the Add Field tool and witness the magic of iteration with Iterate Feature Classes. With each step, we demystify the process, ensuring your geodatabase grows seamlessly. Join us as we connect tools, parameterize, and validate models, uncovering the ins and outs of Model Builder. Stay tuned for the next post where we’ll explore field deletion, delve into table dynamics, and even touch on implementing this functionality in Python. Up your geodata game and revolutionize your GIS workflow!</p><p>Assume you’ve had to add the same field to all geodatabase objects.</p><p>Let’s explore how we can automate this process with Model Builder. We’ll learn how to systematically add a field with the corresponding name, type, and description to all layers in the database.</p><p>At this point, we have an empty model and a functional geographic database with a set of files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*t0HZr-Hlt_ldOtZBtQ_ONw.png" /></figure><p>Let’s create an empty model.</p><p>Right-click on Add_fields.atbx and select “New Model.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*jqgRSli-AMZYKl1t0QvCDw.png" /></figure><p>From the geoprocessing window, let’s find the “Add Field” tool to introduce a new field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*lTEU8PlHBod9zTdgiGAN9w.png" /></figure><p>After selecting it, populate a class with the field name, type, and length.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*GgV7rLSNKpJl49kRoGSyWg.png" /><figcaption>Run the geoprocessing and review the results</figcaption></figure><p>In the attribute table of the layer, observe that our field has been successfully added. In this case, with numerous classes in the database, let’s explore automating the process to avoid manual execution for each class. For this purpose, let’s transition to the Model Builder. The first requirement is to traverse all classes in the database. As you can see, there are various options for this purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*Css7rFouNfeBTnEDLJxMbQ.png" /></figure><p>We will utilise “Iterate Feature Classes”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*QBUBbR-3UWalGjRcSwVoRQ.png" /></figure><p>After adding it to the model, the tool appears inactive (highlighted in grey). This is because we need to set the parameters by adding our working database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*wDmKVhn68tFqfiVaJeYjOw.png" /></figure><p>Upon selecting “Ok,” the tool is validated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*xYCkRWt9mSHkIplfzaHoXg.png" /></figure><p>Validate, save, and run the model to see the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*r2RUGVk6y8IdZvbQwDQkTQ.png" /></figure><p>Check the messages from the class crawl in the database; they will resemble this format:</p><p><em>Model</em></p><p><em>=====================</em></p><p><em>Parameters</em></p><p><em>=====================</em></p><p><em>Messages</em></p><p><em>Start Time: 20 November 2023 17:37:29</em></p><p><em>Executing (Iterate Feature Classes): IterateFeatureClasses C:\GISProject\GISBlog\Tools_Projects\MD_add_fields\AddFields.gdb # # NOT_RECURSIVE</em></p><p><em>Start Time: 20 November 2023 17:37:29</em></p><p><em>Succeeded at 20 November 2023 17:37:30 (Elapsed Time: 0.81 seconds)</em></p><p><em>Executing (Iterate Feature Classes): IterateFeatureClasses C:\GISProject\GISBlog\Tools_Projects\MD_add_fields\AddFields.gdb # # NOT_RECURSIVE</em></p><p><em>Start Time: 20 November 2023 17:37:30</em></p><p><em>Succeeded at 20 November 2023 17:37:30 (Elapsed Time: 0.04 seconds)</em></p><p><em>Executing (Iterate Feature Classes): IterateFeatureClasses C:\GISProject\GISBlog\Tools_Projects\MD_add_fields\AddFields.gdb # # NOT_RECURSIVE</em></p><p><em>Start Time: 20 November 2023 17:37:30</em></p><p>At this point, we can traverse objects in the database. Now, let’s add a field to them. In the Geoprocessing History, observe the tools implemented so far in the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*rG6QMYHh-pyYN3CYfVjSxw.png" /></figure><p>As we’ve been using the “Add Field” tool, let’s incorporate it into our model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*s6Z6SyZO6yeHRZGH30Qvbw.png" /></figure><p>Connect it to the crawl and set the right parameters.</p><p>Delete the block with blue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/1*pejJSTXHRyk_azFJDizNkA.png" /></figure><p>of the work class from the previous step and replace it with the green block</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*u1p4byYNbZRTzAWMbpetxQ.png" /></figure><p>Wire the crawl output to be the field add input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*ZLjc0C692Z0APzKCdYAdRA.png" /></figure><p>Now, validate, save, and run the tool, reviewing the output. Steps must be repeated during execution, indicating that a class is read, and the field is added, then the next class, and so forth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*9qF3sU_AeZYWWajFbQbQsg.png" /></figure><p>Review the result on the map. A new field has been added to the attribute table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*85yk7lzNn-5qKYdVxc1zMQ.png" /><figcaption><em>Note: You may need to reload the data from the database to display the new field</em></figcaption></figure><p>It’s also possible to add an input DB parameter so that this approach can be applied to a new DB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*IJL07pfB7xh8vAi5SCyNxg.png" /></figure><p>Validate and save the model. Run it as a custom geoprocessing.</p><p>Select the model from the catalog window, and double-click to open it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*o2rg59weeJZoykCCDdM2mw.png" /></figure><p>Notice there is no description of the model’s purpose. Let’s add that. Right-click and select Properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*CilPveZQ1puufxs3nlx3mQ.png" /></figure><p>Add the name “AddMultipleFields” and the description “Add multiple fields to DB.” Save the model to reflect the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*JzXENirAQ3JrS5spmfeJiQ.png" /></figure><p>Let’s start it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*DbEgWfLN2KxfCi-E5mL3zA.png" /></figure><p>To maximize this model’s utility, add a few more parameters, specifically field type parameters</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*xoyIvfuG6uYL1qcWSSv33A.png" /></figure><p>Right-click on the “Add Field”, tool, and add Field Name, Type, Length, and Alias.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*14liFO5dPIUPjYnGZyQAkw.png" /></figure><p>Rearrange them automatically with the Auto Layout option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/110/1*iw4ieVEKejNUkZc2EKe5dQ.png" /></figure><p>The model now appears organized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*CHh403d9shYjR19boHlR3g.png" /></figure><p>Now, create parameters from the field characteristics. Validate and save; review the new parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*62HEOO08OIzRd3kjeUXZEg.png" /></figure><p>If you want to add a new field, simply add its parameters.</p><p>In the next post, we will explore how to delete fields by name from the DB. Also, for working with tables, a different approach to creating fields will be needed.</p><p>Finally, we’ll see how to implement this functionality in Python.</p><p><a href="https://gisgp.com/blog/blogIndex.html">GISGP</a></p><p>Thanks for your attention, for more posts subscribe to our newsletter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e24f1e20ffa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create file geodatabase (gdb) with python?]]></title>
            <link>https://medium.com/@kalin_85212/how-to-create-file-geodatabase-gdb-with-python-how-to-use-gdb-in-python-b150be940675?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b150be940675</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[arcgis]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Mon, 15 Jan 2024 18:31:32 GMT</pubDate>
            <atom:updated>2024-02-04T08:08:36.313Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use gdb in python?</h3><p>Let’s start with a few lines about what GDB is and what it is used for.</p><p>In ArcGIS Pro, a geodatabase (geographic database) is a container for storing and managing spatial and non-spatial data. It provides a way to organize and structure your data within the ArcGIS platform. Geodatabases support the storage of various types of geographic data, including features, attributes, relationships, topologies, and more. They play a crucial role in managing and analyzing spatial information efficiently.</p><p>There are two main types of geodatabases in ArcGIS Pro:</p><p>File Geodatabase (FGDB): This is a single-user geodatabase that is stored as a folder in the file system. It is suitable for small to medium-sized projects and is a good choice when you don’t need to support multi-user editing or complex data relationships. File geodatabases are fast and efficient for read and write operations.</p><p>Enterprise Geodatabase: This type of geodatabase is designed for multi-user editing and collaboration within an enterprise environment. It is typically stored in a relational database management system (RDBMS) such as Microsoft SQL Server, Oracle, PostgreSQL, or SAP HANA. Enterprise geodatabases support advanced geodatabase features like versioning, replication, and geodatabase archiving.</p><p>ArcGIS Pro provides tools and functionality to create, manage, and work with geodatabases. Users can import data into geodatabases, perform geoprocessing operations, create and manage relationships between datasets, and more. Geodatabases are essential for maintaining data integrity, managing complex spatial relationships, and ensuring efficient data retrieval and analysis within the ArcGIS environment.</p><p>If you’re referring to using the Python arcpy module to work with a Geodatabase, you can use functions like arcpy.CreateFileGDB_management to create a Geodatabase, and then various arcpy functions to manage and analyze geospatial data within it.</p><p>In arcpy (the ArcGIS Python site package), you can use the CreateFileGDB_management or CreateEnterpriseGeodatabase_management functions to create a File Geodatabase (FGDB) or an Enterprise Geodatabase, respectively. Below are examples for creating a File Geodatabase.</p><p>Creating a File Geodatabase</p><pre>import arcpy<br><br># Set the workspace (folder) where you want to create the File Geodatabase<br>workspace = r&quot;C:\Path\To\Your\Directory&quot;<br><br># Set the name of the File Geodatabase<br>gdb_name = &quot;YourGeodatabase.gdb&quot;<br><br># Combine the workspace and geodatabase name to get the full path<br>gdb_path = arcpy.os.path.join(workspace, gdb_name)<br><br># Create the File Geodatabase<br>arcpy.CreateFileGDB_management(workspace, gdb_name)<br><br>print(f&quot;File Geodatabase &#39;{gdb_name}&#39; created at: {gdb_path}&quot;)</pre><p>Creating an Enterprise Geodatabase:</p><p>Creating an enterprise geodatabase involves more parameters, as it requires a connection file and connection properties for the underlying relational database management system (RDBMS). Below is a simplified example for creating an enterprise geodatabase on Microsoft SQL Server:</p><pre>import arcpy<br><br># Set the workspace (folder) where you want to create the Connection File<br>workspace = r&quot;C:\Path\To\Your\Directory&quot;<br><br># Set the name of the Connection File<br>connection_file_name = &quot;YourConnectionFile.sde&quot;<br><br># Combine the workspace and connection file name to get the full path<br>connection_file_path = arcpy.os.path.join(workspace, connection_file_name)<br><br># Set the parameters for creating the enterprise geodatabase<br>database_platform = &quot;SQL_SERVER&quot;<br>instance_name = &quot;YourSQLServerInstance&quot;<br>database_name = &quot;YourDatabaseName&quot;<br>account_authentication = &quot;DATABASE_AUTH&quot;<br>username = &quot;YourDBUsername&quot;<br>password = &quot;YourDBPassword&quot;<br>version_type = &quot;TRANSACTIONAL&quot;<br><br># Create the Connection File and Enterprise Geodatabase<br>arcpy.CreateDatabaseConnection_management(workspace, connection_file_name, database_platform,<br>                                          instance_name, account_authentication, username,<br>                                          password, version_type)<br><br>print(f&quot;Enterprise Geodatabase Connection File &#39;{connection_file_name}&#39; created at: {connection_file_path}&quot;)</pre><p>Replace the placeholder values with your specific database connection details.</p><p>Remember to adjust the parameters according to your specific requirements and the RDBMS you are using. The examples provided here are simplified, and you may need to refer to the arcpy documentation for more details on additional parameters and options.</p><p>Let’s take a detailed look at how to actually create a file database with python in ArcGIS Pro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*j_TNosLo6ZU-ZMQxcdVoXw.png" /></figure><p>The output of this code is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*H_9L4NMKH11TvurZ6tr2sQ.png" /></figure><p>A sample of the code we used:</p><pre>import arcpy<br>arcpy.management.CreateFileGDB(<br>    out_folder_path=r&quot;C:\GISProject\GISBlog\Tools_Projects&quot;,<br>    out_name=&quot;Roads&quot;<br>)</pre><p>On the first line, we use a built-in library in ArcGIS Pro called arcpy.</p><p>From this library, we utilize the ‘CreateFileGDB’ function, which is part of the ‘arcpy.Management’ module.</p><p>The function takes two parameters: the path to the workspace where we will create our new database, named “out_folder_path.” In our case, the workspace path is set to r”C:\GISProject\GISBlog\Tools_Projects,” where “r” is a parameter indicating that this constant is a path.</p><p>The next parameter is the name of our file database, with “out_name” serving as the variable name. In this instance, we set the value to “Roads.”</p><p>After running the code with “Run,” let’s check if our working database has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*FXaVvkHOs0gQzZyQXdZZ0Q.png" /><figcaption>Of course our database is empty.</figcaption></figure><p>Let’s add data with python to the file database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*zyg7HpsvJtIj9SCo35h2lA.png" /></figure><p>To load data into the file database, we use the “FeatureClassToGeodatabase” command, which is part of “arcpy.conversion”.</p><p>Let’s check the contents of the file database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*3i-AtAJsszhyYgLbgbfhrg.png" /></figure><p>As you can see, it already contains the shp file we loaded.</p><p>Of course, once we’ve created our Roads file database, we don’t need to run arcpy.management.CreateFileGDB.</p><p>The code we’ve used so far is:</p><pre><br>import arcpy<br>arcpy.management.CreateFileGDB(<br>    out_folder_path=r&quot;C:\GISProject\GISBlog\Tools_Projects&quot;,<br>    out_name=&quot;Roads&quot;<br>)<br>arcpy.conversion.FeatureClassToGeodatabase(<br>    Input_Features=r&quot;C:\GISProject\10m_physical\ne_10m_antarctic_ice_shelves_polys.shp&quot;,<br>    Output_Geodatabase=r&quot;C:\GISProject\GISBlog\Tools_Projects\Roads.gdb&quot;<br>)</pre><p>In this case, it will be useful for us to check if the file database exists in the specified path. If it exists, skip its creation; if it is deleted for some reason, create it again. For this purpose, we will export as parameters the name of the database file as well as the path to the workspace. To work with the operating system, we need the built-in ‘os’ module in Python. With its help, we assemble the full access path to the database file: ‘gdb_path = os.path.join(folder_path, gdb_name)’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*1BCF-lQjAiszZjULiGoCtQ.png" /></figure><p>The result of this which is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*rGWZaP3WEOKnkJL-kpgCIA.png" /></figure><p>If we manually delete the file database “Roads.gdb”</p><p>After executing the code, we will get the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*GNk0IFyLhIYxYSQJKM_qDw.png" /></figure><p>Which means our database is created from scratch.</p><p>Of course it no longer contains the loaded data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*GDFjzfGuITeMCc88wID4KA.png" /><figcaption>If it is not displayed in the catalog, after executing the code, use refresh — F5.</figcaption></figure><p>The code we used to check is:</p><pre>import arcpy<br>import os<br><br>folder_path = r&quot;C:\GISProject\GISBlog\Tools_Projects&quot;<br><br>gdb_name = &quot;Roads.gdb&quot;<br><br>gdb_path = os.path.join(folder_path, gdb_name)<br><br>if not arcpy.Exists(gdb_path):<br>    # If it doesn&#39;t exist, create the geodatabase<br>    arcpy.management.CreateFileGDB(folder_path, gdb_name)<br>    print(f&quot;Geodatabase {gdb_name} created.&quot;)<br>else:<br>    print(f&quot;Geodatabase {gdb_name} exist in folder {folder_path}&quot;)</pre><p>Now let’s combine the file database creation and import with the necessary checks.</p><p>Our code will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*Lxb0QVO5IhesJglUvideJQ.png" /></figure><p>The execution of the code on the existing file database ‘Roads.gdb’ is correct.</p><pre>import arcpy<br>import os<br><br>folder_path = r&quot;C:\GISProject\GISBlog\Tools_Projects&quot;<br><br>gdb_name = &quot;Roads.gdb&quot;<br><br>gdb_path = os.path.join(folder_path, gdb_name)<br><br>if not arcpy.Exists(gdb_path):<br>    # If it doesn&#39;t exist, create the geodatabase<br>    arcpy.management.CreateFileGDB(folder_path, gdb_name)<br>    <br>    print(f&quot;Geodatabase {gdb_name} created.&quot;)<br>else:<br>    arcpy.conversion.FeatureClassToGeodatabase(<br>    Input_Features=r&quot;C:\GISProject\10m_physical\ne_10m_antarctic_ice_shelves_polys.shp&quot;,<br>    Output_Geodatabase=gdb_path)<br>    <br>    print(f&quot;Geodatabase {gdb_name} exist in folder {folder_path}&quot;)<br>    print(f&quot;Operation completed in {gdb_name}.&quot;)</pre><p>But let’s delete the “Roads.gdb” database and run the code from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*33G75y4kH6ikiP_hgYOn8A.png" /></figure><p>As you can see the file database has been created but is empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*9YnjD0TL3kqeOd76rClUKQ.png" /></figure><p>This is because only the creation part is executed, but not the import part of the SHP file. In order for our code to work correctly with both existing and new file databases, we will move the import part outside the check.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*c-mO5TyCrAYmZZrs_VIiUQ.png" /></figure><p>We check, through the catalog in Arcgis pro. As this is our final code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*_G-Zqv4ZeEw8zCHn4K7Csw.png" /></figure><p>As this is our final code:</p><p><a href="https://gisgp.com/blog/How_to_create_file_geodatabase_gdb_with_python_in_arcgispro-7.html">How to create file geodatabase (gdb) with python in ArcGIS Pro? How to use gdb in python?</a></p><p>Thank you for your attention.</p><p>In future posts, we will explore how to use Python to check for classes, fields, and values in a file database.</p><p>For more, please visit our blog dedicated to automation at АrcGIS pro.</p><p><a href="https://gisgp.com/blog/blogIndex.html">GISGP</a></p><p>Please consider subscribing to our newsletter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b150be940675" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating the transfer of multiple data into a file geodatabase with ModelBuilder in ArcGIS Pro]]></title>
            <link>https://medium.com/@kalin_85212/automating-the-transfer-of-multiple-data-into-a-file-geodatabase-with-modelbuilder-271b5da29d2c?source=rss-f0eea8eb30d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/271b5da29d2c</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[arcgis]]></category>
            <category><![CDATA[model-builder]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[arcgis-pro]]></category>
            <dc:creator><![CDATA[GISGP]]></dc:creator>
            <pubDate>Sat, 13 Jan 2024 14:37:32 GMT</pubDate>
            <atom:updated>2024-02-04T08:09:20.422Z</atom:updated>
            <content:encoded><![CDATA[<p>Embark on a journey of data transformation with our latest blog post, where we delve into the realm of ModelBuilder in ArcGIS Pro. Join us as we guide you through the seamless automation of transferring multiple datasets into a file geodatabase. Starting from scratch, we’ll help you create a project, establish a toolbox, and craft a model that aligns with your specific needs. Witness the power of organization as we name our toolbox and model with purpose, ensuring clarity and efficiency. Step by step, we explore the intricacies of adding files, creating a new geodatabase, and setting up loading functionality. The heart of our exploration lies in ModelBuilder, where we utilize Iterators and Geoprocessing tools to orchestrate a smooth data transfer.</p><p>In this article, we will develop a model that transfers multiple data into a database.</p><p>Create a project<br>Starting with a new blank project in ArcGIS Pro. From the project, we will choose to create a new toolbox. This is done by right-clicking on Toolboxes from the Catalog pane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*jyhfRRaTvdJq21FmmElizQ.png" /></figure><p>We name the toolbox, choosing Upload_files.atbx as the name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*_4fB1SYgu5UjA2sC3ADHeg.png" /></figure><p>So far we have created an empty container, now we need to create our model.<br>Create a new model.<br>This is done again by right-clicking on our toolbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*CvbBUIl-VhtE1ftWvStljA.png" /></figure><p>Our first model is ready. As you can see on the screen it is empty and with a default name.</p><p>Let’s give it an appropriate name to match its purpose. In one toolbox, to contain multiple models and scripts. Of course, it is good to organize them according to their purpose.<br>We select with the mouse button the newly created model and indicate Properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*mgQg3Hd19bR1B4bqPA0fHg.png" /></figure><p>Two names are available, the name that will be displayed to the user and the name under which the model will be stored and we confirm with OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*Hx4wwx54mTSMZYSGacP82Q.png" /></figure><p>To display the updated names, select the model save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*4DnHhhOBzKgNO8vxP9E9uQ.png" /></figure><p>Now let’s look at the files we will import. For this purpose, from folders I add the folder with the working files in my case in shape format. Let’s take a look at them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*7ZeQo47p21kU66HAD3K4kg.png" /></figure><p>Now let’s create a new geodatabase into which we’ll transfer all the files in bulk.<br>Create a new geographic database<br>This is done by selecting a database, with the right button we select a new database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*3NV54SjhXR9kmg3-XGUu_g.png" /></figure><p>We assign a name to the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*dJRfZ4yN-mWcG94R95ADdw.png" /></figure><p>At this point, the database is empty and cannot be expanded to view its contents.<br>Create loading functionality.<br>Now it’s time to create our model. We go to the ModelBuilder window and select Iterators from the menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*vwLR64U02k3ylEzqXC6uZA.png" /></figure><p>Since we will be loading files we need Iterate Feature Classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*xo8fj05aabzAdeqp9EpYBQ.png" /></figure><p>Iterators has been added to the project but is inactive. Now we need to make settings for file paths and names.<br>Double-click on Iterate Feature Classes.<br>A view similar to the geoprocessing window opens.</p><p>As you can see the folder path selection is a required parameter, let’s add it by clicking on the folder.</p><p>If the main folder contains subdirectories with folders, we choose Recursive, which in practice means to search for files and the contents of the subfolders.</p><p>The tool contains two very useful settings that we will look at later. These are Wildcard to search by part of the file name and Feature Type to select a file by geometry or table type.<br>Confirm with OK.<br>Now our model is active. We can even run it to test what it will do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*_8hQl-crCWGvwSz1xqZxOQ.png" /></figure><p>To learn more please visit the blog page.<br>Thank you for your attention.</p><p><a href="https://gisgp.com/blog/Automating-the-transfer-of-multiple-data-into-a-file-geodatabase-with-ModelBuilder-1.html">Automating the transfer of multiple data into a file geodatabase with ModelBuilder</a></p><p>GISGP</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=271b5da29d2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>