POST
|
Thanks very much for letting me know. I suspected as much but the error message was unclear and I had wondered if I was making a mistake in some manner. Not to worry, I will continute with pyODBC. Thanks again!
... View more
09-23-2020
07:15 AM
|
0
|
0
|
1839
|
POST
|
I am trying to do what seems to be a simple operation: 1. Iterate through a feature class 2. Insert found rows to an MSSQL spatial table. However I keep getting the following error No support for this geometry type. Strangely I get this error even if I only try to insert and int or string with no shapes involved. It seems that Arc does not understand the table which is strange because I can run select operations and Describe() on the table without issue. Does Arc support inserting spatial data to MSSQL in this manner? In the code snipped below: selected_grid_fc: File Geodatabase Feature Class, Geometry Type: Polygon selected_grids_mssql: MSSQL table with a geometry column. The geometry column stores Polygon grid squares from a 100m Fishnet in EPSG:2157 try:
# Start an edit session. Must provide the workspace.
edit_session = arcpy.da.Editor(env.workspace)
# Edit session is started without an undo/redo stack for versioned data (for second argument, use False for unversioned data)
edit_session.startEditing(False, False)
# Start an edit operation
edit_session.startOperation()
search_cols = ['OBJECTID', 'GridId', 'SHAPE@']
insert_cols = ['ObjectId', 'GridId', 'Shape'] # If I user 'Shape@', the error is the same.
selected_grids_mssql = os.path.join(self.sde_path, 'dbo.SelectedGrids')
with arcpy.da.SearchCursor(selected_grid_fc, search_cols) as search_cursor:
with arcpy.da.InsertCursor(selected_grids_mssql, insert_cols) as insert_cursor:
for row in search_cursor:
insert_cursor.insertRow(row)
except Exception as ex:
arcpy.AddError("Something went wrong.")
raise
else:
# Stop the edit operation.
edit_session.stopOperation()
# Stop the edit session and save the changes
edit_session.stopEditing(True)
arcpy.AddMessage("Import successful.") For reference, the following works fine via pyodbc, but I wanted to see if it could be done without the need for an external library. selected_grids = []
selected_grid_cols = ['OBJECTID', 'GridId', 'SHAPE@WKT']
with arcpy.da.SearchCursor(selected_grid_fc, selected_grid_cols) as cursor:
for row in cursor:
selected_grids.append(row)
with Helpers.db_connect().cursor() as cursor:
query = "INSERT INTO [dbo].[SelectedGrids](ObjectId, GridId, Shape) VALUES (?,?,geometry::STGeomFromText(?, 2157));"
cursor.executemany(query, selected_grids)
... View more
09-22-2020
03:48 PM
|
0
|
4
|
1888
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|