POST
|
utf-16 didn't work, adding reload(sys) , sys.setdefaultencoding('Cp1252') to my code worked. Thanks tho. import pyodbc, sys
import pandas as pd
import os
reload(sys)
sys.setdefaultencoding('Cp1252')
... View more
07-13-2020
04:00 PM
|
0
|
2
|
1285
|
POST
|
I am trying to do a SQL dump of a table to excel but I can't get past the error, what am I doing wrong? Error line 14 'utf8' codec can't decode byte 0xc3 in position 0: invalid continuation byte import pyodbc
import pandas as pd
import os
cnxn = pyodbc.connect("Driver={SQL Server};"
"Server=***;"
"Database=***;"
"uid=***;pwd=***")
cursor = cnxn.cursor()
script = """
SELECT * FROM ***.***
"""
df = pd.read_sql(script, cnxn)
writer = pd.ExcelWriter(r'C:\Temp\export.xlsx')
df.to_excel(writer, sheet_name ='Sheet1', encoding='utf-8')
writer.save()
... View more
07-13-2020
03:33 PM
|
0
|
6
|
1362
|
POST
|
I was able to figure it out and it wasn't as complicated as I thought. if int(arcpy.GetCount_management("Parcels").getOutput(0)) > 0:
arcpy.Select_analysis("Parcels", "SelPar")
unique_values = set(row[0] for row in arcpy.da.SearchCursor("SelPar", "Field"))
format1 = ("_".join(unique_values))
Name = format1
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text == "Par Text":
elm.text = Name
... View more
07-08-2020
07:59 AM
|
1
|
0
|
322
|
POST
|
Working with Arcmap 10.6 and ArcToolbox script, I would like to select polygons and pass the attributes of a field of those selected polygons to arcpy.GetParameterAsText , I would then pass the arcpy.GetParameterAsText to update the TEXT ELEMENT of arcpy.mapping.ListLayoutElements to something like R2875103700_R2875103600_R2875300000_R2829301100. Is this possible if so how?
... View more
07-07-2020
08:31 AM
|
0
|
1
|
363
|
POST
|
I am working with a table that I am making trying to query and take the features that are selected from the query to a new layer/feature class but I am not sure why it is not working. I don't get any error's, using Python 3.6.8. I have tried Copy features and Table to geodatabase conversion but nothing gets created. env.workspace = r"D:\Temp\temp.gdb"
origin_table = "LV"
Clause = "group_code IN ('01','02','03','05')"
arcpy.MakeQueryTable_management(origin_table, "tmp_view", "NO_KEY_FIELD", "", "",Clause)
arcpy.TableToGeodatabase_conversion("tmp_view", r"D:\Temp\temp.gdb")
#arcpy.CopyFeatures_management("tmp_view", r"D:\Temp\temp.gdb\LV_1")
... View more
06-19-2020
03:43 PM
|
0
|
2
|
1414
|
POST
|
I was able to get to select features with the following but i was trying to use the arcpy.da.SearchCursor . sql = "[Shape_Area] in (SELECT max([Shape_Area]) FROM fc2 GROUP BY [PIN])"
arcpy.SelectLayerByAttribute_management(fc2,"NEW_SELECTION", sql)
... View more
04-09-2020
11:29 AM
|
0
|
1
|
1097
|
POST
|
My bad, Arcmap and would be using arcpy.SelectLayerByAttribute_management not ByLocation. I have tried the following I don't get an error but nothing is selected sql = "select MAX(Shape_Area) from fc group by PIN"
with arcpy.da.SearchCursor(fc2, ['SHAPE@']) as cursor:
for row in cursor:
arcpy.SelectLayerByAttribute_management(fc2,"NEW_SELECTION", sql)
... View more
04-09-2020
10:58 AM
|
0
|
2
|
1097
|
POST
|
I am try to select the polygons with the max area within parcels but i am having trouble passing the sql through arcpy.da.SearchCursor. How can i pass this sql through SearchCursor? sql = Shape_Area in (select max(Shape_Area) from Bldg_FP1 group by PIN) with arcpy.da.SearchCursor(fc2, ['SHAPE@']) as cursor:
for row in cursor:
arcpy.SelectLayerByAttribute_management(fc,"NEW_SELECTION", sql)
... View more
04-09-2020
10:11 AM
|
0
|
8
|
1203
|
POST
|
Something like below but It might just be easier to use the Use append tool to append your selected features including all attributes. import arcpy
from arcpy import env
fc1 = "" #Feature class to copy from
fc2 = "" #feature class to copy to
arcpy.env.workspace = "" #Workspace "C:/Temp"
arcpy.env.overwriteOutput = True
# Start an edit session. Must provide the worksapce.
edit = arcpy.da.Editor(arcpy.env.workspace)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(True)
# Start an edit operation
edit.startOperation()
arcpy.Append_management(fc1, fc2, "NO_TEST")
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
arcpy.RefreshActiveView()
... View more
04-07-2020
05:21 PM
|
1
|
0
|
2692
|
POST
|
Can you elaborate a little more on what you are trying to accomplish, are you trying to copy all the points from one feature class to another or just copy the selected ones or ones with a certain attribute?
... View more
04-07-2020
10:55 AM
|
0
|
3
|
2692
|
POST
|
Got it to work with making a feature layer. and adding row 10 lyr = r'C:\Temp\TaxParcels.shp'
subs = r'C:\Temp\SubsOutsideCities_Temp.shp'
arcpy.MakeFeatureLayer_management(lyr, "parLyr")
with arcpy.da.UpdateCursor(subs, ["VxCount", "Shape@"]) as cursor: # cycle through outer polygon layer
for row in cursor:
arcpy.management.SelectLayerByLocation("parLyr", "HAVE_THEIR_CENTER_IN",row[1]) # row[1] is SHAPE@
count = int(arcpy.GetCount_management("parLyr")[0])# row[0] to be updated with count
row[0] = (count)
cursor.updateRow(row) # update row
... View more
03-20-2020
02:03 PM
|
1
|
0
|
722
|
POST
|
If i run the following in stand alone python, every value in VxCount1 has the same number. subs = r'C:\Temp\SubsOutsideCities_Temp.shp'
lyr = r'C:\Temp\TaxParcels.shp'
with arcpy.da.UpdateCursor(subs, ["VxCount1", "Shape@"]) as cursor: # cycle through outer polygon layer
for row in cursor:
arcpy.management.SelectLayerByLocation(lyr, "HAVE_THEIR_CENTER_IN", row[1]) # row[1] is SHAPE@
row[0] = int(arcpy.GetCount_management(lyr)[0]) # row[0] to be updated with count
cursor.updateRow(row) # update row
... View more
03-20-2020
12:09 PM
|
0
|
2
|
722
|
POST
|
Randy I was able to get to work, thanks for the help. import arcpy
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Taxlots")[0]
subs = arcpy.mapping.ListLayers(mxd, "SubsOutsideCities")[0]
#arcpy.MakeFeatureLayer_management(par, "parLyr")
with arcpy.da.UpdateCursor(subs, ["VxCount1", "Shape@"]) as cursor: # cycle through outer polygon layer
for row in cursor:
arcpy.management.SelectLayerByLocation(lyr, "HAVE_THEIR_CENTER_IN", row[1]) # row[1] is SHAPE@
row[0] = int(arcpy.GetCount_management(lyr)[0]) # row[0] to be updated with count
cursor.updateRow(row) # update row
... View more
03-20-2020
07:48 AM
|
0
|
0
|
1883
|
POST
|
There is only two options for the spatialJoin_analysis, i am not sure what you mean by the other options. JOIN_ONE_TO_ONE JOIN_ONE_TO_MANY
... View more
03-19-2020
02:08 PM
|
0
|
0
|
1883
|
Title | Kudos | Posted |
---|---|---|
1 | 10-27-2022 11:37 AM | |
1 | 10-31-2023 10:16 AM | |
1 | 02-16-2023 01:50 PM | |
1 | 08-11-2021 11:13 AM | |
1 | 01-06-2021 10:45 AM |
Online Status |
Offline
|
Date Last Visited |
09-10-2024
10:42 AM
|