|
POST
|
I know this is an old thread, but could you please elaborate on how to do this. I'm running into a similar issue.
... View more
12-04-2013
09:47 AM
|
0
|
0
|
590
|
|
POST
|
Hi, I can't seem to find a way to bind to the MaximumValue / MinimumValue properties inside of ClassBreakInfo in ClassBreaksRenderer.Classes. Is the property not exposed to do this? Or am I missing something? I've also tried <sys:Double x:Key="testDouble">1.0</sys:Double> and then using this MinimumValue="{StaticResource testDouble}" which works fine. But I can't figure out how to bind the value of testDouble to a double in my class so that that is is auto updated. Any advice would be greatly appreciated. Thanks
... View more
03-08-2013
07:50 AM
|
0
|
1
|
726
|
|
POST
|
I was correct and there were errors with esri's SSUtilities and/or SSDataObject scripts. By removing them and adding the functionality they had into my script, it not only loaded successfully, but the analyze part also took seconds rather than 10 minutes. I guess when the analyzer drills down into the scripts it takes awhile to run the tests. Anyway, here is the new code in case people are curious. Note that I also fixed the CC part of the email as that wasn't working correctly, although unrelated to esri.
import arcpy
import locale
import os
import smtplib
import string
import zipfile
locale.setlocale(locale.LC_ALL, '')
arcpy.SetLogHistory(False)
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
inputSratchFolder = ""
def createNobelTecFile(inputNTfc, inputNTfileName):
try:
outputNTname = os.path.join(inputSratchFolder, (inputNTfileName + "_Nav.txt"))
f = open(outputNTname,'w')
rows = arcpy.SearchCursor(inputNTfc)
for row in rows:
label = row.getValue("LABEL")
f.write('[' + label + ']\n')
f.write('Type = Mark\n')
lon = row.getValue("LON")
lonDD = int(abs(lon))
lonMM = float((float(abs(lon)) - lonDD) * 60.0)
lonMMs = str(lonMM)
lat = row.getValue("LAT")
latDD = int(lat)
latMM = float((float(lat) - latDD) * 60.0)
latMMs = str(latMM)
f.write('LatLon = ' + str(latDD) + ' ' + latMMs + ' N ' + str(lonDD) + ' ' + lonMMs + ' W\n')
f.write('Color = 0x000000\n')
testType = row.getValue("TYPE")
if testType == "CTD Only":
symbol = str(1)
elif testType == "Bongo and CTD":
symbol = str(9)
elif testType == "Random Clam Station":
symbol = str(1)
elif testType == "Random BTS Station":
symbol = str(1)
elif testType == "Random BTS Station with Bongo":
symbol = str(9)
elif testType == "Random BTS Alt Station":
symbol = str(1)
elif testType == "Scallop - Fixed Station: Start":
symbol = str(2)
elif testType == "Scallop - Fixed Station: End":
symbol = str(3)
elif testType == "Scallop - Non-Random":
symbol = str(4)
elif testType == "Scallop - Non-Random > 40m":
symbol = str(5)
elif testType == "Random Scallop Station":
symbol = str(1)
elif testType == "Fixed Scallop Station":
symbol = str(9)
elif testType == "Random Shrimp Station":
symbol = str(1)
elif testType == "Fixed Shrimp Station":
symbol = str(9)
f.write('BmpIdx = ' + symbol + '\n')
f.write('ExistsOutsideCollection = True\n')
f.write('Locked = True\n')
f.write('MarkRenamed = True\n')
f.close()
return outputNTname
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddMessage("Create NobelTec File Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
def createChiefSciFile(inputCSfc, inputCSfileName):
try:
outputCSname = os.path.join(inputSratchFolder, (inputCSfileName + ".csv"))
fieldList = [f.name for f in arcpy.ListFields(inputCSfc) if not f.name.startswith('Shape')]
exportXYV(inputCSfc, fieldList, outputCSname)
return outputCSname
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddMessage("Create Chief Scientist File Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
def exportXYV(inputFC, fieldList, outFile):
try:
rows = arcpy.da.SearchCursor(inputFC, fieldList)
delimiter = ","
floatTypes = ["Single", "Double"]
localeDict = {}
fieldListObject = arcpy.ListFields(inputFC)
for field in fieldListObject:
fieldType = field.type
if fieldType in floatTypes:
formatToken = "%f"
else:
formatToken = "%s"
localeDict[field.name] = formatToken
try:
fo = open(outFile, 'w')
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddIDMessage("ERROR", 210, fileName)
raise SystemExit()
outRow = delimiter.join(fieldList)
fo.write("%s\n" % outRow.encode('utf-8'))
for row in rows:
rowValues = []
for ind, field in enumerate(fieldList):
value = row[ind]
if value == "" or value == None:
rowValues.append("NULL")
else:
formatValue = locale.format(localeDict[field], value)
rowValues.append(formatValue)
outRow = delimiter.join(rowValues)
fo.write("%s\n" % outRow.encode('utf-8'))
del rows
fo.close()
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddMessage("Create Chief Scientist File Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
def zipUpFolder(inputFC, chiefSciFile, nobelTecFile):
try:
outZipFile = os.path.join(inputSratchFolder, "Stations.zip")
zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_DEFLATED)
zipws(zip, inputFC, chiefSciFile, nobelTecFile)
zip.close()
return outZipFile
except RuntimeError:
if os.path.exists(outZipFile):
os.unlink(outZipFile)
zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_STORED)
zipws(zip, inputFC, chiefSciFile, nobelTecFile)
zip.close()
arcpy.AddWarning(arcpy.GetIDMessage(86133))
def zipws(zip, fc, chiefSciZip, nobelTecZip):
path = os.path.normpath(os.path.dirname(fc))
chiefSciName = os.path.basename(chiefSciZip)
nobelTecName = os.path.basename(nobelTecZip)
rootLen = len(path)+len(os.sep)
for (dirpath, dirnames, filenames) in os.walk(path):
for file in filenames:
if not file.endswith('.lock'):
zip.write(os.path.join(dirpath, file), os.path.join("Stations.gdb", os.path.join(dirpath, file)[rootLen:]))
zip.write(chiefSciZip, chiefSciName)
zip.write(nobelTecZip, nobelTecName)
def send_mail(send_to, subject, text, f):
try:
msg = MIMEMultipart()
msg['From'] = "FirstName.LastName@MyEmail.com"
msg['To'] = COMMASPACE.join(send_to)
msg['CC'] = "FirstName.LastName@MyEmail.com"
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
send_to = [send_to, "FirstName.LastName@MyEmail.com"]
msg.attach( MIMEText(text) )
part = MIMEBase('application', "zip")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
smtp = smtplib.SMTP("MyServer")
smtp.sendmail("FirstName.LastName@MyEmail.com", send_to, msg.as_string())
smtp.close()
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddMessage("Send Email Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
if __name__ == '__main__':
try:
inputGDB = arcpy.GetParameterAsText(0)
global inputSratchFolder
inputSratchFolder = arcpy.GetParameterAsText(1)
inputFileName = arcpy.GetParameterAsText(2)
inputSend = [arcpy.GetParameterAsText(3)]
subject = arcpy.GetParameterAsText(4)
text = arcpy.GetParameterAsText(5)
outputNobelTecFile = createNobelTecFile(inputGDB, inputFileName)
outputChiefSciFile = createChiefSciFile(inputGDB, inputFileName)
outputZipFile = zipUpFolder(inputGDB, outputChiefSciFile, outputNobelTecFile)
send_mail(inputSend, subject, text, outputZipFile)
arcpy.SetParameterAsText(6, "True")
except:
arcpy.SetParameterAsText(6, "False")
arcpy.AddMessage("Create Files Zip and Email Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
... View more
02-08-2013
05:55 AM
|
0
|
0
|
574
|
|
POST
|
I've narrowed down the problem. The creation of the txt file and the zipping and emailing of the feature class along with it work fine. The part that is giving me the error is with the export to csv function. In fact, by just adding these two lines, it will fail: import SSDataObject import SSUtilities I don't have the solution yet, but may try to code without using those scripts...
... View more
02-07-2013
09:07 AM
|
0
|
0
|
574
|
|
POST
|
The python script:
import arcpy
import ErrorUtils
import locale
import os
import smtplib
import SSDataObject
import SSUtilities
import string
import zipfile
locale.setlocale(locale.LC_ALL, '')
arcpy.SetLogHistory(False)
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
inputSratchFolder = ""
def createNobelTecFile(inputNTfc, inputNTfileName):
try:
outputNTname = os.path.join(inputSratchFolder, (inputNTfileName + "_Nav.txt"))
f = open(outputNTname,'w')
rows = arcpy.SearchCursor(inputNTfc)
for row in rows:
label = row.getValue("LABEL")
f.write('[' + label + ']\n')
f.write('Type = Mark\n')
lon = row.getValue("LON")
lonDD = int(abs(lon))
lonMM = float((float(abs(lon)) - lonDD) * 60.0)
lonMMs = str(lonMM)
lat = row.getValue("LAT")
latDD = int(lat)
latMM = float((float(lat) - latDD) * 60.0)
latMMs = str(latMM)
f.write('LatLon = ' + str(latDD) + ' ' + latMMs + ' N ' + str(lonDD) + ' ' + lonMMs + ' W\n')
f.write('Color = 0x000000\n')
testType = row.getValue("TYPE")
if testType == "CTD Only":
symbol = str(1)
elif testType == "Bongo and CTD":
symbol = str(9)
elif testType == "Random Clam Station":
symbol = str(1)
elif testType == "Random BTS Station":
symbol = str(1)
elif testType == "Random BTS Station with Bongo":
symbol = str(9)
elif testType == "Random BTS Alt Station":
symbol = str(1)
elif testType == "Scallop - Fixed Station: Start":
symbol = str(2)
elif testType == "Scallop - Fixed Station: End":
symbol = str(3)
elif testType == "Scallop - Non-Random":
symbol = str(4)
elif testType == "Scallop - Non-Random > 40m":
symbol = str(5)
elif testType == "Random Scallop Station":
symbol = str(1)
elif testType == "Fixed Scallop Station":
symbol = str(9)
elif testType == "Random Shrimp Station":
symbol = str(1)
elif testType == "Fixed Shrimp Station":
symbol = str(9)
f.write('BmpIdx = ' + symbol + '\n')
f.write('ExistsOutsideCollection = True\n')
f.write('Locked = True\n')
f.write('MarkRenamed = True\n')
f.close()
return outputNTname
except:
arcpy.AddMessage("Create NobelTec File Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
def createChiefSciFile(inputCSfc, inputCSfileName):
try:
outputCSname = os.path.join(inputSratchFolder, (inputCSfileName + ".csv"))
fieldList = [f.name for f in arcpy.ListFields(inputCSfc) if not f.name.startswith('Shape')]
exportXYV(inputCSfc, fieldList, outputCSname)
return outputCSname
except:
arcpy.AddMessage("Create Chief Scientist File Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
def exportXYV(inputFC, fieldList, outFile):
ssdo = SSDataObject.SSDataObject(inputFC)
inputFields = [ssdo.oidName, "SHAPE@XY"] + fieldList
cnt = SSUtilities.getCount(inputFC)
badIDs = []
badRecord = 0
try:
rows = arcpy.da.SearchCursor(ssdo.inputFC, inputFields)
except:
arcpy.AddIDMessage("ERROR", 204)
raise SystemExit()
delimiter = ","
floatTypes = ["Single", "Double"]
localeDict = {}
for field in fieldList:
fieldType = ssdo.allFields[field].type
if fieldType in floatTypes:
formatToken = "%f"
else:
formatToken = "%s"
localeDict[field] = formatToken
fo = SSUtilities.openFile(outFile, 'w')
outRow = delimiter.join(fieldList)
fo.write("%s\n" % outRow.encode('utf-8'))
for row in rows:
OID = row[0]
badValues = row.count(None)
badRow = badValues
rowValues = []
for ind, field in enumerate(fieldList):
value = row[ind + 2]
if value == "" or value == None:
rowValues.append("NULL")
else:
formatValue = locale.format(localeDict[field], value)
rowValues.append(formatValue)
if badRow:
badIDs.append(OID)
outRow = delimiter.join(rowValues)
fo.write("%s\n" % outRow.encode('utf-8'))
del rows
fo.close()
badIDs = list(set(badIDs))
badIDs.sort()
badIDs = [ str(i) for i in badIDs ]
bn = len(badIDs)
if bn:
err = ErrorUtils.reportBadRecords(cnt, bn, badIDs, label=ssdo.oidName, allowNULLs = True)
def zipUpFolder(inputFC, chiefSciFile, nobelTecFile):
try:
outZipFile = os.path.join(inputSratchFolder, "Stations.zip")
zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_DEFLATED)
zipws(zip, inputFC, chiefSciFile, nobelTecFile)
zip.close()
return outZipFile
except RuntimeError:
if os.path.exists(outZipFile):
os.unlink(outZipFile)
zip = zipfile.ZipFile(outZipFile, 'w', zipfile.ZIP_STORED)
zipws(zip, inputFC, chiefSciFile, nobelTecFile)
zip.close()
arcpy.AddWarning(arcpy.GetIDMessage(86133))
def zipws(zip, fc, chiefSciZip, nobelTecZip):
path = os.path.normpath(os.path.dirname(fc))
chiefSciName = os.path.basename(chiefSciZip)
nobelTecName = os.path.basename(nobelTecZip)
rootLen = len(path)+len(os.sep)
for (dirpath, dirnames, filenames) in os.walk(path):
for file in filenames:
if not file.endswith('.lock'):
zip.write(os.path.join(dirpath, file), os.path.join("Stations.gdb", os.path.join(dirpath, file)[rootLen:]))
zip.write(chiefSciZip, chiefSciName)
zip.write(nobelTecZip, nobelTecName)
def send_mail(send_to, subject, text, f):
try:
msg = MIMEMultipart()
msg['From'] = r'FirstName.LastName@MyEmail.com'
msg['To'] = COMMASPACE.join(send_to)
msg['CC'] = "FirstName.LastName@MyEmail.com"
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
part = MIMEBase('application', "zip")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
smtp = smtplib.SMTP("MYSERVER")
smtp.sendmail(r'FirstName.LastName@MyEmail.com', send_to, msg.as_string())
smtp.close()
except:
arcpy.AddMessage("Send Email Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
if __name__ == '__main__':
try:
inputGDB = arcpy.GetParameterAsText(0)
global inputSratchFolder
inputSratchFolder = arcpy.GetParameterAsText(1)
inputFileName = arcpy.GetParameterAsText(2)
sendto = arcpy.GetParameterAsText(3).split(";")
subject = arcpy.GetParameterAsText(4)
text = arcpy.GetParameterAsText(5)
outputNobelTecFile = createNobelTecFile(inputGDB, inputFileName)
outputChiefSciFile = createChiefSciFile(inputGDB, inputFileName)
outputZipFile = zipUpFolder(inputGDB, outputChiefSciFile, outputNobelTecFile)
send_mail(sendto, subject, text, outputZipFile)
arcpy.SetParameterAsText(5, "True")
except:
arcpy.SetParameterAsText(5, "False")
arcpy.AddMessage("Create Files Zip and Email Tool Failed")
arcpy.AddError(arcpy.GetMessages(2))
... View more
02-07-2013
04:43 AM
|
0
|
0
|
574
|
|
POST
|
Hi, I wrote a python script, wrapped it in ModelBuilder and tried to publish it. It just gets stuck in a loop, forcing me to cancel the publish. It passed the analysis and all the data used in it is in verified folders in the ArcServer data sources. I can't figure out what's going on. I've tried publishing it from ArcMap on both my desktop computer and on the server itself, but get the same error. The error is 001270 Consolidating the data failed. I followed all steps listed in the help for that error and it didn't work. I'm out of ideas, can someone look at this code and figure out why it won't publish? My only guess is it has to do with some sort of temporary data, possible the %scratchFolder%, although unlikely. My other thought is one of the import scripts is giving some errors. The code takes a feature class, email information, and the %scratchFolder% variable. It creates a NobelTec file (which is just a simple text file in the open navigation format) and a csv of the feature class's table, then zips the two new files and the feature class together, and emails the end user. Pretty simple and works fine from ArcMap. Most of it is code from the ArcToolBox that I took and hard-coded some things and deleted unnecessary parts. I exported the ModelBuilder code to python and will show that first, then show the python script tool itself. (Note that I replaced email addresses, folder locations, and server info with dummy info, but have them written out on my copy.) Any help would be GREATLY appreciated! Due to text length issues, the python code for the script will be posted in the first reply. Exported ModelBuilder code:
import arcpy
arcpy.ImportToolbox("//XXX.XXX.XXX.XXX/arcData/lab_data/FOLDER1/FOLDER2/MyToolBox10_1.tbx")
jobID = arcpy.GetParameterAsText(0)
if jobID == '#' or not jobID:
jobID = "\\\\XXX.XXX.XXX.XXX\\arcData\\lab_data\\FOLDER1\\FOLDER2\\ToolData\\SaveAndEmail.gdb\\Stations"
Output_File_Name = arcpy.GetParameterAsText(1)
if Output_File_Name == '#' or not Output_File_Name:
Output_File_Name = "BTS_2013_Spring"
Email_To = arcpy.GetParameterAsText(2)
if Email_To == '#' or not Email_To:
Email_To = "EndUserEmail@WhereEver.com"
Email_Subject = arcpy.GetParameterAsText(3)
if Email_Subject == '#' or not Email_Subject:
Email_Subject = "BTS_2013_Spring_Stations"
Email_Body = arcpy.GetParameterAsText(4)
if Email_Body == '#' or not Email_Body:
Email_Body = "Here are your stations"
Worked = arcpy.GetParameterAsText(5)
Input_Stations = "%jobID%"
Scratch_Folder = "%scratchFolder%"
arcpy.gp.toolbox = "//XXX.XXX.XXX.XXX/arcData/lab_data/FOLDER1/FOLDER2/MyToolBox10_1.tbx";
arcpy.gp.CreateFilesZipAndEmail(Input_Stations, Scratch_Folder, Output_File_Name, Email_To, Email_Subject, Email_Body)
... View more
02-07-2013
04:42 AM
|
0
|
3
|
851
|
|
POST
|
And I figured it out... it was dumb too. Setting the OutputSpatialReference did work, it was WHERE I was setting it. I was doing it in the MainPage() function (before the map was even set), so it was setting it to a null projection. I set it after the map was drawn and it works fine. Thanks for the help!
... View more
07-28-2011
06:06 AM
|
0
|
0
|
488
|
|
POST
|
Also, I'm somewhat new to fiddler. What tab should I be looking at to help figure this out?
... View more
07-28-2011
05:36 AM
|
0
|
0
|
488
|
|
POST
|
Thanks for the reply, however I did try _geoprocessorTask.OutputSpatialReference = MyMap.SpatialReference; already and it didn't work. I've also tried adding the geometry line here: private static WebMercator _mercator = new WebMercator(); . . . foreach (Graphic graphic in gpLayer.FeatureSet.Features) { graphic.Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as Symbol; graphic.Geometry = _mercator.FromGeographic(graphic.Geometry); graphicsLayer.Graphics.Add(graphic); } But then it just gets in a loop and never outputs anything. How does the Viewer for Silverlight handle the point results of a geoprocess? (Since that outputs the results correctly.)
... View more
07-28-2011
05:34 AM
|
0
|
0
|
488
|
|
POST
|
Hi, I've created a geoprocessing service that takes a few string inputs and creates a random point feature class (well, it's a little more complex than that, but that is basically what it does). It works fine inside of arcmap. I then created a test page using the new beta version of the ArcGIS Viewer for Silverlight, adding the tool. It also works perfectly and displays the results exactly where they should be. Now I'm creating a custom silverlight page for the tool. I followed all the example code I've seen and while it correctly makes the points (as I can see in the arcgisjobs folder), it displays them all around 0,0 (off of Africa). So it seems the projection is off. The app uses the regular web_mercator_aux, but my geoprocessing script uses a geographic coordinate system (and I need to keep it as such, gcs_north_american_1983). I've tried setting the task's "OutputSpatialReference" and "ProcessSpatialReference" to mymap.SpatialReference as well setting the graphics' geometry.SpatialReference to the same thing, all with no luck. So, 2 questions. One, since the viewer displays them correctly, any chance we could get at the outputted source code?? And two, more realistically, any idea how I can convert the points to the correct system? Thanks private void GeoprocessorTask_GetResultDataCompleted(object sender, GPParameterEventArgs e) { GraphicsLayer graphicsLayer = MyMap.Layers["StationLayer"] as GraphicsLayer; GPFeatureRecordSetLayer gpLayer = e.Parameter as GPFeatureRecordSetLayer; foreach (Graphic graphic in gpLayer.FeatureSet.Features) { graphic.Symbol = LayoutRoot.Resources["RedMarkerSymbol"] as Symbol; graphicsLayer.Graphics.Add(graphic); } }
... View more
07-27-2011
12:06 PM
|
0
|
4
|
813
|