|
POST
|
I'll bring this up to see if there is a way it can be made more efficient at the tool level. Delete_management may not be helping because it deletes data from disk (First sentence in Summary - Delete) Meanwhile, MakeNetCDFTableView_md holds the Table Views in memory (First point in Usage - MakeNetCDFTableView) As Dan points out, the third point in Usage states 'An existing table view will be overwritten if the same table view name is entered.' If you can use the same name repeatedly it will effectively handle the delete for you, and should have a steady memory footprint. It also may be a good idea to use a Generator Expression instead of lists/loops? Generators are very helpful when reaching memory limits, as they process a single item at a time. Under the hood this often allows the resources to be released earlier than they would otherwise.
... View more
08-04-2017
11:14 AM
|
0
|
0
|
772
|
|
POST
|
Yes good point, that will work and makes it more robust.
... View more
08-04-2017
10:28 AM
|
1
|
0
|
5748
|
|
POST
|
Assuming the tables are small enough to be held in memory, you can use set comparisons: paths = {'table1': r'path\t1', 'table2': r'path\t2'}
sets = map(lambda t: {row for row in arcpy.da.SearchCursor(t, arcpy.ListFields(t))}, paths.values()]
if len(sets[0] - sets[1]) > 0:
arcpy.management.DeleteRows(paths['table1'])
arcpy.management.Append(paths['table2'], paths['table1']) edit: This compares the entire tables, not row-by-row, I might have misunderstood what you wanted..
... View more
08-04-2017
10:23 AM
|
1
|
0
|
4080
|
|
POST
|
Hello Vishal, There are some issues with your if statements, so currently the script will never make it to the SelectLayerByAttribute call. The first conditional is: fieldList = arcpy.ListFields('Target Feature')
fieldName = ['Field3']
fieldValue = ['%45B%']
if fieldName in fieldList: fieldName is a list, since you surrounded it with square brackets. So you are checking if a list holding 'Field3' is in fieldList, not the 'Field3' string itself. The result of arcpy.ListFields contains Field objects which possess a name Property - so we can use a list comprehension to extract them. The result will look something like: ['Field1', 'Field2', 'Field3'], so we can see ['Field3'] isn't inside, however 'Field3' by itself is. This post explains how to search for a list of values within another list, and may help clear it up further. The second conditional: if fieldValue in fieldName: Has a similar issue - The list ['%45B%'] does not exist inside ['Field3'], which again has no sublists. At this point, instead you may want to check the value of each row inside 'Target Feature', this is where Cursors come in. However, for what you are trying to do in this script, Cursors are unnecessary, I just wanted to mention them for your benefit. You don't need to use cursors, because the arcpy.SelectLayerByAttribute_management() tool allows you to provide a query, which you are doing in your above example. This loops through the feature class automatically, cursors loop through it manually. So therefore, we just need a single conditional statement in this case. With these changes, this should be the result: import arcpy
fieldList = arcpy.ListFields('Target Feature')
fieldName = 'Field3'
fieldValue = '%45B%'
# list comp to extract field names
if fieldName in [f.name for f in fieldList]:
query = "Field3 LIKE " + "'" + str(fieldValue) + "'"
arcpy.SelectLayerByAttribute_management ('Target Feature', NEW_SELECION, query) Its also worth mentioning, in case you run into it, that in some cases 'Target Feature' won't be enough and you may need the full path to the dataset on disk. (Shoutout to vangelo-esristaff for a reminder on the Field objects )
... View more
08-04-2017
09:50 AM
|
3
|
8
|
5748
|
|
POST
|
Looks like there is one more step missing. The max() function in Python returns the maximum value in a list, so you seem to have a list of the values. Is there a corresponding list of segments? If so, you can get the index of the maximum value using: segments = ['a', 'b', 'c', 'd', 'e']
l = [1,2,3,2,1]
i = l.index(max(l))
# 2
segments[i]
# 'c'
... View more
08-02-2017
04:00 PM
|
1
|
1
|
942
|
|
POST
|
Looks like you're on the right track, however I think its over complicated a little doing a spatial join for each row. Instead you can use Geometry Objects and their spatial operations. It is easier to work with the more modern arcpy.da.SearchCursor and UpdateCursor when you want to access the geometry of your feature classes. Here is an example of using this method: from arcpy.da import SearchCursor
from arcpy.da import UpdateCursor
COH_ADDRESS = "C:\\Users\\mclbr\\Desktop\\AddressTest.gdb\\Places\\COH_Address"
TAXLOTS_NOAT = "C:\\Users\\mclbr\\Desktop\\AddressTest.gdb\\TAXLOTS_NOAT"
arcpy.AddField_management(COH_ADDRESS, 'TLNO', 'TEXT')
# SHAPE@XY gives us the centroid
coh_fields = ['SHAPE@XY', 'TLNO']
# SHAPE@ gives us the Geometry object
taxlots_fields = ['SHAPE@', 'TLNO']
# using a list allows us to loop over the cursor multiple times
coh_list = [i for i in UpdateCursor(COH_ADDRESS, coh_fields)]
taxlots = SearchCursor(TAXLOTS_NOAT, taxlots_fields)
# for each taxlot
for taxlot in taxlots:
# Find coh rows with no TLNO and centroids within taxlot
# [i for i in coh_cursor if not i[1]] is a list comprehension which
# returns only coh_list rows with TLNO = None, to reduce the amount of
# compares per iteration as the values are set.
for coh_address in [i for i in coh_list if not i[1]]:
# if so, update that row with the TLNO from taxlot
if coh_address[0].within(taxlot[0]):
coh_address[1] = taxlot[1]
coh_address.updateRow()
... View more
08-02-2017
12:15 PM
|
0
|
0
|
699
|
|
POST
|
If you don't use 3rd-party packages in your code then you should be able to share the .pyt file as-is over a network share. If you're importing packages that aren't present in the base installation (ie: via pip (10.x) or conda (Pro) and importing them in your .pyt) then you will need to ensure that those packages are installed on consumers' machines as well. Alternatively, if you're sharing with more tech-savy colleagues, you could host the .pyt on a site like github.com - this will make it easier to ensure everyone is using the same version of your file, if you need make any changes. I'm happy to elaborate on anything if you'd like, let me know.
... View more
08-01-2017
05:17 PM
|
1
|
0
|
1112
|
|
POST
|
(Continued conversation from https://community.esri.com/thread/192139-arcgis-pro-141-failed-to-load-system-tools-please-restart-arcgis-pro#comment-70375… ) Based off your comment "I had ArcGIS Pro 1.4 installed to C:\ArcGISPro because it gave me an option of where I wanted to install it." In the other thread, and seeing the line conda.CondaError: Unable to determine if prefix 'C:\ArcGISPro\bin\Python' is writable I think your registry is still pointing to the 1.4 install. We use the paths set in the registry for some of the bootstrapping our envs need to do to avoid PATH collisions. Are you able to run regedit or is that not possible on this machine?
... View more
07-28-2017
11:17 AM
|
0
|
2
|
1224
|
|
POST
|
This specific issue should be fixed for 2.0, since we updated the .dll - however there are still some potential quirks. Did you install 2.0 fresh or upgrade from a previous version? If upgrading your previous files may not have been overwritten which could cause version incompatibility which leads to this error. You can delete the %ProInstall%\bin\Python\envs\arcgispro-py3 folder and 'repair installation' via the installer to recreate the fresh environment. You do not need to add Pro's Python to PATH, however if working from the command line the environment needs to be activated. You can either use Start>ArcGIS>Python Command Prompt to bring up a prompt with the env already activated, or launch python.exe from within the arcgispro-py3 folder. Let me know and we'll get it figured out!
... View more
07-27-2017
11:25 AM
|
2
|
2
|
1004
|
|
POST
|
Hello Ionut, It looks like something unusual has happened to your installation, I unfortunately can't seem to reproduce the issue so I'll give some general advice: If the environment is broken, you can delete the 'arcgispro-py3' folder in %proInstall%\bin\Python\envs and rerun the installer, select 'repair installation' and it will recreate the fresh environment for you. Jupyter Notebook creates shortcuts in the start menu, so may need Admin privileges to install correctly. (You should get a UAC pop-up in the Pro package manager in this case.) Click the refresh button in the Pro package manager (blue circular arrows above package list) to get the latest versions of the package list. 'arcgis' is up to version 1.2.0 - there have been a few issues with packages shipped from Continuum Analytics that are outside of our control which may cause problems. (See this thread) Anaconda is fairly aggressive in setting your system's PATH variable - double check that it isn't causing confusion. Its odd on the last screenshot to see Python 3.4 and 3.5 referenced on the same operation. Currently arcpy is part of the Pro folder structure and not a 'pure' package, so it is not supported to install via Anaconda. (Working on this as we speak, should be supported soon.) As per Curtis' post it is possible to do currently but I can't guarantee things will work if you choose to follow those instructions. Hopefully that helps a bit and gets you back to a working state. If you continue to have problems let us know!
... View more
07-27-2017
11:14 AM
|
1
|
1
|
12937
|
|
POST
|
I believe the easiest way to approach this would be to create a dictionary with keys of all the points which represent connections between pipes, and a value that is a list of all the pipe classes which connect at that point. Then for each line, check the points that touch the line for the class value matching your criteria for that selection.
... View more
07-19-2017
12:18 PM
|
0
|
0
|
805
|
|
POST
|
The string.replace() function does not change the string in place, it returns a new string with the replaced words. Instead you could do: feet_list = ["1000 feet", "23908 feet", "1200000000 feet"]
meter_list = []
for area in feet_list:
s = area.replace("feet", "meters")
meter_list.append(s)
print(meter_list)
# ['1000 meters', '23908 meters', '1200000000 meters']
Or alternatively: meter_list = [f.replace("feet", "meters") for f in feet_list]
print(meter_list)
# ['1000 meters', '23908 meters', '1200000000 meters']
... View more
06-30-2017
11:40 AM
|
1
|
0
|
3558
|
|
POST
|
Yeah its not something I've used often, just saw the snippet in the docs and figured it was a different approach worth trying. I also just found this tutorial which looks better than the PIL approach, uses OffsetImage and AnnotationBox: pylab_examples example code: demo_annotation_box.py — Matplotlib 2.0.2 documentation
... View more
06-27-2017
02:58 PM
|
0
|
0
|
8793
|
|
POST
|
In the matplotlib docs there are some examples using PIL (Python Image Library) to resize the image before plotting: In [16]: from PIL import Image
In [17]: img = Image.open('../_static/stinkbug.png')
In [18]: img.thumbnail((64, 64), Image.ANTIALIAS) # resizes image in-place
In [19]: imgplot = plt.imshow(img) Perhaps give that a try?
... View more
06-26-2017
11:48 AM
|
1
|
2
|
8793
|
|
POST
|
There is a python.exe within the %Pro%\bin\Python\envs\arcgispro-py3 folder which should work if set as a project interpreter in PyCharm.
... View more
06-23-2017
10:18 AM
|
2
|
1
|
1780
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-23-2016 11:51 AM | |
| 1 | 12-27-2016 03:58 PM | |
| 1 | 11-28-2016 09:17 AM | |
| 1 | 12-08-2016 05:09 PM | |
| 1 | 12-28-2016 12:00 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:25 AM
|