Skip to content

Commit

Permalink
missing imports (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
procrastinatio authored Jun 26, 2024
1 parent a736cca commit fba0e50
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SymbolsFilter.pyt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class SymbolFilter:
def execute(self, parameters, messages):
"""The source code of the tool."""

from utils import arcgis_table_to_df # Twice imported
from helpers import arcgis_table_to_df # Twice imported

inLayer = parameters[0].valueAsText
inSymbolsFile = parameters[1].valueAsText
Expand Down
39 changes: 39 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import arcpy
import geopandas as gpd
import pandas as pd
from collections import OrderedDict
from shapely.geometry import shape
from arcgis.geometry import Geometry

import logging


def arcgis_table_to_df(in_fc, input_fields=None, query="", spatial_filter=None):
"""Function will convert an arcgis table into a pandas dataframe with an object ID index, and the selected
input fields using an arcpy.da.SearchCursor.
:param - in_fc - input feature class or table to convert
:param - input_fields - fields to input to a da search cursor for retrieval
:param - query - sql query to grab appropriate values
:returns - pandas.DataFrame"""
OIDFieldName = arcpy.Describe(in_fc).OIDFieldName
available_fields = [field.name for field in arcpy.ListFields(in_fc)]
logging.debug(f"Available fields: {available_fields}")
logging.debug(f"Input fields: {input_fields}")
if input_fields:
# Preserve order of the 'input_fields'
final_fields = list(
OrderedDict.fromkeys(
item for item in input_fields if item in available_fields
)
)
else:
final_fields = available_fields
logging.debug(f"intersection: {final_fields}")
data = [
row
for row in arcpy.da.SearchCursor(
in_fc,
final_fields,
where_clause=query,
spatial_filter=spatial_filter,
search_order="SPATIALFIRST",
)
]
fc_dataframe = pd.DataFrame(data, columns=final_fields)
fc_dataframe = fc_dataframe.set_index(OIDFieldName, drop=True)
return fc_dataframe


def get_selected_features(layer, esri_geom=True):
# Get the selected feature IDs as strings
Expand Down

0 comments on commit fba0e50

Please sign in to comment.