POST
|
Sorry about that Joshua, my issue was that the selection wasn't being made. Was bogged down by other projects I forgot to mention what wasn't working.
... View more
08-04-2017
10:29 AM
|
0
|
0
|
3308
|
POST
|
So I am working on a custom tool that uses one of the existing fields to make a selection by attribute. For example, say I have a feature called Target Feature and in the feature, the fields were called Field1, Field2, Field3, and Field4. I am trying to get a variable to be set equal to arcpy.ListFields('Target Feature') and then to check if a field name is in that feature. The selection I want wasn't working, no selection was being made actually. Here's what I was leaning towards but it didn't work for me: import arcpy
fieldList = arcpy.ListFields('Target Feature')
fieldName = ['Field3']
fieldValue = ['%45B%']
if fieldName in fieldList:
if fieldValue in fieldName:
arcpy.SelectLayerByAttribute_management ('Target Feature', NEW_SELECION, "Field3 LIKE " + "'" + str(fieldValue) + "'") But this isn't working for me. Any help is appreciated!
... View more
08-04-2017
08:52 AM
|
0
|
12
|
5566
|
POST
|
So I have been tasked with creating a geoprocessing service for my company but I am trying to figure out which would be better to create it with, ModelBuilder or Python. Looking for pros and cons of using either one if anyone can help with that.
... View more
07-20-2017
06:42 AM
|
0
|
4
|
2761
|
POST
|
That does work, but I may leave it as my script below shows it because that way it's a lot easier to follow in terms of what's being done. I may at some point change it to reflect your comment about storing it in my gdb instead of in_memory.
... View more
07-19-2017
10:46 AM
|
0
|
0
|
1241
|
POST
|
Figured it out. Here's my solution which just adds to your code Blake: Blake, thank you so much for the help! some of the variables were already defined before so not included in my solution code unless asked for! import arcpy
import datetime
import os
mxd = arcpy.mapping.MapDocument("Current")
date = datetime.date.today()
unitedStatesBoundary = arcpy.mapping.ListLayers(mxd, 'United States Boundary')[0]
targetFeature = arcpy.mapping.ListLayers(mxd, 'Target Feature')[0]
mapName = str(mxd.filePath).split('\\')[-1:][0][:-4]
mapFolder = str(mxd.filePath)[:23]
saveLocFS = mapFolder
folderNameFS = "{} UG {} {}".format(mapName[0:7], mapName[8:], date)
df = arcpy.mapping.ListDataFrames(mxd)[0]
stats = []
statesFS = {6:'California'}
statesAbbreviationsFS = {6:'CA'}
statesCDCCode = {6:'California CDC Code'}
for state in statesFS:
valueStatesFS = dict.get(statesFS, state)
valueStatesAbbreviationsFS = dict.get(statesAbbreviationsFS, state)
valueCDCCode = dict.get(statesCDCCode, state)
unitedStatesBoundary.definitionQuery = "Name = '{}'".format(valueStatesFS)
arcpy.RefreshActiveView()
arcpy.SelectLayerByLocation_management(targetFeature,"intersect",unitedStatesBoundary,"","NEW_SELECTION")
mxd.save()
stateMapNameXLS = "{}_{}.xls".format(valueStatesAbbreviationsFS, valueCDCCode)
outXLS = os.path.join(footageReportFolder, footageReportFolderName, stateMapNameXLS)
exportLoc = "{}/{}/{}".format(footageReportFolder, footageReportFolderName, footageReportGDB)
stateMapName - "{}_{}".format(valueStatesAbbreviationsFS, valueCDCCode)
for field in arcpy.ListFields('Target Feature'):
if field.name == 'TotalFeet':
stats.append(['TotalFeet', "SUM"])
stateMap_stats_inmem = os.path.join("in_memory", "stateMap_stats_inmem")
try:
arcpy.Statistics_analysis('Target Feature', stateMap_stats_inmem, stats)
arcpy.TableToTable_conversion('Target Feature', exportLoc, stateMapName)
arcpy.TableToExcel_conversion(stateMap_stats_inmem, outXLS)
finally:
arcpy.Delete_management("in_memory")
... View more
07-19-2017
07:21 AM
|
2
|
0
|
1241
|
POST
|
Blake, I was able to follow your script most of the way through. I did have a question though. I do want to be able to save a copy of the results in my custom gdb (footage.gdb) hence why in my original script I used TableToTable_conversion previously. Anyway to incorporate that into your potential solution script? Your way made sense for some of the things. I do need to run tests to see if it works for me.
... View more
07-19-2017
05:37 AM
|
0
|
2
|
1241
|
POST
|
Blake, my code still creates in the Default.gdb in my documents on my local server. I was thinking of using the in_memory workspace but not sure how to incorporate that into my code. Do you think you can help me out with that? I'll post my code that currently is working for me: import arcpy
import arcpy.mapping as map
from arcpy import env
import datetime
mxd = arcpy.mapping.MapDocument("Current")
date = datetime.date.today()
unitedStatesBoundary = arcpy.mapping.ListLayers(mxd, 'United States Boundary')[0]
targetFeature = arcpy.mapping.ListLayers(mxd, 'Target Feature')[0]
mapName = str(mxd.filePath).split('\\')[-1:][0][:-4]
mapFolder = str(mxd.filePath)[:23]
saveLocFS = mapFolder
folderNameFS = mapName[0:7] + " UG " + mapName[8:] + " " + str(date)
df = arcpy.mapping.ListDataFrames(mxd)[0]
stats = []
statesFS = {6:'California'}
statesAbbreviationsFS = {6:'CA'}
statesCDCCode = {6:'California CDC Code'}
for state in statesFS:
valueStatesFS = dict.get(statesFS, state)
valueStatesAbbreviationsFS = dict.get(statesAbbreviationsFS, state)
valueCDCCode = dict.get(statesCDCCode, state)
unitedStatesBoundaryQuery = "Name = " + "'" + str(valueStatesFS) + "'"
unitedStatesBoundary.definitionQuery = unitedStatesBoundaryQuery
arcpy.RefreshActiveView()
arcpy.SelectLayerByLocation_management(targetFeature,"intersect",unitedStatesBoundary,"","NEW_SELECTION")
mxd.save()
stateMapName = str(valueStatesAbbreviationsFS) + "_" + str(valueCDCCode)
footageFolder = footageReportFolder + "/" + footageReportFolderName + "/"
footageGDB = "footages.gdb"
inTable = 'Target Feature'
exportLoc = footageFolder + footageGDB
outTable = str(stateMapName)
outXLS = footageFolder + str(stateMapName) + ".xls"
for field in arcpy.ListFields('Target Feature'):
if field.name == 'TotalFeet':
stats.append(['TotalFeet', "SUM"])
arcpy.Statistics_analysis('Target Feature', stateMapName, stats, "")
arcpy.TableToTable_conversion(inTable, exportLoc, outTable, "")
arcpy.TableToExcel_conversion(inTable, outXLS, '', '')
This code is creating it first in my Default.gdb and then saving a copy in my custom gdb called footage (referenced in the code). Then it is creating an excel spreadsheet. I am looking to skip saving in the Default.gdb and preferrable store in temp in_memory workspace and then at the end of my code, clear out the in_memory workspace.
... View more
07-18-2017
01:12 PM
|
1
|
5
|
1241
|
POST
|
I am currently working on a custom tool that helps me automate some of my reports. Part of the reports deliverable in a spreadsheet that has footage by each report generated. The reports are KMZs. My script runs as anticipated and created tables as the script says to, but the location in which they are being saved is the default.gdb in my local documents in the ArcGIS folder. I need to find a way to either be able to delete the tables created in the gdb after I'm able to pull my information using python or being able to save it in a custom location. My current code looks like this: import arcpy
import arcpy.mapping as map
from arcpy import env
import datetime
date = datetime.date.today()
stats = []
statesFS = {6:'California', 14:'Illinois'}
statesAbbreviationsFS = {6:'CA', 14:'IL'}
statesCDCCode = {6:'California CDC Code', 14:'Illinois CDC Code'}
for state in statesFS:
valueStatesFS = dict.get(statesFS, state)
valueStatesAbbreviationsFS = dict.get(statesAbbreviationsFS, state)
valueCDCCode = dict.get(statesCDCCode, state)
stateMapName = str(valueStatesAbbreviationsFS) +"-" + str(valueCDCCode) + "-" + str(date)
for field in arcpy.ListFields('Input Feature Class'):
if field.name == 'TotalFeet':
stats.append(['TotalFeet', "SUM"])
arcpy.Statistics_analysis('Input Feature Class', stateMapName, stats, "") Any help is appreciated.
... View more
07-18-2017
07:49 AM
|
0
|
7
|
1653
|
POST
|
Figured it out and here's the solution: import arcpy
import arcpy.mapping as map
mxd = arcpy.mapping.MapDocument("Current")
visibleFields = ["Field1", "Field2", "Field3", "Field4", "Field5"]
field_info = arcpy.Describe('Fiber Segments').fieldInfo
df = arcpy.mapping.ListDataFrames(mxd)[0]
for index in xrange(0, field_info.count):
if field_info.getfieldname(index) not in visibleFields:
field_info.setvisible(index,"HIDDEN")
arcpy.Delete_management('Output Feature',"")
arcpy.MakeFeatureLayer_management('Input Feature','Output Feature Layer',"","",field_info)
addLayer = arcpy.mapping.Layer('Output Feature Layer')
arcpy.mapping.AddLayer(df, addLayer)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
inputLayer = arcpy.mapping.ListLayers(mxd, 'Output Feature Layer')[0]
symbologyLayer = r'C:\pathway\Output Feature Layer symbology.lyr'
arcpy.ApplySymbologyFromLayer_management (inputLayer, symbologyLayer) This is working well for me without any errors. Not entirely sure why the raw string didn't work but the way it's set equal to inputLayer seems to do the trick.
... View more
07-13-2017
10:51 AM
|
0
|
0
|
495
|
POST
|
Yes. I actually figured it out. I'll add that to the comments to show the solution.
... View more
07-13-2017
10:49 AM
|
0
|
0
|
495
|
POST
|
Ah, line 13 is actually Output Feature Class. I'm running this tool over and over again to test it. Just using line 13 to delete the traces of the last Output Feature Class.
... View more
07-13-2017
10:18 AM
|
0
|
2
|
495
|
POST
|
So my custom tool script first creates a new feature layer based on an existing feature layer using the MakeFeature_management function with just the certain fields I want showing. After that, the tool has a variable called inputLayer = to the raw string of the newly created Feature Layer. Here's what the script looks like so far: import arcpy
import arcpy.mapping as map
mxd = arcpy.mapping.MapDocument("Current")
visibleFields = ["Field1", "Field2", "Field3", "Field4", "Field5"]
field_info = arcpy.Describe('Fiber Segments').fieldInfo
df = arcpy.mapping.ListDataFrames(mxd)[0]
for index in xrange(0, field_info.count):
if field_info.getfieldname(index) not in visibleFields:
field_info.setvisible(index,"HIDDEN")
arcpy.Delete_management('Output Feature',"")
arcpy.MakeFeatureLayer_management('Input Feature','Output Feature Layer',"","",field_info)
addLayer = arcpy.mapping.Layer('Output Feature Layer')
arcpy.mapping.AddLayer(df, addLayer)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
inputLayer = r'Output Feature Layer'
symbologyLayer = r'C:\pathway\Output Feature Layer symbology.lyr'
arcpy.ApplySymbologyFromLayer_management (inputLayer, symbologyLayer) The issue here is that the symbology isn't applying to the Output Feature Layer when the entire script is run. If you run these lines individually in the python module in ArcMap, they run fine and apply the symbology. Any thoughts on this here?
... View more
07-13-2017
09:11 AM
|
0
|
5
|
1242
|
POST
|
As always, thank you Joshua! Your help and input has been greatly appreciated and very helpful.
... View more
07-13-2017
09:04 AM
|
0
|
0
|
373
|
POST
|
I think I figured out what the issue was....if you see the df variable, it has .name at the end. I use that variable later for MapToKML tool. so i need to make that a local variable instead of an universal one. and for addLayer, df variable shouldn't have .name at the end. Is that correct? I ran the script, and it did add the layer this time.
... View more
07-13-2017
08:59 AM
|
0
|
2
|
2108
|
POST
|
So here's the code and all of the inputs with it mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0].name
visibleFields = ["Field1", "Field2", "Field3", "Field4", "Field5"]
field_info = arcpy.Describe('Fiber Segments').fieldInfo
# if conditional for report type when FS is working
for index in xrange(0, field_info.count):
if field_info.getfieldname(index) not in visibleFields:
field_info.setvisible(index,"HIDDEN")
arcpy.Delete_management('Fiber Segments NOC',"")
arcpy.MakeFeatureLayer_management('Fiber Segments','Fiber Segments NOC',"","",field_info)
addLayer = arcpy.mapping.Layer('Fiber Segments NOC')
arcpy.mapping.AddLayer(df, addLayer)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
... View more
07-13-2017
08:56 AM
|
0
|
0
|
2108
|
Title | Kudos | Posted |
---|---|---|
1 | 07-26-2018 09:12 AM | |
1 | 07-18-2017 01:12 PM | |
1 | 03-09-2017 09:57 AM | |
2 | 03-22-2018 09:49 AM | |
1 | 09-19-2017 01:18 PM |