A toolkit for converting Excel coordinates to ArcGIS GDB
Project description
excelgdb
A toolkit for converting Excel coordinates into ArcGIS Geodatabase (GDB) layers, including points, lines, and polygons. Features
Convert Excel Data: Easily convert Excel files with coordinate data into ArcGIS Geodatabase feature classes.
Supports Points, Lines, and Polygons: Add multiple geometry types from Excel sheets.
Organized Structure: Create, populate, and clean Geodatabase layers from Excel data using separate modules for points, lines, and polygons.
Installation
Install the excelgdb package: pip install excelgdb
Usage
Below is a complete example of how to use the excelgdb package to read coordinate data from Excel sheets and add it to ArcGIS Geodatabase layers.
import pandas as pd
import excelgdb
def main(): # Geodatabase path gdb_path = r"Data\Ouput\example.gdb" # Function to check and add 'ORIG_FID' field if it does not exist
# Function to read points from an Excel file and add them to the point layer
def add_points_from_excel(layer, excel_file):
df = pd.read_excel(excel_file,sheet_name="hospital")
for _, row in df.iterrows():
x, y = row['X'], row['Y']
layer.add_point(x, y)
# Function to read lines from an Excel file and add them to the line layer
def add_lines_from_excel(layer, excel_file, sort_field):
df = pd.read_excel(excel_file, sheet_name="railway")
# Grouping points by 'sort_field' column in the Excel file to create separate lines
grouped = df.groupby(sort_field)
# Creating a dictionary to store coordinates grouped by `sort_field`
coordinates_grouped = {}
for name, group in grouped:
# Extracting coordinates for the current line segment
coordinates = [(row['X'], row['Y']) for _, row in group.iterrows()]
coordinates_grouped[name] = coordinates # Store coordinates with `sort_field` as the key
# Adding grouped coordinates to the layer as lines
layer.add_line_xls(coordinates_grouped)
# Function to read polygons from an Excel file and add them to the polygon layer
def add_polygons_from_excel(layer, excel_file,sort_field):
df = pd.read_excel(excel_file, sheet_name="shahrestan")
# Grouping coordinates by 'sort_field' column if needed
grouped = df.groupby(sort_field)
# Creating a dictionary to store coordinates grouped by `sort_field`
coordinates_grouped = {}
for name, group in grouped:
# Extracting coordinates for the current polygon
coordinates = [(row['X'], row['Y']) for _, row in group.iterrows()]
coordinates_grouped[name] = coordinates # Store coordinates with `sort_field` as the key
# Adding grouped coordinates to the layer as polygons
layer.add_polygon_xls(coordinates_grouped)
# Creating layers & Reading data from Excel files and adding to layers
point_layer = excelgdb.PointLayer(gdb_path, "Hospital")
add_points_from_excel(point_layer, r"data\hospital.xlsx")
line_layer = excelgdb.LineLayer(gdb_path, "Rails", "ORIG_FID")
add_lines_from_excel(line_layer, r"data\railway.xlsx", "ORIG_FID")
line_layer.delete_null_records()
polygon_layer = excelgdb.PolygonLayer(gdb_path, "Shahrestan", "ORIG_FID")
add_polygons_from_excel(polygon_layer, r"data\shahrestan.xlsx", "ORIG_FID")
polygon_layer.delete_null_records()
if name == "main": main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file excelgdb-0.4.tar.gz.
File metadata
- Download URL: excelgdb-0.4.tar.gz
- Upload date:
- Size: 561.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4db4c38d2dc168b3740d35c61d9907c4fe41d311956480bdeeded83decac667e
|
|
| MD5 |
eaebf5168952c4a00cb8f5a169b4007e
|
|
| BLAKE2b-256 |
7afc24a884d1cfa54953b4a46a376f3af3081a5f155aad54619743c8722f2717
|
File details
Details for the file excelgdb-0.4-py3-none-any.whl.
File metadata
- Download URL: excelgdb-0.4-py3-none-any.whl
- Upload date:
- Size: 565.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aa2d2ac57ac2c2fd11dd027f285dc8a353fff9da5081229b113c29e9fccab67
|
|
| MD5 |
61b2fd3a64b86f3300917fb08c009b02
|
|
| BLAKE2b-256 |
74099f7c9ad2d992cd5fdc31c46dc2aac7d1f701ae59152540da0845aecc185b
|