|
POST
|
Where did you change these settings? I can't see anything in our Organisations AGOL account on the web.
... View more
09-20-2018
05:23 PM
|
0
|
1
|
3354
|
|
POST
|
I found a solution. I had a niggling feeling that it was the comparisons between original and current extent that was not behaving the way I expected. I originally thought this would be the best indication of the map having moved/changed based on the features in the layers. After seeing the scale print statements and how fine they were (i.e. oldscale = 404659.559547) I figured it would be highly unlikely these would ever occur twice. Thus, I changed the code from comparing original and current extent to scales and now it works as expected. Can't thank you enough for your help with this!
... View more
09-18-2018
07:08 PM
|
0
|
0
|
1213
|
|
POST
|
Thanks for your help. Glad we at least got the index issues sorted! I'll have to look into python 3. Anything in particular here that won't talk in the new version? I'm guessing the syntax has changed?
... View more
09-18-2018
07:03 PM
|
0
|
1
|
1213
|
|
POST
|
That makes sense and works (insert face plant here). The part that I must have been getting hung up on though is the desire for this to be returning a typical scale concentrated on a small area (i.e. 1:20,000), meaning that the logic I've used to get the map to focus on the grouped features isn't working as expected. Fore example. Before running the script, the map is focused on a selection of polygons in one location (EIG > 0 and EIGA = 0). I run this script to change the definition query to look at a different selection of polygons in a different location (where EIG = 0 and EIGA > 0). The code should examine the if query at Line 43 as False and skip to the next ELIF (Line 47) resulting in an unchanged dataframe extent (at this point). Next it should examine the if EIGA > 0 (Line 51) as TRUE then set the current extent variable. Line 54 sees the current extent compared to the original extent (should result in TRUE) and proceed to Line 55. It would apply the layer extent to the dataframe and step up to the next in the list. That should be the end of it but for some reason it is progressing through to the elif at Line 61 and finding that TRUE. I would expect this to be FALSE because the current_ext and orig_ext variables are unchanged (to my knowledge) despite the dataframe extent being updated so should result in no further action being taken. What actually seems to be happening is the code is running the ELIF (Line 61) as TRUE and comparing the min/max values from the old extent and the new extent resulting in a huge scale. This should only be getting run if there are new features in both layers which will be similarly geolocated. This does work as expected when both layers > 0.
... View more
09-18-2018
06:40 PM
|
0
|
4
|
7651
|
|
POST
|
I've eliminated a big chunk of code that doesn't apply to this MXD so the lines are different from the original but I've been trying to factor that into my post/responses. Still looks correct to me though here? I added in the print statements and this is the result when running a query where EIG = 0 and EIGA > 0 (sorry if I'm formatting this wrong - trying to break it up into the info/error sections). Executing: UpdateDefinitionQueries "Lake Muir 2" LM2 # # MLM7AFC
Start Time: Wed Sep 19 08:48:54 2018
Running script UpdateDefinitionQueries...
Entered In GeoMaster definition query updated
Entered In GeoMaster Archive definition query updated
scalelist: [5000, 7500, 10000, 12500, 20000, 25000, 30000, 40000, 50000, 60000, 70000, 75000, 80000, 90000, 100000]
old scale: 404659.559547
Failed script UpdateDefinitionQueries...
Traceback (most recent call last):
File "W:\Mapping\ToolboxPythonCodes\SCRIPTS\Update Definition Queries.py", line 78, in <module>
newscale = scalelist[bisect(scalelist, oldscale)] # bisect old scale to get new scale
IndexError: list index out of range
Failed to execute (UpdateDefinitionQueries). Failed at Wed Sep 19 08:49:05 2018 (Elapsed Time: 10.25 seconds)
... View more
09-18-2018
05:54 PM
|
0
|
6
|
7651
|
|
POST
|
Thanks Vince for the tip. I've updated the original code snippet so hopefully I have that correct now. This still isn't helping the "list index out of range" error though at line 78.
... View more
09-18-2018
05:35 PM
|
0
|
8
|
7651
|
|
POST
|
It was intended to just skip that section of code if it didn't meet the count criteria (no features so no need to apply the layer extent to the data frame extent). I assumed that if it didn't meet that criteria it would just move on to the next valid bit of code instead or needing an ELIF. Have I figured that incorrectly?
... View more
09-17-2018
04:55 PM
|
0
|
10
|
7651
|
|
POST
|
The code below seems to function correctly most of the time except when running through a situation where line 43 is False (no extent updates based on this layer) and Line 51 is True (1+ feature in this layer), meaning Line 54 is also True (extent set at Line 22 should still match extent at Line 52). What I'm not understanding is 2 things: 1. Why is it running through the elif at Line 61 when the condition should be False (as per Line 54 being True) 2. Why when it does run through the elif at Line 61 I get the below Trackback error about the list Index being out of range when it works elsewhere in the same manner? Hope that all makes sense! import arcpy
from arcpy import env, mapping
from bisect import bisect
#input parameters;
Plantation = arcpy.GetParameter(0)
ForestID = arcpy.GetParameter(1)
CommonName = arcpy.GetParameter(2)
PYear = arcpy.GetParameter(3)
OpCode = arcpy.GetParameter(4)
#variables;
title1 = Plantation + " PLANTATION"
title2 = Plantation + "\r\nPLANTATION"
title3 = Plantation + " (" + CommonName + ")"
title4 = Plantation + " P" + PYear + " AREA STATEMENT"
mxd = mapping.MapDocument("CURRENT")
elements = mapping.ListLayoutElements(mxd)
layers = mapping.ListLayers(mxd)
HTL_layer_list = ["Entered In GeoMaster", "Entered In GeoMaster Archive"]
dflist = arcpy.mapping.ListDataFrames(mxd, "")
orig_ext = dflist[0].extent
new_exp = "PLANTATION = '" + Plantation + "'"
new_sur_exp = "PLANTATION <> '" + Plantation + "'"
as_new_exp = "EnteredInGeoMaster IS NOT NULL AND Plantation = '" + Plantation + "'"
opcode_exp1 = "Entered_In_GeoMaster IS NOT NULL AND Ops_Code = '" + OpCode + "'"
opcode_exp2 = "Ops_Code = '" + OpCode + "'"
scalelist = [5000, 7500, 10000, 12500, 20000, 25000, 30000, 40000, 50000, 60000, 70000, 75000, 80000, 90000, 100000]
if mxd.title <> ("Cutting Returns Entered in GeoMaster"):
###other code here###
elif mxd.title == ("Cutting Returns Entered in GeoMaster"):
mxd.activeView = "Page_Layout"
for lyr in layers:
if lyr.name == "Entered In GeoMaster":
lyr.definitionQuery = opcode_exp1
arcpy.AddMessage(lyr.name + " definition query updated")
EIGfeature_count = arcpy.GetCount_management(lyr)[0]
if EIGfeature_count > 0:
ext = lyr.getExtent() #gets the new extent of the Entered In GeoMaster layer
dflist[0].extent = ext #applies the Entered In GeoMaster layer extent to the dataframe
elif lyr.name == "Entered In GeoMaster Archive":
lyr.definitionQuery = opcode_exp2
arcpy.AddMessage(lyr.name + " definition query updated")
EIGAfeature_count = arcpy.GetCount_management(lyr)[0]
if EIGAfeature_count > 0:
current_ext = dflist[0].extent
if current_ext == orig_ext:
ext = lyr.getExtent() #gets the new extent of the Entered In GeoMaster layer
dflist[0].extent = ext #applies the Entered In GeoMaster layer extent to the dataframe
oldscale = dflist[0].scale # Get scale of dataframe
newscale = scalelist[bisect(scalelist, oldscale)] # bisect old scale to get new scale
dflist[0].scale = newscale # Apply new scale to dataframe
elif current_ext <> orig_ext:
# get current map extent
xmin, xmax = dflist[0].extent.XMin, dflist[0].extent.XMax
ymin, ymax = dflist[0].extent.YMin, dflist[0].extent.YMax
# loop through def query layer extents and create one extent to fit them all
lyr_ext = lyr.getExtent()
if lyr_ext.XMin < xmin:
xmin = lyr_ext.XMin
if lyr_ext.YMin < ymin:
ymin = lyr_ext.YMin
if lyr_ext.XMax > xmax:
xmax = lyr_ext.XMax
if lyr_ext.YMax > ymax:
ymax = lyr_ext.YMax
# set df extent to new extent
dflist[0].extent = arcpy.Extent(xmin, ymin, xmax, ymax)
oldscale = dflist[0].scale # Get scale of dataframe
newscale = scalelist[bisect(scalelist, oldscale)] # bisect old scale to get new scale
dflist[0].scale = newscale # Apply new scale to dataframe
elif lyr.name == "PlantationsHarvestPlan_OperationsPlanner_WA":
lyr.definitionQuery = new_exp
arcpy.AddMessage(lyr.name + " definition query updated") Traceback (most recent call last):
File "W:\Mapping\ToolboxPythonCodes\SCRIPTS\Update Definition Queries.py", line 78, in <module>
newscale = scalelist[bisect(scalelist, oldscale)] # bisect old scale to get new scale
IndexError: list index out of range For reference, the aim here is to updated the definition queries on 2 layers in an open MXD, check for features in each layer and zoom the extent to view all the features in both layers before stepping the scale up (using bisect) to the next round scale in the list.
... View more
09-16-2018
11:53 PM
|
0
|
12
|
12257
|
|
POST
|
Thanks. I'm going to try both solutions and I think both will likely work form the logic I'm reading.
... View more
09-16-2018
05:13 PM
|
0
|
0
|
3617
|
|
POST
|
Good pickup on the missing "for lyr in layers" statement. The code was a cut down of a larger script and I missed copying the first line of that section so that's all good. I'll give the "if HTL_lyr.name in HTL_layerl_list:" section a try and see what happens. Thanks!
... View more
09-16-2018
05:12 PM
|
0
|
0
|
3617
|
|
POST
|
Hi All. I'm trying to run the below python code with no luck. The 2 layers listed on line 20 are referenced again on line 37 when I attempt to cycle through their extents. The code should pull the extents and apply them to the data frame. The issue is that the list at line 20 won't work unless there are no spaces in the layer names. If enclose the names in "..." then the code is "syntax error free" but fails at line 37 when trying to extract the extent of a string object instead of a layer. How can I work around this (would prefer to not have to rename my layers in the mxd!). import arcpy
from arcpy import env, mapping
from bisect import bisect
#input parameters;
Plantation = arcpy.GetParameter(0)
ForestID = arcpy.GetParameter(1)
CommonName = arcpy.GetParameter(2)
PYear = arcpy.GetParameter(3)
OpCode = arcpy.GetParameter(4)
#variables;
title1 = Plantation + " PLANTATION"
title2 = Plantation + "\r\nPLANTATION"
title3 = Plantation + " (" + CommonName + ")"
title4 = Plantation + " P" + PYear + " AREA STATEMENT"
mxd = mapping.MapDocument("CURRENT")
elements = mapping.ListLayoutElements(mxd)
layers = mapping.ListLayers(mxd)
HTL_layer_list = ["Entered In GeoMaster", "Entered In GeoMaster Archive"]
dflist = arcpy.mapping.ListDataFrames(mxd, "")
opcode_exp1 = "EnteredInGeoMaster IS NOT NULL AND Ops_Code = '" + OpCode + "'"
opcode_exp2 = "Ops_Code = '" + OpCode + "'"
if lyr.name == "Entered In GeoMaster":
lyr.definitionQuery = opcode_exp1
arcpy.AddMessage(lyr.name + " definition query updated")
elif lyr.name == "Entered In GeoMaster Archive":
lyr.definitionQuery = opcode_exp2
arcpy.AddMessage(lyr.name + " definition query updated")
# get current map extent
xmin, xmax = dflist[0].extent.XMin, dflist[0].extent.XMax
ymin, ymax = dflist[0].extent.YMin, dflist[0].extent.YMax
# loop through def query layer extents and create one extent to fit them all
for HTL_lyr in HTL_layer_list:
HTL_ext = HTL_lyr.getExtent()
if HTL_ext.XMin < xmin:
xmin = ext.XMin
if HTL_ext.YMin < ymin:
ymin = ext.YMin
if HTL_ext.XMax > xmax:
xmax = ext.XMax
if HTL_ext.YMax > ymax:
ymax = ext.YMax
# set df extent to new extent
dflist[0].extent = arcpy.Extent(xmin, ymin, xmax, ymax)
... View more
09-14-2018
12:29 AM
|
0
|
5
|
3809
|
|
POST
|
Looks like the short answer is not really. It appears to not be a tool that's available in the Toolbox but rather a menu item, so no anatomy to examine. Might have to send this one to an ESRI contact.
... View more
09-02-2018
09:10 PM
|
0
|
1
|
2576
|
|
POST
|
Is it possible to access the "Create Local Copy for Editing" and "Synchronize Local Edits with Server" functions using python? I have a tool that transfers data from one AGO layer to another but has manual steps requiring the user to download local copies of both layers, run the tool and then synchronize both layers again. Making a local copy of a feature service for editing—Help | ArcGIS for Desktop I would like to be able to automate the download/upload part of the process too as it happens at a set extent each time so is predictable. Is this possible? I can't see anything from my Googling and searching of GeoNet.
... View more
09-02-2018
07:06 PM
|
0
|
6
|
2927
|
|
POST
|
We have layer file setup that uses Unique values to create the Symbology. We currently edit the Label of each Symbol to include an Area amount in the legend next to each symbol. This layer changes from time to time though and the labels need to be manually edited to reflect the new Area totals. Is there a way to import labels based on the unique values used to categorise the symbols (using Python maybe?). If this is possible, then when the total area changes for a given value, we could rerun a script that would calculate the total area for each value, concatenate the value and area text before importing the text as the new label for the corresponding value in the Symbology. The main reason for this is that we don't want to have to redo the "Add All Values" and lose the customised colour schemes setup. William kalande
... View more
07-03-2018
06:45 PM
|
0
|
0
|
818
|
|
IDEA
|
I've just been looking around to see if this functionality was included. Apparently not. I hope it is in the future as it would be a great little feature to have extended to labeling! Trying to make my first Vector Tile Basemap and finding all these great tools.
... View more
01-23-2018
10:46 PM
|
3
|
0
|
7584
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | Monday | |
| 3 | Sunday | |
| 2 | Sunday | |
| 1 | Sunday | |
| 1 | 05-19-2026 05:02 PM |
| Online Status |
Offline
|
| Date Last Visited |
Tuesday
|