POST
|
Hey Dan! Thanks for replying I've tried PYTHON_9.3, same problem. Sounds like it's time for PRO...I guess that means my education has become dated (also I think 2010 was a type. Looks like 2.7 support ends in 2020)
... View more
06-27-2018
12:36 PM
|
1
|
1
|
524
|
POST
|
Hey Joshua, I like your solution to Joshua's problem. Very elegant. Cheers, Joshua
... View more
06-22-2018
10:26 AM
|
0
|
0
|
1392
|
POST
|
Hello Schwartz, I think you need to use an update cursor. Something like this might work: (built in ArcMap 10.4.1) import arcpy
#Input table:
table=r"C:\...\mytable.dbf"
#Get list of fields
fields=[]
for field in arcpy.ListFields(table):
fields.append(field.name)
#Update cursor
with arcpy.da.UpdateCursor(table, fields) as cursor:
#Set up dictionary to store previous non-null non-empty values
lastNonNullVals={}
for field in fields:
lastNonNullVals[field]="" #set a starting value for each field
for row in cursor:
for field in fields:
#Check if the current cell is null or empty
if row[fields.index(field)] in [None,"", " "]:
#Check if the previous value for the field exists
if lastNonNullVals[field] not in [None,"", " "]:
#Set the cell to the previous non-null non-empty value
row[fields.index(field)]=lastNonNullVals[field]
else:
#if there is a value for the cell, set it so it can be used in the next row(s)
lastNonNullVals[field]=row[fields.index(field)]
cursor.updateRow(row)
Let me know if it works out!
... View more
06-22-2018
08:33 AM
|
1
|
1
|
1392
|
POST
|
Hello Bixby, I'm using ArcMap 10.4.1. Thanks for testing it out! I guess it's not an issue anymore.
... View more
06-21-2018
10:00 AM
|
0
|
3
|
524
|
POST
|
Hey GIS experts, I ran into a strange problem with the arcpy.CalculateField_management tool. I'm not sure if this is a bug or just an error in my thinking, but I thought I'd post it just in case someone else has the same issue. If you run the commands in this order they work fine. arcpy.MakeTableView_management(mainTable, "tableView") arcpy.AddField_management(mainTable, "Province_Long", "TEXT", 100) arcpy.AddJoin_management("tableView", "Province_Short", lookupTable, "Prov_Short") arcpy.CalculateField_management("tableView","MainTable.Province_Long","!LookupTable.Prov_Long!","PYTHON") Result are as expected (the Province_Long field has data in it) If you run the commands in this order they do not work. arcpy.MakeTableView_management(mainTable, "tableView") arcpy.AddJoin_management("tableView", "Province_Short", lookupTable, "Prov_Short") arcpy.AddField_management(mainTable, "Province_Long", "TEXT", 100) arcpy.CalculateField_management("tableView","MainTable.Province_Long","!LookupTable.Prov_Long!","PYTHON") Result are not as expected (the Province_Long field has no data in it) No error is thrown, meaning that the field Province_Long exists and can be found, but for some reason the data is not being retrieved from the joined table. This only occurs when you are calculated from a field from the joined table. I also built a stand-alone script if someone wants to replicate the issue on their end. To change the script from not working to working, swap the two lines of code under #Swap these two lines import arcview
import arcpy
#=====Allow overwrite=====
originalOverwriteOutput = arcpy.env.overwriteOutput
arcpy.env.overwriteOutput = True
#=====Build main table=====
mainTable=arcpy.CreateTable_management(arcpy.env.scratchGDB, "MainTable")
arcpy.AddField_management(mainTable, "Address", "TEXT", 100)
arcpy.AddField_management(mainTable, "Province_Short", "TEXT", 100)
with arcpy.da.InsertCursor(mainTable, ["Address","Province_Short"]) as cursor:
cursor.insertRow(["123 Sesame Street","ON"])
cursor.insertRow(["10 Downing Street","NS"])
cursor.insertRow(["221B Baker Street","QC"])
cursor.insertRow(["4 Privet Drive","BC"])
#=====Build lookup table=====
lookupTable=arcpy.CreateTable_management(arcpy.env.scratchGDB, "LookupTable")
arcpy.AddField_management(lookupTable, "Prov_Short", "TEXT", 100)
arcpy.AddField_management(lookupTable, "Prov_Long", "TEXT", 100)
with arcpy.da.InsertCursor(lookupTable, ["Prov_Short","Prov_Long"]) as cursor:
cursor.insertRow(["NL","Newfoundland and Labrador"])
cursor.insertRow(["PE","Prince Edward Island"])
cursor.insertRow(["NS","Nova Scotia"])
cursor.insertRow(["NB","New Brunswick"])
cursor.insertRow(["QC","Quebec"])
cursor.insertRow(["ON","Ontario"])
cursor.insertRow(["MB","Manitoba"])
cursor.insertRow(["SK","Saskatchewan"])
cursor.insertRow(["AB","Alberta"])
cursor.insertRow(["BC","British Columbia"])
cursor.insertRow(["YT","Yukon"])
cursor.insertRow(["NT","Northwest Territories"])
cursor.insertRow(["NU","Nunavut"])
#=====Run lookup=====
arcpy.MakeTableView_management(mainTable, "tableView")
#==================================================
#Swap these two lines
arcpy.AddJoin_management("tableView", "Province_Short", lookupTable, "Prov_Short") #If this line is first, calc field does nothing
arcpy.AddField_management(mainTable, "Province_Long", "TEXT", 100) #If this line is first, it works properly
#==================================================
arcpy.CalculateField_management("tableView","MainTable.Province_Long","!LookupTable.Prov_Long!","PYTHON")
#=====Print output=====
with arcpy.da.SearchCursor(mainTable, ["Address","Province_Short","Province_Long"]) as cursor:
for row in cursor:
print("Address: "+str(row[0])+", Province_Short: "+str(row[1])+", Province_Long: "+str(row[2]))
arcpy.AddMessage("Address: "+str(row[0])+", Province_Short: "+str(row[1])+", Province_Long: "+str(row[2]))
#=====Reset overwrite=====
arcpy.env.overwriteOutput = originalOverwriteOutput
... View more
06-21-2018
08:44 AM
|
0
|
5
|
1030
|
POST
|
Hello Rene, Thank you for sharing! I did not know that existed. Taking a image client-side would mean we are still locked at 96dpi. Is this correct? Thank you!
... View more
07-25-2017
09:12 AM
|
0
|
0
|
1057
|
POST
|
Hello PW, My workaround really sucks. It's a BIG time and resource sink. We got StreetMap Premium from esri. The product comes with data and an MXD that's almost an exact match of the 'streets' basemap. I also found a MXD that closely matches the light gray basemap and reconnected all the layers to point to the data from StreetMap Premium. Then I created services for those MXDs and with the help of my expert co-worker, made a printing service that replaces the standard 96DPI raster basemap with the new service. It gets more complicated if you want to 'sandwich' a thematic layer in between the layers of the basemap (for example roads on top of a choropleth). I've talked with several developers at esri and this unfortunately seems to be the only way right now. If you find anything else, please let me know. I'm eagerly waiting the day printing is supported for the vector tiles! Good luck! (Upvote the idea here)
... View more
07-21-2017
12:35 PM
|
0
|
2
|
1057
|
POST
|
Hello Mike, Thanks for the clear post. Nice looking script, I have a few suggestions of the get-go. the line arcpy.FeatureClassToFeatureClass_conversion(nfc, NewoutLocation, newFCName) has no where clause (the optional 4th parameter). I think this means that even if the line weren't erroring out, it would create a full copy of every row in the "nfc" feature class X times (where X is the number of rows in the "nfc" feature class). I think you will want to add a where clause so it only exports the current row each time. Something like this might work: arcpy.FeatureClassToFeatureClass_conversion(nfc, NewoutLocation, newFCName, "NAME = '"+row.NAME+"'") In addition to the query, you might want to try exporting to the GDB, not the Dataset within the GDB. I've run into problems before when exporting to a Dataset. Sometimes inconsistent projections or precisions can cause problems. Try outputting to "outLocation" for now, and exporting to a Dataset once we have everything else working. Your new line (including item 1 above, should look something like this: arcpy.FeatureClassToFeatureClass_conversion(nfc, outLocation, newFCName, "NAME = '"+row.NAME+"'") Let me know if those 2 changes do anything. Also,any chance you can post a small data set for testing? Good luck!
... View more
05-12-2016
08:55 AM
|
0
|
1
|
432
|
POST
|
Hello Mike, I'm still kicking around. Feel free to ask away! I'll see if I can help (and it looks like we may get help from guru Dan Patterson)
... View more
05-12-2016
07:03 AM
|
1
|
3
|
432
|
POST
|
Hello Ernesto, Seems like this was an issue that got fixed: https://github.com/Esri/ArcREST/issues/163 You might want to try downloading and installing again.
... View more
02-23-2016
06:44 AM
|
1
|
0
|
212
|
POST
|
Hello Paul, I have prepared a Python Add-In that should do what you need. I attached a .zip of it. Note that: To install the Add-In, run "PythonAddIn.esriaddin" You can see the raw code under the "Install" folder If you make any changes, run the "makeaddin.py" and then re-install with "PythonAddIn.esriaddin" If you haven't already, you can download the python add-in wizard here. You can use "addin_assistant.exe" to change the Add-In documentation. Let me know if it works out for you! Also, I ran into one limitation. If the user has an attribute table open (from one of the related tables), they will have to close and re-open the table to see the changes. More info here.
... View more
03-26-2015
12:17 PM
|
1
|
3
|
1196
|
POST
|
Hello Paul, I'm working on a python solution (I don't know ArcObjects either). Can you let me know the exact name of the key field for the complaint point file? Thank you!
... View more
03-26-2015
07:13 AM
|
0
|
1
|
1196
|
POST
|
Hello Paul, I actually ran my python script outside of ArcMap using IDLE, but it can also be run within ArcMap. I did not set it up as a python add-in. Also, as Blake pointed out, the script will copy over ALL keys in the complaint file to the related tables each time it runs (thanks for that catch Blake!). I have a few ideas on how to proceed; We can change the script so that it only copies over keys that don't yet exist in the related tables. This would mean the script could be run in ArcMap or outside ArcMap (with IDLE), and just requires pointers to the data. We can use Blake's idea and only run the script on selected records. This would mean we have to be in ArcMap and have to be able to programmatically pick out the complaint layer with the user selected points. If we set this up as an add-in, there is a way to pick out the layer the user has selected in the TOC. We can combine the 2 above approached so that if users run the tool twice on the same Key, it won't create duplicate records in the related tables. Let me know what you think!
... View more
03-24-2015
08:32 AM
|
0
|
2
|
2183
|
POST
|
Ok, so I wrote a small python script that should work. The script should be able to handle a few points really quickly, but will be slower than needed if your very large numbers of input points. Since your said it will only be one at a time, this should be fine. I included two ways of selected your related tables (manually and automatically). Remove the method you choose not to use. You will also need to make sure your key field already exists in all your related tables. import arcview
import arcpy
workDir="C:\\path\\to\\data\\TESTGeodatabase.gdb"
pointsFC="MCCOG_Complaint.DBO.complaint"
keyField="complaintKey"
#Manually select related tables:
relatedTables=["MCCOG_Complaint.DBO.complaintProblem","MCCOG_Complaint.DBO.complaintWorkOrder","MCCOG_Complaint.DBO.complaintContractor"]
#Automatically select related tables:
arcpy.env.workspace=workDir
relatedTables=arcpy.ListTables("MCCOG_Complaint.DBO.complaint*") #all table that begin with 'MCCOG_Complaint.DBO.complaint'
#Copy rows to related tables:
with arcpy.da.SearchCursor(workDir+"\\"+pointsFC,[keyField]) as inRows:
for inRow in inRows:
for relatedTable in relatedTables:
with arcpy.da.InsertCursor(workDir+"\\"+relatedTable,[keyField]) as outRows:
outRows.insertRow(inRow)
print("Complete!") Let me know how it goes!
... View more
03-17-2015
08:58 AM
|
1
|
3
|
2183
|
Title | Kudos | Posted |
---|---|---|
1 | 03-17-2015 08:58 AM | |
1 | 01-16-2014 10:03 AM | |
1 | 02-23-2016 06:44 AM | |
1 | 06-22-2018 08:33 AM | |
1 | 03-26-2015 12:17 PM |
Online Status |
Offline
|
Date Last Visited |
05-21-2021
08:26 AM
|