POST
|
Well, I have garbage collector (gc) enabled, and if I ever use cursors I habitually del them when I'm done with them. But, I have the data creation section of the script commented out for my current test runs, so there isn't any geoprocessing going on before the export section runs right now. The only thing I have printing to the interactive window right now is when it starts - and is done with - each map PNG. Are there other things I can do do free up memory while exporting?
... View more
07-31-2015
11:20 AM
|
0
|
0
|
1055
|
POST
|
Has anyone else had problems with scripts that export PNGs not working after upgrading versions of ArcGIS? I have a windows box that runs a script using arcpy each day to export > 900 PNGs. For the last year it's been running fine, with ArcGIS 10.0. Last week I decided it was finally time to upgrade... I uninstalled ArcGIS 10.0 and installed ArcGIS 10.3. My other scripts (that make 50 maps as opposed to 900) continued to work just fine. However, when running the big script, python stops working after about 30 maps have been exported. This happens whether the script is running via Task Manager or if I'm running it manually using IDLE. The timing of the failure is not consistent, some times it makes more maps than others. But, it always fails sooner or later. I'm including a screenshot of the error dialog boxes I get when running the script with IDLE. I tried exporting JPGs instead of PNGs and got the same error. I tried lowering the dpi of the images and it didn't help. I even uninstalled ArcGIS 10.3 and installed ArcGIS 10.2.2, hoping that it was just an issue with 10.3 - but that did not fix it either. Any other ideas?
... View more
07-31-2015
09:53 AM
|
2
|
8
|
3798
|
POST
|
Hi Jorge, thanks for your fast reply, and sorry for my slow one. I've had a chance to dig back into this task. Having the leader lines in polygon form works for me. I can make center lines out of the polygon outlines. I've now had to try doing this for a couple of different annotation feature classes. Sometimes, Feature to Polygon works fine the first time. Once, Feature to Polygon did not work, but Feature Class to Shapefile (multiple) did work, so that was a good idea. But with another annotation feature class, neither works. I'm stumped as to why this happens so (seemingly) randomly.
... View more
03-04-2015
05:15 PM
|
0
|
0
|
928
|
POST
|
I have an annotation feature class. Some of the annotation features have leaders. What I to end up with is a feature class of lines that represent the leader lines from the annotation. I know that in the past, I have been able to run a geoprocessing tool like Feature To Polygon on my annotation feature class, with the result being polygons for the both text boxes and the leader lines. For some reason I can't yet figure out, this is not happening with the annotation feature class I am working on now. The tool is only giving me a polygon for the text box, and nothing for the leader line. This has been the case using Feature To Line and Feature Envelope To Polygon as well. I've tried running this using both ArcGIS 10.2 and 10.1, with the same result. The only strange thing I have noticed about this annotation feature class is that, when I add it to my ArcMap session, the annotation classes with leaders are automatically turned off in the table of contents. Also, when I view the annotation feature class in the ArcCatalog preview pane, the leaders do not show up. All the attributes appear OK (they are placed, have assigned symbol IDs, etc.). Below is a quick screenshot. The annotation feature class is showing with its arrow and dot leaders. The green polygons (on top of the annotation) are the result of the Feature To Polygon tool. What I really need is for features to be created for the leader lines as in addition to the text boxes... but they are just not made.
... View more
09-22-2014
09:42 AM
|
0
|
3
|
5591
|
POST
|
I downloaded and installed MySQLdb to access data on our SQL databases. It was the first thing I tried that worked and I've just been using it ever since.
... View more
09-11-2014
09:58 AM
|
0
|
0
|
1238
|
POST
|
Thank you! I was finally able to get back around to my project today. This is exactly what I needed, a functioning example. I think part of my problem may have been that I was not defining a function when selecting the stations within the buffer circle. I was just doing this:
fLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
var selGraphics = fLayer.getSelectedFeatures();
and then looping through the objects in selGraphics. I have also never used "lang.hitch()" before. Something new to read up on! Side note, the code posted is a little different from the "Select with Feature Layer" sample code that I see on the Samples page now... interesting. Thanks for your help! Now I can move forward with this web map!
... View more
09-04-2014
12:25 PM
|
0
|
0
|
952
|
POST
|
OK, there has GOT to be a way to do this that I'm just not seeing on my own. I have a feature layer of points (stations) in my map. The task is to find the three points in the feature layer that are closest to where the user clicks on the map (and then display data from those stations, etc...). So far, I have been able to select all points within a 50-mile radius circle of the clicked-point, and I have saved the points' names/IDs and locations (as point geometry) to an array. Next, I want to loop through the objects in the array I've just made, and for each, find its distance from the clicked-point (using the geometryService.distance method). Then I add the station's name and distance to a new array/list. My plan from there is to figure out which three stations are the closest, and get the data I need to display, etc. My problem is that the code is looping through the array faster than it can figure out each distance. In my second array/list, every distance has the same station name, which happens to be the name of the last station in the first array. I know that the result of the geometryService.distance method is a deferred object. I've been trying to educate myself on these. I think I get the jist of deferreds, but I can't figure out how to make them work for me here. I have seen suggestions by some to use a deferred list, but it appears that you have to know how many items you want in that list beforehand. In my case, I don't know exactly how many points will be within that 50-mile radius of the user's clicked-point. Here is my javascript code as it stands. At this point, my feature layer (named fLayer) already has the points within the 50-mile radius selected.
var selGraphics = fLayer.getSelectedFeatures();
var feature;
list = [];
for (i = 0; i < selGraphics.length; i++) {
var stnname;
feature = selGraphics;
stnname = feature.attributes["Name"];
uoid = feature.attributes["uid"];
ptloc = feature.geometry;
list.push({name:stnname, uid:uoid, loc:ptloc});
}
console.log('outside first loop now');
console.log(list);
distlist = [];
for (i in list) {
station = list
console.log(station);
ptloc = station.loc;
distParams.geometry2 = ptloc;
thisdist = geometryService.distance(distParams, function(distance) {
console.log(station.name, distance);
distlist.push({name:station.name, dist:distance});
});
}
console.log('outside second loop now');
console.log(distlist);
BTW, I am much more comfortable with python than I am with javascript/html, hence my personal need to use lists/arrays. If there is a better way to deal with this I'm open to suggestion! Thanks!
... View more
08-22-2014
03:59 PM
|
0
|
2
|
2908
|
POST
|
Is the ability to create custom symbols in a script for use in a layer renderer (using ArcPy) anywhere near the horizon? I was able to do this using VBA when I had ArcGIS 9.3, and I miss this ability.
... View more
07-30-2014
04:02 PM
|
0
|
2
|
689
|
POST
|
Thank you very much for the advice! I added the Integrate tool to my script, in addition to adjusting the environment XY Resolution (0.0001 Feet) and Tolerance (0.001 Feet) at the beginning of the script. Now everything appears to be working the way I wanted. In addition, I also found that keeping a tiny search radius of 0.001 Feet (instead of leaving the parameter blank) for the Split Line at Point tool yielded better results for me. Thanks again!
... View more
04-07-2014
08:57 AM
|
1
|
0
|
3845
|
POST
|
Just wondering if anyone else has seen this / has any quick suggestions. I'm currently using ArcGIS 10.0 I am running the 'Split Line At Point' tool in a script. My inputs are in a feature dataset - I have a feature class of lines (streams) and a feature class of points. The points were created previously in the script using the 'Make Route Event Layer' and 'Feature Class to Feature Class' tools, so they are located along the lines. I'm using a search radius of '1 FEET' and for the output, creating a new feature class in the same feature dataset. When examining the output split lines and comparing them to the points, the lines are not always split where the points are at. Sometimes they are just not split where a point is. Sometimes they are split where a point does not exist. I can say that the majority of the time, the lines have been split correctly. It appears that the problem occurs where there are many points are near each other (within a few feet). I'm experimenting with different resolution/tolerance settings for the feature dataset, but right now this does not appear to be helping. Any ideas? I'm including an image with two screenshots of this issue. The green points are where the lines are supposed to be split. The brown lines are the output, symbolized with a black dot at each end, showing where the lines actually have been split. [ATTACH=CONFIG]32699[/ATTACH]
... View more
04-01-2014
02:18 PM
|
0
|
5
|
11059
|
POST
|
Using python dictionaries/lists helped a lot! Thanks to everyone for your answers. This part of the script still had to be run over night, but that is way faster than what I was doing before. # Make some dictionaries and lists for population and area
totalpopdict = {}
areadict = {}
totalareadict = {}
allblockids = []
allhuc8s = []
rows = arcpy.SearchCursor(finalblocks)
for row in rows:
blockid = str(row.BLOCKID10)
thisblockpop = str(row.POP10)
totalpopdict[blockid] = thisblockpop
thisblockarea = row.Shape_Area
thisblockhuc8 = str(row.HUC_8)
thisblockidhuc8 = blockid + '_' + thisblockhuc8
areadict[thisblockidhuc8] = thisblockarea
if blockid in totalareadict:
oldtotalarea = totalareadict[blockid]
newtotalarea = thisblockarea + oldtotalarea
totalareadict[blockid] = newtotalarea
else:
totalareadict[blockid] = thisblockarea
allblockids.append(blockid)
allhuc8s.append(thisblockhuc8)
del rows, row
gc.collect()
# Make lists of the unique blockids and huc8s
blockids = []
[blockids.append(value) for value in allblockids if not blockids.count(value)]
huc8s = []
[huc8s.append(value) for value in allhuc8s if not huc8s.count(value)]
# Calculate a dictionary with number of block pieces
gc.collect()
blkpiecesdict = {}
thisblockhuc8s = areadict.keys()
for blockid in blockids:
count = 0
for thisblockhuc8 in thisblockhuc8s:
if thisblockhuc8[:15] == blockid:
count += 1
blkpiecesdict[blockid] = count
print 'gathered needed info into lists and dictionaries'
# Calculate a list with population estimates
gc.collect()
popestlist = []
for blockid in blockids:
for huc8 in huc8s:
thisblockidhuc8 = blockid + '_' + huc8
if thisblockidhuc8 in areadict:
totalpop = float(totalpopdict[blockid])
totalarea = float(totalareadict[blockid])
numpieces = blkpiecesdict[blockid]
if numpieces > 1:
thisarea = areadict[thisblockidhuc8]
pctarea = thisarea / totalarea
pctpop = pctarea
thispop = totalpop * pctpop
elif numpieces == 1:
thispop = totalpop
thisarea = totalarea
pctpop = 1.0
pctarea = 1.0
else:
thispop = 0
thisarea = 0.0
pctpop = 0.0
pctarea = 0.0
line = [blockid, huc8, totalpop, thispop, pctpop, totalarea, thisarea, pctarea, numpieces, thisblockidhuc8]
popestlist.append(line)
# Make a CSV out of the data we have (to be joined to the finalblocks feature class)
gc.collect()
f = open(csv, 'w')
headerline = 'UniqueID,BLOCKID,HUC8,TotalPop,ThisPop,PctPop,TotalArea,ThisArea,PctArea,NumPieces,BlkID_HUC8' + '\n'
f.write(headerline)
for line in popestlist:
logline = str(popestlist.index(line)) + ',' + str(line[0]) + ',' + str(line[1]) + ',' + str(line[2]) + ',' + str(line[3]) + ',' + str(line[4]) + ',' + str(line[5]) + ',' + str(line[6]) + ',' + str(line[7]) + ',' + str(line[8]) + ',' + str(line[9])
logline = logline + '\n'
f.write(logline)
f.close()
# Convert the CSV into GDB table
desc = arcpy.Describe(csv)
fields = desc.fields
fieldinfo = arcpy.FieldInfo()
for field in fields:
print field.name
fieldinfo.addField(field.name, field.name, 'VISIBLE', '')
csv_view = 'csv_' + dtime
arcpy.MakeTableView_management (csv, csv_view, '', '', fieldinfo)
arcpy.TableToTable_conversion (csv, FGDB, csv_view, '', '', '')
newtable = FGDB + '\\' + csv_view
newtable_view = 'newtable_' + dtime
arcpy.MakeTableView_management (newtable, newtable_view)
# Make Table View of the finalblocks feature class
finalblocks_view = 'finalblocks_' + dtime
arcpy.MakeTableView_management (finalblocks, finalblocks_view)
# Join the CSV to the finalblocks feature class based on blockid
arcpy.JoinField_management (finalblocks_view, 'BlkID_HUC8', newtable_view, 'BlkID_HUC8')
print 'Join performed'
# Calculate the POP10_est field
arcpy.CalculateField_management (finalblocks_view, 'POP10_est', '[ThisPop]', 'VB')
print 'POP10_est field calculated'
print datetime.datetime.today()
... View more
11-28-2012
11:54 AM
|
0
|
0
|
652
|
POST
|
When working with large datasets I typically follow this workflow: 1. Use a search cursor to load the entire dataset into a Python dictionary (i.e. into memory). 2. Process all of the records using the data in the dictionary. 3. Use an update cursor to update the entire dataset with the results. I'm not sure what's the bottleneck in your code but the above will save the time consumed by MakeTableView and GetCount processes and the creation of an update cursor for every block id. Let me know if some pseudocode would help explain ths further. I think I understand what you're saying... basically, get the data from the feature class's table into a list or array (or is 'dictionary' a term that means something else?), and then do the heavy-duty processing from there...? If you have the time, some pseudocode would probably help... It looks like I am going to have to set this project aside for the time being, to work on some higher-priority items. I'll post again when I am able to try out your idea. Thanks Brad!
... View more
11-07-2012
02:34 PM
|
0
|
0
|
652
|
POST
|
If you are on 10.1, have you considered using the new Data Access module (arcpy.UpdateCursor vs arcpy.da.UpdateCursor)? http://resources.arcgis.com/en/help/main/10.1/#/What_is_the_data_access_module/018w00000008000000/ The cursors are considerably faster. Jeff Actually, I am using 10.0. I'll talk to our GIS Manager about getting 10.1... If/when I am able to upgrade, I'll look into using the Data Access module. Thanks Jeff!
... View more
11-07-2012
02:09 PM
|
0
|
0
|
652
|
POST
|
Here's what I'm doing - I have a polygon feature class of census blocks with populations. I have split these census blocks based on watershed boundaries (side, note, many of the blocks fall completely within a watershed and were not split). Now... each piece of each block that was split up still has the total population for that block attributed to it. I'm trying to figure out an estimate of the population for each piece of each block. For each piece of each block, I'm calculating the percent of a block's total area that piece is, and finally applying that percent-of-area to the block's total population. I am running this for an entire state. By my estimate, if the script takes 16 seconds to calculate each census block, it will take nearly 84 days to run... That's no good. I know there are a lot of cursors running, but I can't think of a better way to do this off the top of my head. The cursor(s) should be looking at a table view, which normally has only 1 - 3 records. 'blockids' is a list with each unique BLOCKID. "finalblocks" is the variable standing for my census blocks feature class. blockcounter = 1 for blockid in blockids: # Make Table View of all polygons with this blockid block_view = 'block_view' + blockid wclause = '"BLOCKID10" = \'' + blockid + "'" arcpy.MakeTableView_management (finalblocks, block_view, wclause) bcount = arcpy.GetCount_management(block_view) print str(bcount) + ' block pieces for ' + blockid + '... ' + str(blockcounter) + ' of ' + str(len(blockids)) rows = arcpy.UpdateCursor(block_view) for row in rows: blockpop = str(row.POP10) if blockpop <> '0': if str(bcount) <> '1': # If this block ID has multiple pieces and total population is not 0 totalarea = 0.0 totalpop = 0.0 for row in rows: totalarea += row.Shape_Area for row in rows: thisarea = row.Shape_Area pctarea = thisarea / totalarea totalpop = row.POP10 thispop = totalpop * pctarea row.POP10_est = thispop rows.updateRow(row) else: # If there is only one polygon for this block ID for row in rows: row.POP10_est = row.POP10 rows.updateRow(row) else: # If the total population of this block is 0 anyway for row in rows: row.POP10_est = 0 rows.updateRow(row) del rows, row blockcounter += 1 Thank you in advance for any help!
... View more
11-06-2012
07:58 AM
|
0
|
9
|
768
|
POST
|
Try using your feature layer (F_PORTALES) as the input for the CalculateField tool, instead of the original feature class (PORTALES)?
... View more
04-08-2011
07:29 AM
|
0
|
0
|
569
|
Title | Kudos | Posted |
---|---|---|
1 | 04-07-2014 08:57 AM | |
2 | 01-06-2011 07:44 AM | |
1 | 01-27-2023 12:33 PM | |
3 | 06-18-2020 03:48 PM | |
1 | 02-11-2016 03:53 PM |
Online Status |
Offline
|
Date Last Visited |
07-11-2024
07:57 PM
|