POST
|
Hello Kirsten, Apologies for reviving an old post but did you ever get an answer to this? I have the same issue! Cheers, Gino
... View more
01-05-2017
10:44 PM
|
0
|
2
|
607
|
POST
|
Thanks Dan. Yep, I don't know why it does this, I would think it if it works the first time it should have reference to the layer set correctly, not sure why it would lose it after the first run? This tool is designed to work with layers in a particular MXD so in this instance I just grabbed the layer from the TOC and used its datasource property as the input. Will keep your suggestion in mind when I need to reference the script folder however 🙂 Cheers, Gino
... View more
11-01-2016
04:29 PM
|
0
|
0
|
425
|
POST
|
FYI I decided to hard-code the featurelayers path into the validation code and it works fine. I still cannot explain the behaviour in my previous post.
... View more
10-31-2016
09:50 PM
|
0
|
2
|
425
|
POST
|
Hello, I have a custom python script and tool which is designed to allow a user to select and zoom to a locality. Param[0] is a feature layer (containing locality boundaries) and param[1] is a multi value list which is populated from a field in the selected feature layer in param[0]. If I open the MXD and open the tool the localities in param[1] populate perfectly. If I use the tool to select a particular locality and zoom to it the script will run perfectly. However, if I then reopen the tool to use it again the only value which will be populated in param[1] is the locality value I used when I previously ran the tool and not all the locality values. I cannot get this to reset until I close the MXD and open it fresh again. The validation code is attached. Can anyone please tell me what I am doing wrong? I am sure it is something terribly simple which I am not seeing... Cheers, Gino
... View more
10-31-2016
12:01 AM
|
0
|
4
|
1107
|
POST
|
Hello, Apologies, I understand this is a basic issue but it confuses me. I have a script tool which I am writing in python to work with a particular MXD. In this script tool I have the following lines of code to reference two layers in the MXD's TOC. subjectLayer = arcpy.mapping.ListLayers(mxd,subjectlayerName)[0] subjectLayer.definitionQuery = "" cadastralLayer = arcpy.mapping.ListLayers(mxd,"Cadastre")[0] arcpy.AddMessage( cadastralLayer) #To test if layer is set correctly cadastralLayer.definitionQuery = "" The subjectLayer object gets set correctly. This is chosen as a parameter in the tools UI. The definition query also gets set correctly.The cadastralLayer object gets populated also (AddMessage shows grouplayername\layername) but I get a "Script failure: 'unicode' object has no attribute 'definitionQuery'" error when it tries to set a definition query on it. This object is set by referencing the layer name in the TOC. My question is why is one a unicode and the other a layer object as they were both referenced using ListLayers? How do I correctly reference layers in the TOC? Thanks in advance.
... View more
09-23-2015
12:42 AM
|
0
|
2
|
3172
|
POST
|
You have helped someone...me! I was getting error 000229 trying to batch merge and buffer 10 or so layers and had tried various work-arounds including removing them from grouplayers but nothing worked. Clicked background processing off and it worked flawlessly. Thank you for posting this!
... View more
09-20-2015
11:47 PM
|
1
|
0
|
810
|
POST
|
Thanks for the advice above Kevin, I have implemented it into a single script and it now works great! Cheers, Gino
... View more
05-31-2015
06:49 PM
|
1
|
0
|
556
|
POST
|
Hi Kevin, Thanks for the great info. The reason I wanted 2 services was for 2 reasons. The first is mainly for neatness, combined the two tools have 17 parameters and I thought this may be a problem for people using this app on smaller screens/laptops. Secondly, I plan to use the first tool to create 'queries' of the data, so the user could extract more than one query per session. Then I planned to have a drop down list in the second tool where the user could choose which one of this query layers to perform the geoprocessing on. This would allow the user to operate only on the area of interest and not the whole dataset which will probably cause the request to time out on the server. However in saying this your advice above does make sense to me. I think I will try and put these scripts into a model and run them as one overall tool. Will have a go and let you know the results. Once again, thanks for your help! Cheers, Gino
... View more
05-28-2015
04:31 PM
|
0
|
0
|
556
|
POST
|
Hello, I am building a web app using arcgisonline and the web app builder. I have 2 custom python script tools, the first creates a layer from a list of OIDs from GenerateNearTable, the second performs some geoprocessing operations on this layer. This works fine in desktop but when I publish them to a web app (using arcgis online and the web app builder) I cannot access the layer from the first task in the second task. The layer is there, it displays fine, it is just not in the choice list for the second task. The second geoprocessing task has the rest of the layers as options as well as the original layer I used to create the gp result in desktop to publish from. Is it possible to use the output of one gp task as an input to another? If so would someone be kind enough to give me some insight as too how? Is this a ridiculous idea to begin with (pls be gentle, it is my first web app )? Thanks to all in advance. Cheers, Gino
... View more
05-27-2015
11:58 PM
|
0
|
3
|
4234
|
POST
|
Hi Kevin, After some re-jigging of the code it appears to be working as you say now, still in 10.1. I believe (not 100% sure on this) the issue was fixed by using the "CURRENT" MXD and making sure .save() was performed on the map document object after the definition query was set. Thank you for your help. I have attached the code in case anyone else may find it useful. Regards, Gino import arcpy import os import re import datetime #-------------------PARAMETERS-------------------------------------------------- textfilePath = arcpy.GetParameterAsText(0) # Path to text file with parcel descriptions. outputFolder = arcpy.GetParameterAsText(1) # Out folder path exportdataCheckbox = arcpy.GetParameterAsText(2) # Checkbox to export data to a geodatabase. #------------------------------------------------------------------------------- def ReadTextFile(path): textFile = open(path, "r") lines = textFile.readlines() textFile.close return lines def ExportKMZ(lotplan): try: # Output file name. If a file of the same name exists then delete it # and create a new file outKMZ = os.path.join(outputFolder,lotplan, "lot" + lotplan + "_" + today + ".kmz") if arcpy.Exists(outKMZ): os.remove(outKMZ) # Get layer extent rectangle and remove superfluos information. The # remaining coordinates should be in format LL UR extent = subjectLayer.getSelectedExtent(False) cleanextent = re.sub('[A-Za-z]', '', str(extent)) # Create KMZ arcpy.MapToKML_conversion(mxd.filePath,"KMZExportMap", outKMZ,"0","NO_COMPOSITE","VECTOR_TO_IMAGE",cleanextent,"1024","96","CLAMPED_TO_GROUND") arcpy.AddMessage("KMZ exported: " + outKMZ) except Exception, e: arcpy.AddError(e.message) print e.message def CreateOutputFolder(cleanlotplan): # Create a project folder if needed global outFolder outFolder = os.path.join(outputFolder,cleanlotplan) if not os.path.exists(outFolder): os.makedirs(outFolder) def ExportSubject(cleanlotplan): try: # Create a project geodatabase if needed if not arcpy.Exists(os.path.join(outFolder, "Data_" + today +".gdb")): arcpy.CreateFileGDB_management(outFolder, "Data_" + today +".gdb") # Create a subject layer in geodatabase global outGDB # Create object as 'global' as it will be used 'ron outGDB = os.path.join(outFolder, "Data_" + today +".gdb") subjectlayerName = os.path.join(outGDB,"SubjectLot" + cleanlotplan + "_" + today) if arcpy.Exists(subjectlayerName): arcpy.Delete_management(subjectlayerName) # Export subject features arcpy.CopyFeatures_management(subjectLayer, subjectlayerName ) arcpy.AddMessage("Subject parcels exported to: " + subjectlayerName) del subjectlayerName except Exception, e: arcpy.AddError(e.message) print e.message def ExportDataToGeodatabase(cleanlotplan): try: # Get extent from 'extent_layer' object desc = arcpy.Describe(subjectLayer) extent = desc.extent arcpy.env.workspace = outGDB arcpy.AddMessage("Old Exten: " + str(arcpy.env.extent)) arcpy.env.extent = extent arcpy.AddMessage("Old Exten: " + str(arcpy.env.extent)) # Iterate layers and export to GDB. Check to see if layer is a # featurelayer and is not missing datasources. layers = arcpy.mapping.ListLayers(mxd) for layer in layers: if "Data Group" in layer.longName and layer.isFeatureLayer == True: outlayerPath = os.path.join(outGDB,layer.datasetName + "_" + today) arcpy.CopyFeatures_management(layer, outlayerPath) arcpy.AddMessage("Layer (" + layer.name + ") exported to: " + outlayerPath) # Refresh view and TOC arcpy.RefreshActiveView arcpy.RefreshTOC except Exception, e: arcpy.AddError(e.message) finally: # Reset geoprocessing environment settings arcpy.ResetEnvironments() arcpy.AddMessage("Subject parcel list: " + textfilePath) arcpy.AddMessage("Output location: " + outputFolder) # Get parcel description from .txt file lotplanList = ReadTextFile(textfilePath) # Get MXD, etc. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "KMZExportMap") [0] subjectLayer = arcpy.mapping.ListLayers(mxd,"Subject Lot Plan", df)[0] # global variables outFolder = None outGDB = None failedexportList = [] # Get date today = re.sub('[-]',"",str(datetime.date.today())) # Iterate items in list for lotplan in lotplanList: try: # Remove whitespace and capitalise lotplan cleanlotplan = lotplan.strip().upper() arcpy.AddMessage("Processing lot description: " + cleanlotplan) whereClause = """"LOTPLAN" = '""" + cleanlotplan + "'" subjectLayer.definitionQuery = whereClause # Save mxd so the definition query is picked up in the KMZ export mxd.save() # Use feature count to determine if lot/plan was found. count = int(arcpy.GetCount_management(subjectLayer).getOutput(0)) # Conditional statement to determine if a feature(s) within the subject # layer match the lotplan used in definition query. If count is 0 then # not matching feature were found - move to next lot/plan. If count > 0 # then the parcel has been found. Call geoprocessing and export routines # using the parcels details to create the outputs. if count > 0: arcpy.AddMessage("Found parcel: " + cleanlotplan) # Create main output folder for lot description CreateOutputFolder(cleanlotplan) # If selected export ESRI data if str(exportdataCheckbox) == "true": ExportSubject(cleanlotplan) ExportDataToGeodatabase(cleanlotplan) ExportKMZ(cleanlotplan) else: arcpy.AddWarning("Could not find parcel: " + cleanlotplan) failedexportList.append(lotplan) except Exception, e: arcpy.AddError(e.message) finally: # Always remove deinition query before processing the next lotplan subjectLayer.definitionQuery = None # Create text file to store unfound parcel descriptions. txtfilePath = os.path.join(outputFolder,"UnfoundLots_" + today + ".txt") txtFile = open(txtfilePath, "a") if len(failedexportList) > 0: for lot in failedexportList: txtFile.write(lot) txtFile.flush() txtFile.close() del txtFile del failedexportList del outFolder del outGDB del subjectLayer del mxd del lotplanList
... View more
05-27-2014
04:26 PM
|
0
|
0
|
784
|
POST
|
Hi Kevin, That could be the difference - I am still running 10.1 SP1 as that is what the internal clients I support are running and also I still believe it is the official version for our Dept according to IT 😞 Perhaps I will need to convince IT to upgrade. Thanks for you help! If I get a workable solution for this in 10.1 I will post it. Cheers, Gino
... View more
05-25-2014
04:11 PM
|
0
|
0
|
784
|
POST
|
Hi Kevin, I have plugged an MXD into it and the extraction happens fine...except...the definition query is not honoured by the MapToKML tool. I need the subject lot to be the only parcel from the cadastral layer to be exported to KMZ. At the moment the script will export that parcel and all other parcels from the cadastral layer which are within the extent here. extent = subjectLayer.getSelectedExtent(False) I think this is just the way the tool works and have now resolved to finding a workaround. The options I am considering are exporting the parcel to a new temporary layer and running MapToKML or attempting to use a uniquevaluerenderer and only add the value for the subject parcel - I am not having any luck with the latter at the moment. When I have a suitable workaround I will post but in the mean time any help is greatly appreciated. Cheers, Gino
... View more
05-22-2014
04:05 PM
|
0
|
0
|
784
|
POST
|
Hi Ian, See below for my code - please excuse my general messiness as I am new to python. The list of cadastral parcels is just a .txt file with a separate description (lot/plan) on each line. Thanks for you reply, any help is appreciated 🙂 Cheers, Gino #-------------------PARAMETERS--------------------------------------------------
textfilePath = r"C:\_TEMP_SSD_PERFORMANCE\ToKML Test\SLATS1011_LotPlans2.txt"
mxdPath = r"C:\_TEMP_SSD_PERFORMANCE\ToKML Test\ExportToKMZ.mxd"
outputFolder = r"C:\_TEMP_SSD_PERFORMANCE\ToKML Test\Outputs"
#-------------------------------------------------------------------------------
import arcpy
import os
import re
def ReadTextFile(path):
textFile = open(path, "r")
lines = textFile.readlines()
textFile.close
return lines
def Extract(lotplan, extent):
try:
outKMZ = os.path.join(outputFolder, lotplan + ".kmz")
if arcpy.Exists(outKMZ):
os.remove(outKMZ)
cleanextent = re.sub('[A-Za-z]', '', str(extent))
arcpy.MapToKML_conversion(mxdPath,"KMZExportMap", outKMZ,"0","NO_COMPOSITE","VECTOR_TO_IMAGE",cleanextent,"1024","96","CLAMPED_TO_GROUND")
except Exception, e:
print e.message
# Get parcel description from .txt file
lotplanList = ReadTextFile(textfilePath)
# Get MXD, etc.
mxd = arcpy.mapping.MapDocument(mxdPath)
df = arcpy.mapping.ListDataFrames(mxd, "KMZExportMap") [0]
subjectLayer = arcpy.mapping.ListLayers(mxd,"Subject Area", df)[0]
# Iterate parcels, apply definition query and export
for lotplan in lotplanList:
cleanlotplan = lotplan.strip()
whereClause = """"LOTPLAN" = '""" + cleanlotplan + "'"
subjectLayer.definitionQuery = whereClause
extent = subjectLayer.getSelectedExtent(False)
print cleanlotplan
Extract(cleanlotplan,extent)
subjectLayer.definitionQuery = None
del subjectLayer
del mxd
del lotplanList
... View more
05-21-2014
03:05 PM
|
0
|
0
|
784
|
POST
|
Hi All, My apologies if this should have been posted elsewhere (python maybe?) - please move if it is. I am attempting to use python to iterate a list of properties and run the MapToKML tool so that it will create a KML showing that cadastral parcel and any surrounding data within the other layers in the MXD. The subject lot is specified by using a definition query on the subject/cadastral layer to show ONLY that lot - the extent of the layer is then used with the MapToKML tool so that the surrounds are picked up. This all works fine. The issue I am having is that the same extents worth of parcels are being exported from the subject layer also - i.e. Map To KML is not honouring the definition query (see attached - the subject layer is the heavier black line). Is there a way to get this to honour the definition query? Should I be using the Layer To KML (Conversion) and iterating over layers individually? Am I going about this whole process in completely the wrong way - I am not sure - any advice/help welcome 😉 Thanks in advance, Gino
... View more
05-20-2014
11:44 PM
|
0
|
8
|
4517
|
POST
|
Thanks for the replies guys, they are very much appreciated. Neil, that is exactly what I was after! Thanks again!
... View more
10-13-2013
04:35 PM
|
0
|
0
|
495
|
Title | Kudos | Posted |
---|---|---|
1 | 09-01-2020 02:43 PM | |
1 | 11-23-2020 04:39 PM | |
1 | 11-09-2017 08:46 PM | |
1 | 07-26-2020 01:18 PM | |
1 | 09-20-2020 07:13 PM |
Online Status |
Offline
|
Date Last Visited |
12-20-2022
06:14 AM
|