If/Then Field Calculations

2774
10
Jump to solution
07-29-2021 04:19 AM
Labels (3)
FynnScharpen
Occasional Contributor

Good evening,

I'm searching for help regarding field calculations. 

I have a column called NVT which divides the total amount of points into groups. 

The query shall divide the points having the same NVT number into groups of 32.

The division into subgroups of 32 is consistant. the amount of points per NVT isnt

For Example: NVT 1= 96 points --> NVT 1 shall become 3 subgroups. 

NVT1: 

Points 1-32 get LFD3 =1 

Points 33-64 get LFD3 = 2 

Points 65-96 get LFD3 = 3

Same for NVT2 and NVT 3 and so on.

Thanks in advance 🙂 Hopefully my explanation is okay!

 

Zuweisung.PNG

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

read my blog

Group, split and reclass using numpy, python and arcpy

off to the garden.... back in 8 hours 😉


... sort of retired...

View solution in original post

10 Replies
jcarlson
MVP Esteemed Contributor

This would be simple enough, but do you have any requirements for how the calculation sorts the features into their respective categories?

- Josh Carlson
Kendall County GIS
0 Kudos
FynnScharpen
Occasional Contributor

No, that doesn't matter. Easiest would be:

How many Adresses has each NVT?

Divide the amount by 32 and give each group of 32 the same ID in LFD3. Always reach 32 until the last subgroup which can have less than 32 

0 Kudos
DanPatterson
MVP Esteemed Contributor

is this divmod week?

example

a  # an array, pretend it is a field
array([  0,   8,  16,  24,  32,  40,  48,  56,  64,  72,  80,  88,  96,
       104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200,
       208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304,
       312])

divmod(a, 32)[0]
array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,
       5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9], dtype=int32)

as a field calculation

divmod(!your_field!, 32)[0]

or replace 32 with whatever divisor you want.  If you want the remainder, replace [0] with [1]


... sort of retired...
0 Kudos
FynnScharpen
Occasional Contributor

Tahnks for trying to help Dan! I know what you mean but that doesn't fit my purpose. In my case the array/field is different. For example: 

array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,....])

so for the first 32  times  1 in the array it shall return 1 in a new column for each one. for the next 32 times 1 it shall return 2.

So if the array has 90 times a 1 it shall return in a new column for the first 32: "1" for the next 32:  "2" and for the remaining 26: "3"

 

If you have an idea let me know. I definetly have to improve in this area 🙂 

 

Kind regards Fynn 

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

Well that would be easy if NVT was all 1 ... or does it change to 2 etc.

Easier still if NVT were in sequential order and doesn't need to be sorted.

Is Hausnummer sequential as well? and equal to OBJECTID?

All key details, otherwise a simple counter would work


... sort of retired...
0 Kudos
FynnScharpen
Occasional Contributor

Thats the problem. NVT can have numbers between 1 and 100, has to be sorted and its frequency of each varies. Hausnummer is only sequential in this test case normally it isn't. 

Not sure if you understood my problem. My technical English needs to improve.

1. Step: Sorting all addresses based on NVT

2. Step: Count the number of addresses that have the same NVT number.

3. Step: The first 32 addresses with the same NVT number get a 1 in LF3D if there are more than 32 the next 32 get the 2 in LF3D and so on.

4. Step: Repeating step 3 for the next NVT number

0 Kudos
DanPatterson
MVP Esteemed Contributor

Like this?

Left table... Vals_ range from 1 to 3 inclusive.

Purpose : sort, group and reclass the Vals_ data into groups of 12, sequencing each group from 1 onward.

Example:  there are  1: 38, 2: 31, 3: 31]

Groups are split at  

1: [ 12, 24, 36])

2: [ 12, 24])

3: [ 12, 24])]

and resequenced.

input_output.png

I have attached an Excel version of the table for you to look at


... sort of retired...
Tags (2)
FynnScharpen
Occasional Contributor

Yes, thats it! Now I'm even more curious how you did that. The "new_key" is exactly what I tried to achieve

 

Thanks in advance, Fynn

0 Kudos
DanPatterson
MVP Esteemed Contributor

read my blog

Group, split and reclass using numpy, python and arcpy

off to the garden.... back in 8 hours 😉


... sort of retired...