Hi..
i want ask a question about this..
see the attachment about my shp data..
so i have the shp attribute like in the attachment..
i want to fill the "name" field using the formula like: shape_length < 50 = A, 20 < Shape_length < 500 = B and shape_length > 500 = C..
is it possible to do that??
can someone help me to explain it?
Thanks
Solved! Go to Solution.
Well you changed mine.
I think I covered everything, just follow mine..
To do this manually, you'll use Select by Attributes. Select all records where SHAPELENGTH <= 50, then use the Field Calculator to calculate "A" into your text field. Repeat the same workflow modifying your SHAPELENGTH query and using the Field Calculator.
thanks for your reply Mr Schwartz
but i want to fill automatically and i just found using VBA script in field calculator with IF statements but i have another trouble with multiple IF statments
i put this code in field calculator
Dim Name
if [SHAPE_Length] < 50 then
Name = "A"
elseif 50 < [SHAPE_Length] < 1000 then
Name = "B"
elseif [SHAPE_Length] > 1000 then
Name = "C"
end if
but after it run, the result only take Name < 50 = A, Name >50 = B..
i think i put the wrong code
don't use vba
switch to python
I rearranged the logic since a Shape_Length field will never be <null> so you only have to check for < 50 ( ie 'A' ) and > 1000 ( ie 'C') then everything else has to be 'B'
your code isn't indented properly... see
/blogs/dan_patterson/2016/08/14/script-formatting
for formatting code blocks for geonet
shape_length < 50 = A, 20 < Shape_length < 500 = B and shape_length > 500 = C.
your ranges overlap, so I assum you meant 50 < … < 500
python parser, code block below, destination field needs to be string/text. There will be no nulls since it is a shape_length field
expression:
func(!Shape_Length!)
def func(a):
""" parser"""
if a < 50:
val = 'A'
elif a > 500:
val = 'C'
else:
val = 'B'
return val
Hi Mr Patterson,
i tried your code last night, and its still show some error..
i write this in Pre-Logic script code:
def func(!SHAPE_Length!):
""" parser"""
if !SHAPE_Length! < 50:
val = 'STA'
elif !SHAPE_Length! > 5000:
val = 'Center Line'
else:
val = 'Row'
return val
and in below box i write this
Name =
func( !SHAPE_Length!)
i keep get the error processing code..
where am i wrong??
thanks
Well you changed mine.
I think I covered everything, just follow mine..
Thanks Mr Patterson really Helpful...