Symbology of layer file to CSV

2030
5
02-06-2017 09:29 AM
MihaKlemencic
New Contributor III

I would like write RGB values of each polygon in attribute table and then convert to excel/CSV/txt file.

I found this script that writes RGB values for each polygon into attribute table. I created new script as it shows on this page. However when I run the tool, I get a message:

Executing: rgbValues D:\temp\GIS\eGeologija\KRANJ\SIMBOLOGIJA krpoly_opis_polygon #
Start Time: Mon Feb 06 18:15:25 2017
Running script rgbValues...
STARTED

======================================================================
D:\temp\GIS\eGeologija\KRANJ\SIMBOLOGIJA\TempGDB.gdb
Path: D:\temp\GIS\eGeologija\KRANJ\SHP\krpoly.shp
Spatial Reference: D48_Slovenia_TM
TEMPS SET
_R field exists
_G field exists
_B field exists

======================================================================

* FREQUENCIES & TEMP CARTO TILES
Failed script rgbValues...

Traceback (most recent call last):
File "D:\temp\GIS\eGeologija\RGB_values.py", line 107, in <module>
arcpy.Frequency_analysis(LayerPath, TempFrequency, FieldName, "")
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\analysis.py", line 1276, in Frequency
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000735: Frequency Field(s): Value is required
Failed to execute (Frequency).


Failed to execute (rgbValues).
Failed at Mon Feb 06 18:15:26 2017 (Elapsed Time: 0.45 seconds)

Line 107 represents this line of code: arcpy.Frequency_analysis(LayerPath, TempFrequency, FieldName, "").

Here I do not know how to reapir script so I would appreciate your help!

0 Kudos
5 Replies
BlakeTerhune
MVP Regular Contributor

It looks like either you're not entering a value for the FieldName parameter or it's not wired up correctly when you made the script tool. You can see when it prints the new R, G, and B fields it doesn't have to original FieldName with it (which it should).

EDIT:

I just noticed you're entering TEMPS SET as the FieldName. Field names cannot have spaces so double check that the field name is correct and that you're not using a field alias instead.

MihaKlemencic
New Contributor III

It seems strange if I choose LYR file as Symbology layer, I have no option to choose Symbology field.

I prepared map package that includes data and script. Blake, can you check what is wrong?

0 Kudos
BlakeTerhune
MVP Regular Contributor

By importing your shapefile to a file geodatabase and classifying the symbology category using unique values (one field) instead of unique values, many fields, I was able to get this script to run. The shapefile wasn't working because it doesn't specify if a field is nullable, which is something the script checks for. And the many fields symbology wasn't working because the script only has input for one symbology field.

I specified the following script tool parameters.

Here's the script output:

Messages
Executing: Script C:\Users\blaket\Downloads\RGB_values.mpk krpoly LIT_SIF
Start Time: Tue Feb 07 10:28:20 2017
Running script Script...
STARTED

======================================================================
C:\Users\blaket\Downloads\RGB_values.mpk\TempGDB.gdb
Path: C:\Users\blaket\Downloads\RGB_values.mpk\testing.gdb\krpoly
Spatial Reference: D48_Slovenia_TM
LIT_SIF
Type: Double
Precision: 0
Scale: 0
Lenght: 8
Null: True
TEMPS SET
LIT_SIF_R field created
LIT_SIF_G field created
LIT_SIF_B field created

======================================================================

* FREQUENCIES & TEMP CARTO TILES
- Symbology Frequency Analysis Completed
- Temp Tile Feature Class: C:\Users\blaket\Downloads\RGB_values.mpk\TempGDB.gdb\TempTileFC
- Temp Tile Feature Class Field Added:LIT_SIF
- Centroid Feature Class For Raster:442035.953186113888.847687

======================================================================

* LOOPING VALUES

--------------
- Frequency Field Name:LIT_SIF
- Frequency Record: 1.0
- Temp Layer:TempLayerClone1.0
- Calculate Tile Field Expression: '1.0'
- Temp Tile: C:\Users\blaket\Downloads\RGB_values.mpk\TempGDB.gdb\TempTileFC
- Layer Added
- IS NOT TEXT
- Layer Updated
- Selection Qu:"LIT_SIF"=1.0
- Zoomed
- RGB Raster Exported
- RGB Raster: C:\Users\blaket\Downloads\RGB_values.mpk\TempRaster.tif
- R: 120
- G: 179
- B: 157
- Selection: krpoly
- Def: "LIT_SIF"=1.0
- Calculated & Cleared
- Removed & Cleared

--------------
- Frequency Field Name:LIT_SIF
- Frequency Record: 2.0
- Temp Layer:TempLayerClone2.0
- Calculate Tile Field Expression: '2.0'
- Temp Tile: C:\Users\blaket\Downloads\RGB_values.mpk\TempGDB.gdb\TempTileFC
- Layer Added
- IS NOT TEXT
- Layer Updated
- Selection Qu:"LIT_SIF"=2.0
- Zoomed
- RGB Raster Exported
- RGB Raster: C:\Users\blaket\Downloads\RGB_values.mpk\TempRaster.tif
- R: 247
- G: 153
- B: 182
- Selection: krpoly
- Def: "LIT_SIF"=2.0
- Calculated & Cleared
- Removed & Cleared

--------------
- Frequency Field Name:LIT_SIF
- Frequency Record: 3.0
- Temp Layer:TempLayerClone3.0
- Calculate Tile Field Expression: '3.0'
- Temp Tile: C:\Users\blaket\Downloads\RGB_values.mpk\TempGDB.gdb\TempTileFC
- Layer Added
- IS NOT TEXT
- Layer Updated
- Selection Qu:"LIT_SIF"=3.0
- Zoomed
- RGB Raster Exported
- RGB Raster: C:\Users\blaket\Downloads\RGB_values.mpk\TempRaster.tif
- R: 142
- G: 182
- B: 237
- Selection: krpoly
- Def: "LIT_SIF"=3.0
- Calculated & Cleared
- Removed & Cleared

--------------

... snip ...


Completed script Script...
Succeeded at Tue Feb 07 10:30:02 2017 (Elapsed Time: 1 minutes 41 seconds)

MihaKlemencic
New Contributor III

Thank you for your work  We will try to figure out how to obtain RGB values from unique values, many fields, if it possible.

This script requires to define one field that symbology is driving off. If we figure out to how obtain RGB values from many fields, which parameter should be choosen for Symbology field instead of String

0 Kudos
BlakeTerhune
MVP Regular Contributor

I don't know the intricacies of this script so I can't offer much advice on how to proceed. However, I suspect that it won't be as easy as changing the script tool parameters. You're likely going to have to rewrite some Python code in the script.

0 Kudos