|
POST
|
Have you attempted to use raw_input? I don't know if it'd work in this context, but give it a go! def onMouseDownMap(self, x, y, button, shift):
#choose XY on dataframe
mxd = arcpy.mapping.MapDocument("current")
dataframe = arcpy.mapping.ListDataFrames(mxd)[0]
global z
var = raw_input("Enter Z-Value: ")
z= int(var)
PointGeom = arcpy.PointGeometry(arcpy.Point(x,y,z), None, True, False)
global A
A = "C:\\Users\\Casper\\Desktop\\DENEMELER\\obs_point_fromAddin5.shp"
arcpy.CopyFeatures_management(PointGeom, A)
print "saved as a point.shp..."
... View more
01-05-2016
08:45 AM
|
1
|
0
|
1914
|
|
POST
|
You definitely want to include plt.close() after you have finished with writing the plot to a file!!! Google it
... View more
01-05-2016
08:21 AM
|
0
|
0
|
2432
|
|
POST
|
I've seen weirdness at times too. But if you do not instantiate plt.show(), simply save the fig, close it and then just allow os.system to open it using whatever default Windows application that typically views .png files to open it should remove the instability issues because a Tkinter window is not being used.
... View more
01-05-2016
08:03 AM
|
1
|
0
|
2432
|
|
POST
|
As an alternative, why not just let the default image viewer open the plot? import os
import matplotlib.pyplot as plt
def plotthegraph():
xLabelName = "x label"
yLabelName = "y_label"
title = "Title"
fig = plt.figure()
plt.plot(range(10), range(10))
plt.xlabel(xLabelName, fontsize = 14)
plt.ylabel(yLabelName, fontsize = 14)
plt.title(str(title), fontsize = 16)
plt.grid()
plt.savefig(r'H:\abc.png')
plt.close()
os.system(r'H:\abc.png') #this should allow the installed image viewer to open the png
... View more
01-05-2016
07:46 AM
|
0
|
4
|
8360
|
|
POST
|
I didn't see it in your code example (or in Dan' either), but you should close the plt --- include this line after the plt.show(): plt.close() See if that stops the instability you are experiencing.
... View more
01-05-2016
06:50 AM
|
0
|
0
|
2432
|
|
POST
|
With the dictionary and da.UpdateCursor solution I provided you would not need any AddJoin_management, TableView or CalculateField_management at all. An alternative is to convert both FC's to NumPy arrays, do appropriate join, calculate the desired column and then can invoke arcpy.da.NumpyArrayToFeatureClass to return to the ESRI stack. However this will mean a new output feature class rather than a simple field calculation. Both have their places and I have implementations with each setup. But I also do have simple AddJoin and CalculateField methods employed as well! Just depends on which toolset is best suited to satisfy the requirements.
... View more
12-31-2015
09:39 AM
|
2
|
0
|
3022
|
|
POST
|
You can fill a dictionary and then use that in conjunction with the arcpy.da.UpdateCursor to calculate the field. Something like this works and will likely be efficient for large sets compared to CalculateField_management: def JoinAndCalcuWithUpdateCursor():
baseFC = r'H:\Documents\ArcGIS\Default.gdb\[layer to update]'
joinFC = r'H:\Documents\ArcGIS\Default.gdb\[layer to join with]'
joincols= ['<join column>', '<column to use in calculate>']
joindict = {}
with arcpy.da.SearchCursor(joinFC, joincols) as rows:
for row in rows:
joinvals = row[0]
updatevals = row[1]
joindict[joinvals]=[updatevals]
del row, rows
# un-comment if you need to add a column to hold the calculated values
#arcpy.AddField_management(baseFC, "CalcField", "TEXT", "25")
basecols = ['<join column>', '<column to calculate>']
with arcpy.da.UpdateCursor(baseFC, basecols) as updRows:
for updRow in updRows:
keyval = updRow[0]
if joindict.has_key(keyval):
updRow[1] = joindict[keyval][0]
else:
updRow[1] = ''
updRows.updateRow(updRow)
del updRow, updRows
... View more
12-31-2015
06:30 AM
|
2
|
0
|
3022
|
|
POST
|
It's difficult to make a suggestion without seeing any code, but have you considered replacing CalculateField_management with da.UpdateCursor? I honestly don't know if that's going to help, but it's pretty much all guessing without digging into the details.
... View more
12-30-2015
11:53 AM
|
1
|
2
|
3022
|
|
POST
|
The fact is that there are already File geodatabases with data inside It makes perfect sense to employ the Attachments model on File Geodatabases, it's going to allow you to have many related attachments to any 1 feature. To replicate this with your own method will require some significant investment in development. The other reason for the output geodatabase to not use attachment is that further, the data should be inserted in an enterprise geodatabase (SQL Server spatially enabled). Do you mean ArcSDE registered within the SQL Server? If so, then again, the Attachment model is perfectly well suited for this environment. I'm not so sure why you think it isn't. I could see a storage limitations might be a valid concern, but that's unrelated to the fact that setting up Attachments on a SDE instance in SQL Server can and does perform well.
... View more
12-30-2015
10:27 AM
|
0
|
0
|
2353
|
|
POST
|
This workflow might satisfy your requirement, although I'd further research the continued use of the Raster column and perhaps determine if the Attachments model is a more appropriate option for the final repository. Your first task is to retrieve the contents of the Raster column from the source Feature Class. If you will ultimately want to populate the destination with Attachments then you will need to establish a unique value for each feature and name the output image with that value. Here I have an "Imgs" column representing the Raster column and "DBKEY" column that is simple a text type that has 5 character values unique to each feature. def writeRasFldContents():
#set the env workspace, otherwise it will write results to C:\users... dir
arcpy.env.workspace = r'H:\saveFolder'
arcpy.env.overwriteOutput = True
#specify an output folder to write out the Raster column images
output_path = r'H:\saveFolder'
os.chdir(output_path)
#input FeatureClass with the Raster column you wish to write out to a blob field
fc = r'H:\Documents\ArcGIS\Default.gdb\XY01TEST'
#write the images from the raster column, skipping any nulls or else it will error
with arcpy.da.SearchCursor(fc, ("Imgs", "DBKEY"), skip_nulls=True) as cursor:
for row in cursor:
filename = "{0}.tif".format(row[1])
row[0].save(filename)
print filename
del row
del filename Now that we have a file folder of output images in a folder and each relates back to each feature, you can now go thru the process to setup Attachments on the SDE feature class (just use the Geoprocessing tools to perform this). if you simply want to add a blob field onto the source feature class and populate it with the Raster column, these two additional def's will accomplish that: def writeBlobs():
fc = r'H:\Documents\ArcGIS\Default.gdb\XY01TEST'
input_path = r'H:\saveFolder'
full_file_paths = get_filepaths(input_path)
for f in full_file_paths:
if f.endswith(".tif"):
imgname = os.path.basename(f)
dbkey = os.path.splitext(imgname)[0]
expr = "DBKEY= '" + dbkey + "'"
print expr
myfile = open(f, 'rb').read()
#Imgs2 is the new blob column to populate the imgs
with arcpy.da.UpdateCursor(fc, ['Imgs2'], expr) as ucur:
for urow in ucur:
urow[0] = myfile
ucur.updateRow(urow)
def get_filepaths(directory):
file_paths = [] # List which will store all of the full filepaths.
# Walk the tree.
for root, directories, files in os.walk(directory):
for filename in files:
# Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
file_paths.append(filepath) # Add it to the list.
return file_paths Finally if you want to read the blobs to validate: def readBlobs():
#to check if the blob column was updated with the content of the raster column
fc = r'H:\Documents\ArcGIS\Default.gdb\XY01TEST'
with arcpy.da.SearchCursor(fc, ['Imgs2', 'DBKEY'], skip_nulls=True) as cursor:
for row in cursor:
binaryRep = row[0]
fileName = row[1]
print fileName
#save the content of the raster field to a new folder
open(r'H:\saveFolder2' + os.sep + fileName, 'wb').write(binaryRep.tobytes())
del row
del binaryRep
del fileName
... View more
12-30-2015
08:02 AM
|
1
|
0
|
2353
|
|
POST
|
It says it right in the documentation on the arcpy.da.UpdateCursor ArcGIS Help 10.1 Raster fields are not supported. Is there any reason why you are not using Attachments? The other alternative I can come up with is to store paths to images on a file server, but that's going to require a lot of code to manage things and seems dangerous to lose the image-to-feature relationships if you manage this entirely outside of the database.
... View more
12-30-2015
05:44 AM
|
1
|
2
|
2353
|
|
POST
|
Great illustration. I just started using the exc_traceback to simplify the error as I rarely need (or understand!) the error and line references to the actual modules/packages. But most of the time I don't even have try/catch during development!
... View more
12-29-2015
06:56 AM
|
1
|
1
|
3877
|
|
POST
|
As Dan mentioned, the try/except block can be a double-edge sword sometimes, especially at design-time. I personally don't really employ them until I'm ready to build a test deployment version because I just want to see the tracebacks when they hit the Interactive Window (PythonWin). Even then, the print or arcpy.AddMessage methods don't help much for much of my deployed implementations and I will typically use these try/catch blocks for writing out log events.
... View more
12-29-2015
06:27 AM
|
1
|
3
|
3877
|
|
POST
|
I'd try to uncover what the actual error is first. You can either simply remove the try/except block and it should print the traceback, or just update your except to print the actual error rather than "No File found program termintated" (you will need to add another import statement with the code below... import traceback
try:
'do stuff
except:
exc_traceback = sys.exc_info()
print traceback.print_exc()
... View more
12-29-2015
05:50 AM
|
1
|
6
|
3877
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|