POST
|
You could use the in memory workspace. Then the feature class only exists in memory and will be discarded after the script is finished running. import arcpy
arcpy.env.workspace = "in_memory"
... View more
10-27-2016
10:52 AM
|
1
|
1
|
408
|
POST
|
Here is a Python function that does what you need: def fill_donut(in_lyr):
'''Edits a layer in-place and fills all donut holes or gaps in the selected
features. Will operate on entire layer if there are no features selected.
Requires layer to honor selected features.
'''
desc = arcpy.Describe(in_lyr)
shapefield = desc.ShapeFieldName
rows = arcpy.UpdateCursor(in_lyr)
n = 0
polyGeo = arcpy.Array() # to hold edited shape
polyOuter = arcpy.Array() # to hold outer ring
for row in rows:
feat = row.getValue(shapefield)
qInterior = False
for partNum in range(feat.partCount) :
part = feat.getPart(partNum)
for pt in iter(lambda:part.next(),None) : # iter stops on null pt
polyOuter.append(pt)
if part.count > len(polyOuter) :
qInterior = True
polyGeo.append(polyOuter) # reassemble each part
polyOuter.removeAll() # ready for next part
if qInterior : # in any part of this feature, otherwise skip update
n+=1
row.setValue(shapefield,polyGeo)
rows.updateRow(row)
polyGeo.removeAll()
del rows,row
msg = "Features with interior ring filled "+str(n)
arcpy.AddMessage(msg)
arcpy.RefreshActiveView()
... View more
10-25-2016
06:28 AM
|
1
|
0
|
1572
|
POST
|
Are you missing some code in the above block? Is there a line later in the code where you call SummaryStats? In order to execute the code you would have to call SummaryStats like so: SummaryStats(DistrictConfig) I'm not sure I understand why you have 2 functions. It looks like the second one just calls the first one. And your comments are different ways you would like to run it? I would just have one function and call it 3 times (or 21 times). # Define the funtion
def DistrictFunction(DistrictConfig, distfc, totalexpression, totalscline, statsfield, fields,TotalLong):
print "Calculating Total Line Tickets per District"
arcpy.MakeFeatureLayer_management(linefc, unique_name, totalexpression)
arcpy.Statistics_analysis(unique_name, totalscline , statsfield, "DISTRICT")
arcpy.JoinField_management(distfc, "NAME", totalscline, "DISTRICT", fields)
with arcpy.da.UpdateCursor(distfc, ["FREQUENCY"]) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
#Calculate and Join Totals per District Polys
arcpy.MakeFeatureLayer_management(polyfc, unique_name, totalexpression)
arcpy.Statistics_analysis(unique_name, totalscpoly , statsfield, "DISTRICT")
arcpy.JoinField_management(distfc, "NAME", totalscpoly, "DISTRICT", fields)
with arcpy.da.UpdateCursor(distfc, ["FREQUENCY_1"]) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
arcpy.CalculateField_management(distfc, TotalLong, totalCalc)
arcpy.DeleteField_management(distfc, ["FREQUENCY", "FREQUENCY_1"])
# Call the function 3 times
try:
DistrictFunction(DistrictConfig, distfc, totalexpression, totalscline, statsfield, fields, TotalLong)
DistrictFunction(DistrictConfig, distfc, totalexpression, totalscpoly, statsfield, fields, TotalLong)
DistrictFunction(DistrictConfig, distfc, overDueExpression, overDueLine, statsfield, fields, OverDueTotal)
except Exception as e:
logger.info(e.message, exc_info=True)
raise e
... View more
10-24-2016
10:54 AM
|
0
|
0
|
2089
|
POST
|
Functions use variables to define parameters (stuff inside the parenthesis that can change each time you call the function). In the above code you are defining your functions, but you are not executing them. # Define function
def do_something(variable1, variable2):
# do something with variable1
# do something with variable2
# Call the function
do_something(x, y)
# Call the function again using different values
do_something(a, b) The first time I called the function ‘x’ was plugged in for variable1 and ‘y’ was plugged in for variable2. The second time I called the function ‘a’ was plugged in for variable1 and ‘b’ was plugged in for variable2.
... View more
10-24-2016
10:07 AM
|
1
|
2
|
2089
|
POST
|
I have 250 layers in a map service and I need pop-ups enabled for all of them. Is there a way to enable pop-ups in all layers in a map at once? I'm fine with accepting all the default field names and values, I just don't want to have to go through each layer individually to enable the pop-up.
... View more
10-03-2016
03:06 PM
|
0
|
0
|
863
|
POST
|
I thought about doing that, but felt like it would look odd to the public to see a map and there be no data in the map. I wound up using an AppStudio free template, Quick Report. It does everything I need except send alerts. It's great because there is no map visible to the app users, the map is only visible behind the scenes using AGOL.
... View more
06-17-2016
06:51 PM
|
0
|
0
|
469
|
POST
|
I have created an web app using the web app builder. One of the feature layers has pop-ups that contain links that take you to a certain page in a pdf for each feature. The pop-up configuration link is below. Item is an attribute column that refers to the pdf and Page is a column that refers to the page number in the pdf. http://___________.maps.arcgis.com/sharing/rest/content/items/{Item}/data#page={Page} The pdfs are stored on ArcGIS Online so when you click on the link, the app redirects you to an amazon server. It works great in Firefox and Chrome, but IE seems to strip the '#page={Page}' part during the redirection. Then the pdf opens at the first page. Is there a workaround for this?
... View more
06-02-2016
08:08 AM
|
0
|
0
|
1169
|
POST
|
I'm looking to create mobile app similar to the Citizen Problem Reporter, but with the map and other reports not visible to the public. So the app should be pretty basic, take a photo, report an issue. And then have the map and all the data available behind the scenes for the organization. Another component would be custom alerts that periodically go out to app users. Does something like this exist? Would downloading the source code for citizen reporter make it possible to create this app? Would it be better to look for a app builder outside of ArcGIS Online? Any suggestions?
... View more
06-02-2016
07:49 AM
|
0
|
2
|
2898
|
POST
|
I am working on a near analysis that determines the closest distance from a polygon layer to one of three other vector layers. The polygon layer relates to the three other layers using EO ID. When I determine the closest distance, I want to only be looking at records with the same EO ID. Here is the Python code that I came up with: # Copy the input feature class so the near fields can be added
arcpy.FeatureClassToFeatureClass_conversion(in_fc, out_path, out_name, subset_query)
out_fc = os.path.join(out_path, out_name)
# Create search cursor to loop though records in the output feature class
srows = arcpy.da.SearchCursor(out_fc, ["EO_ID"])
for srow in srows:
# Convert eoid to an integer
eoid = int(srow[0])
# Create EO ID queries
eoid_query = "{0} = {1}".format(eoid_field, eoid)
sf_eoid_query = "EO_ID = {}".format(eoid)
# Make feature layers using eoid queries
arcpy.MakeFeatureLayer_management(out_fc, "out_lyr", eoid_query)
arcpy.MakeFeatureLayer_management(src_1, "src1_lyr", sf_eoid_query)
arcpy.MakeFeatureLayer_management(src_2, "src2_lyr", sf_eoid_query)
arcpy.MakeFeatureLayer_management(src_3, "src3_lyr", sf_eoid_query)
# Run near analysis
arcpy.Near_analysis("out_lyr", ["src1_lyr","src2_lyr","src3_lyr"]) When I run this code I get a PyScripter application error: Access violation at address 56D0E49C in module 'FileGDB.dll'. Write of address B2689930. When I run the script in IDLE I get "pythonw.exe has stopped working" Thanks so much for your help. ArcGIS 10.2 Python 2.7 PyScripter 2.5.3x86 32 bit Windows 7 64 bit
... View more
12-05-2014
12:49 PM
|
0
|
0
|
2142
|
POST
|
True it only hides the fields, but then when I export to Excel shouldn't it only export the fields that are in the table view? The end goal is to get to an Excel table. I could use the table to table tool and field mappings or copy the feature class and delete fields before exporting, but I was trying bypass making a new GIS file before exporting to Excel.
... View more
11-21-2014
10:33 AM
|
0
|
1
|
1308
|
POST
|
I have a feature class that I would like to export the attributes to Excel, while excluding certain fields. I know I could make a copy of the feature class and delete fields, but I would like to use the field info object to exclude the unnecessary fields while creating a table view. The following code still exports all the fields, can you tell me what I am missing? After creating the table view I have tried, using copy rows instead of export to excel and got the same results. I also tried fieldinfo.removeField(index) for the fields I want to exclude but that returned an error (RuntimeError: ERROR 999999: Error executing function). Thanks for your help.
#---- Make Table View that only contains the needed fields and copy to Excel table
# Get the fields from the input feature class
fields= arcpy.ListFields(in_fc)
# Create a fieldinfo object
fieldinfo = arcpy.FieldInfo()
# Iterate through the fields and set them to fieldinfo
for field in fields:
# If field name is in list of fields to keep,
if field.name in out_fields:
# Add to fieldinfo object
fieldinfo.addField(field.name, field.name, "VISIBLE", "")
# Make the table view with only desired fields
arcpy.MakeTableView_management(in_fc, "table_view", field_info = fieldinfo)
# Copy to Excel table
arcpy.TableToExcel_conversion("table_view", out_table)
... View more
11-21-2014
09:21 AM
|
0
|
4
|
4964
|
POST
|
1. Right click on your new field, to get to the field calculator 2. Click the Python radio button 3. Check the Show Codeblock box 4. In the Pre-Logic Script Code box, copy and paste this function: def get_num_from_string(string):
'''This function retrieves numbers from a string and converts them to integers'''
# Create empty string to store numbers as a string
num = ''
# Loop through characters in the string
for i in string:
# If one of the characters is a number, add it to the empty string
if i in '1234567890':
num+=i
# Convert the string of numbers to an integer
integer = int(num)
return integer 5. Then in the bottom box, type this (but replace ADDRESS, with the name of your address field): get_num_from_string(!ADDRESS!) Hint: Choose long integer as your datatype for the new field. Or if you want to keep it a string, make the function return "num" instead of "integer"
... View more
12-24-2013
05:59 AM
|
4
|
0
|
3784
|
POST
|
The help documentation says that the tool "Removes the specified toolbox, either by specifying its path or referencing its alias." The example in the help shows how to use the tool with the full pathname, but not using the alias. I want to write a script that removes a custom python toolbox using the toolbox alias instead of the path, but I cannot get it to work. This is how it is supposed to work:
import arcpy
def print_custom_tbxs():
toolboxes = arcpy.ListToolboxes()
provided_toolboxes = ["3D Analyst Tools(3d)", "Analysis Tools(analysis)", "Coverage Tools(arc)", "Cartography Tools(cartography)", "Conversion Tools(conversion)", "Data Interoperability Tools(interop)", "Data Management Tools(management)", "Editing Tools(edit)", "Geocoding Tools(geocoding)", "Geostatistical Analyst Tools(ga)", "Linear Referencing Tools(lr)", "Multidimension Tools(md)", "Network Analyst Tools(na)", "Parcel Fabric Tools(fabric)", "Samples(samples)", "Schematics Tools(schematics)", "Server Tools(server)", "Spatial Analyst Tools(sa)", "Spatial Statistics Tools(stats)", "Tracking Analyst Tools(ta)"]
print "Imported toolboxes:"
for toolbox in toolboxes:
if toolbox not in provided_toolboxes:
print toolbox
print_custom_tbxs()
print
arcpy.ImportToolbox(r"E:\Tools\General_Tools.pyt")
print_custom_tbxs()
print
arcpy.RemoveToolbox(r"E:\Tools\General_Tools.pyt")
print_custom_tbxs()
print The above code produces the below print statements: >>> Imported toolboxes: Imported toolboxes: General_Tools(gen) Imported toolboxes: >>> But then I replace the RemoveToolbox line and use the toolbox alias instead of the full pathname, and none of these lines work: arcpy.RemoveToolbox("General_Tools_gen")
arcpy.RemoveToolbox("gen")
arcpy.RemoveToolbox("General Tools (gen)")
arcpy.RemoveToolbox("(gen)")
arcpy.RemoveToolbox("General Tools - gen") I get this error: >>> Imported toolboxes: Imported toolboxes: General_Tools(gen) Traceback (most recent call last): File "E:\Python_scripts\ImportToolbox\ToolboxImportCheck_forum_question.py", line 15, in <module> arcpy.RemoveToolbox("gen") File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 746, in RemoveToolbox return gp.removeToolbox(toolbox) File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 274, in removeToolbox self._gp.RemoveToolbox(*gp_fixargs(args, True))) RuntimeError: ERROR 999999: Error executing function. >>> Why doesn't this work? Am I using the wrong syntax?
... View more
08-13-2013
07:01 AM
|
0
|
0
|
277
|
POST
|
I have created several custom Python toolboxes with several tools in each toolbox. Within the execute method of a tool, I am able to call tools from another toolbox using the tool syntax (arcpy.tool_toolboxalias). But when I try to call a tool from a tool that is in the same toolbox, I get this error- AttributeError: Object: Tool or environment <Tool_toolboxalias> not found The error does not show up consistently. Sometimes the tool will work, and then after not changing any code I will get the error again. I've tried importing the toolbox that I am working in (I would think that would not be necessary). Has anyone else had this problem? Are you supposed to be able to call a tool from within the same toolbox? Should I be using OOP instead to call the execute method within the tool class?
... View more
06-06-2013
07:09 AM
|
0
|
0
|
1095
|
POST
|
Has this issue been resolved? It looks like this person had the same issue- http://forums.arcgis.com/threads/69378-ArcGIS-10.1-Dissolve-multipart-features-not-working. I have 3 people in my office and we are all having the same problem. All working on Windows 7 (not Windows XP) 32-bit machines. Dissolve tool worked fine in 10.0 and after the upgrade it does not dissolve multipart features.
... View more
01-22-2013
03:52 AM
|
0
|
0
|
1159
|
Title | Kudos | Posted |
---|---|---|
1 | 10-27-2016 10:52 AM | |
1 | 10-25-2016 06:28 AM | |
1 | 10-24-2016 10:07 AM | |
4 | 12-24-2013 05:59 AM |
Online Status |
Offline
|
Date Last Visited |
09-12-2023
03:53 PM
|