POST
|
@SteveCole , I seem recall from a python class that you need to "del" your "theCursor" to close the table/layer. So on line 77 in your script put "del theCursor" at the far left. You may already know that, but the documentation doesn't really mention anything about deleting cursors, when you're done with that table. I hope that helps a little.
... View more
a week ago
|
0
|
1
|
95
|
POST
|
Your little script is almost correct. I had to change nam[0:1] to nam[0:2], because the "c" got skipped and yielded MDavid. The following works, and yields McDavid. Thanks so much!!! def FindLabel ( [STN] ):
nam = [STN].lower()
nam = nam.replace("mc", "Mc")
nam = nam[0:2] + nam[2].capitalize() + nam[3:]
return nam
... View more
02-13-2024
12:34 PM
|
1
|
1
|
275
|
POST
|
That partially works. STN.replace("MC", "Mc") returns McDAVID. What I want is McDavid. Thanks for your help. I'll keep trying.
... View more
02-13-2024
12:09 PM
|
0
|
3
|
288
|
POST
|
I have a featureclass of street names where all of the names are in uppercase. I can set a label class using an expression STN begins with "MC%", but I want python to label the streets starting with MC to convert the label to proper case, for example, MCDAVID would be McDavid. Does anyone have a suggestion for using python to do this? I've already tried using [STN].title(), but that yields Mcdavid. Thanks for the suggestions.
... View more
02-13-2024
10:09 AM
|
0
|
6
|
363
|
IDEA
|
@Bud , you sort of can. I create a polygon from four lat./long. coordinates. I collect four sets of coordinates from emails for marking utilities. I think that the array is actually a list, but in this instance it works like an array. After this portion of code, I use an UpdateCursor to add attributes to the new polygon in a feature-class. FYI, I'm still on Pro 2.9, so I'm using arcpy version 2. fc = r"C:\myPython.gdb\AZ811_BlueStake"
iCursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])
array = arcpy.Array([arcpy.Point(lonX_NW, latY_NW),
arcpy.Point(lonX_NE, latY_NE),
arcpy.Point(lonX_SE, latY_SE),
arcpy.Point(lonX_SW, latY_SW)])
# Spatial reference set to GCS_WGS_1984
spatial_reference = arcpy.SpatialReference(4326)
polygon = arcpy.Polygon(array, spatial_reference)
iCursor.insertRow([polygon])
del iCursor
... View more
10-31-2023
02:07 PM
|
0
|
0
|
324
|
POST
|
#JasmineSpring, one thing you need to do after using any cursor, is you need to del the cursor. Your code should look something like this... import arcpy
# Get the selected layer
layer = arcpy.GetParameterAsText(0)
# Create a list of field names starting with "poa"
poa_fields = [field.name for field in arcpy.ListFields(layer) if field.name.startswith("poa")]
for field in poa_fields:
with arcpy.da.UpdateCursor(layer, poa_fields) as cursor:
for row in cursor:
if row[0] is None:
row[0]="1"
cursor.updateRow(row)
del cursor
# Use the Field Calculator to calculate the product
expression = "1" if not poa_fields else " * ".join([f"!{field}!" for field in poa_fields])
arcpy.CalculateField_management(layer, "Product_poa", expression, "PYTHON") (see line 15).
... View more
10-25-2023
03:24 PM
|
0
|
1
|
548
|
POST
|
Here's an earlier post "Programmatically select layer definition query" found here https://community.esri.com/t5/arcgis-parcel-fabric-questions/programmatically-select-layer-definition-query/td-p/1114999 See also - "Delete vs deactivate layer definition query"- https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313695
... View more
09-21-2023
10:17 AM
|
0
|
0
|
696
|
POST
|
#xavro, here's a link that will get you started. https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/specifying-a-query.htm
... View more
09-21-2023
09:40 AM
|
0
|
0
|
743
|
POST
|
I've had the same problem. I am forced to set the map's layout scale after my feature is drawn from the x/y coordinates. Here's a snippet of what I do after running a script that collects data from a "utility marking request" that draws the feature from Lat/Long coordinates. lyt = aprx.listLayouts()[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "MainMapFrame")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
mf.camera.scale = 24000.0 After the script runs, I have to zoom to the feature using Pro (version 2.9). I think Esri needs to make the getLayerExtent() to allow for a percentage, like when you "zoom to selected feature" or for a map book layout where you can set a percentage for the feature extent in Pro. Maybe you could submit it as a Python Idea. Just a thought.
... View more
08-23-2023
12:37 PM
|
0
|
1
|
454
|
POST
|
@adamwade1 , the only solution that I found to work was to use the function provided by @RogerDunnGIS on 02-02-2023 08:37 AM (see above in this thread).
... View more
08-16-2023
12:00 PM
|
0
|
0
|
1366
|
POST
|
I tried to set the definitionQuery property to "" and None. All that happened was the layer's definition query was made inactive and the new definition query was created and made active. Thanks for your advice. I will just have to accept that I will have to delete the old definition query from within the aprx.
... View more
07-31-2023
04:11 PM
|
1
|
0
|
540
|
POST
|
I finally figured out how to REMOVE/DELETE the definition query from a specific layer in a specific map. Ultimately, I used the Cartographic Information Model (cim) to access the definitionExpression. I read through the Python CIM access web page. https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/python-cim-access.htm In my aprx file, I right-clicked the map's name and selected "Save As Map File" the map(s), and them opened the *.mapx file as a *.json file. Next, I searched through the file for the "definitionExpression" field. After trying a bunch of things, I finally found that I want to change the layers "featureTable.definitionExpression" to equal "". Here's my code. import arcpy
# Reference a project, map, and layer using arcpy.mp
aprx = arcpy.mp.ArcGISProject('current')
m = aprx.listMaps("Inset")[0]
lyr = m.listLayers("AZ811 BlueStake")[0]
# Return the layer's CIM definition
cim_lyr = lyr.getDefinition('V2')
# Modify the featureTable.definitionExpression
cim_lyr.featureTable.definitionExpression = ""
# Push the changes back to the layer object
lyr.setDefinition(cim_lyr)
... View more
07-31-2023
01:50 PM
|
1
|
3
|
544
|
POST
|
@RogerDunnGIS, Thanks for providing this function. I'm really new to python, so please correct me if I'm wrong. If I understand your function correctly, I need to provide two variables to the function: "layer", and "sqlFilter" that the function uses? How do I call/use your function? Thanks so much for your help.
... View more
07-31-2023
09:33 AM
|
0
|
1
|
1471
|
POST
|
@Anonymous User Thanks for your suggestions. I FINALLY figured it out. I set the mf.camera.scale. aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("811Tickets")[0]
lyr = m.listLayers("AZ811 BlueStake")[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "MainMapFrame")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
mf.camera.scale = 25200.0
... View more
07-28-2023
03:47 PM
|
0
|
0
|
546
|
POST
|
Thanks for your help @Anonymous User . Unfortunately, when I tried your suggestion... aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("811Tickets")[0]
lyr = m.listLayers("AZ811 BlueStake")[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "MainMapFrame")[0]
lyrExt = mf.getLayerExtent(lyr, False, True)
mf.panToExtent(lyrExt)
mf.camera.setExtent(lyrExt) I found that it works the same as... aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("811Tickets")[0]
lyr = m.listLayers("AZ811 BlueStake")[0]
lyt = aprx.listLayouts()[0]
mf = lyt.listElements("mapframe_element", "MainMapFrame")[0]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True)) I'm trying to stay at a scale of 1:25,200, but the both of these scripts zoom to the feature's/layer's extent. If I figure it out, I'll post my corrected script.
... View more
07-28-2023
02:13 PM
|
0
|
0
|
562
|
Title | Kudos | Posted |
---|---|---|
1 | 02-13-2024 12:34 PM | |
1 | 07-31-2023 04:11 PM | |
1 | 07-31-2023 01:50 PM | |
2 | 07-24-2023 11:16 AM | |
4 | 07-14-2023 11:54 AM |
Online Status |
Offline
|
Date Last Visited |
2 hours ago
|