After several tries I had a solution for the problem. I'm still not perfectly satisfied with the result but it does what it has to.
It creates a list of IDs and REGION IDs. If I Join this CSV to the shapefile I can use Dissolve by REGION ID and that's it!
I've created a tool of it in ArcGIS.
It may help someone so I copy my code here:
import arcpy
import random
import pysal
import scipy
import numpy as np
# PARAMETERS
# The minimum value the merged polygons have to reach.
# Parameter in script: Minimum value:
# Data type: Long
FLOOR = int(arcpy.GetParameterAsText(0))
# The path of the shapefile to be merged.
# Parameter in script: Path of input shapefile:
# Data type: Shapefile
shapefile = arcpy.GetParameterAsText(1)
# The name of the ID field in the shapefile to be merged.
# Parameter in script: ID field in input shapefile:
# Data type: Field
# Obtained from: Path of input shapefile:
IDfield = arcpy.GetParameterAsText(2)
# The name of the field containg the values to sum up to FLOOR.
# Parameter in script: Field containing values to sum:
# Data type: Field
# Obtained from: Path of input shapefile:
Vfield = arcpy.GetParameterAsText(3)
# The name of the output CSV file containing polygon IDs and region codes for each input polygon.
# Parameter in script: CSV file containing region codes:
# Data type: File
# Direction: Output
# Filter: csv;
csv = arcpy.GetParameterAsText(4)
# Seed value for random.
# Parameter in script: Seed:
# Data type: Long
seed = int(arcpy.GetParameterAsText(5))
'A klaszterizálás során használt kezdő érték.'
# Initial value for clustering.
# Parameter in script: Initial:
# Data type: Long
initial = int(arcpy.GetParameterAsText(6))
# PREPARATION
# Randomization.
random.seed(seed)
np.random.seed(seed)
# Binary matrix for rook neighbourhood.
weight = pysal.rook_from_shapefile(shapefile,idVariable=IDfield)
dbf = pysal.open(shapefile[:-4] + '.dbf')
IDarray = np.array([dbf.by_col[IDfield]])
IDarray = IDarray.transpose()
Varray = np.array([dbf.by_col[Vfield]])
Varray = Varray.transpose()
# REGIONALIZATION
solution = pysal.region.Maxp(weight,Varray,FLOOR,Varray)
regions = solution.regions
# SAVE RESULT - .CSV
csv_write = open(csv,'w')
csv_write.write('"IDfield","REGION_ID"\n')
for i in range(len(regions)):
for geo in regions[i]:
csv_write.write('"' + str(geo) + '","' + str(i+1) + '"\n')
csv_write.close()