clusterpy / clusterpy

Library of spatially constrained clustering algorithms
www.rise-group.org
BSD 3-Clause "New" or "Revised" License
64 stars 29 forks source link

Problem dissolving solution #46

Open darribas opened 8 years ago

darribas commented 8 years ago

I can't dissolve the shapefile for a solution, am I missing anything? I'm posting here an example using a toy example data (from pysal), but I have not been able to get it to work with other datasets too.

import pysal as ps
import clusterpy as clp
col = clp.importArcData(ps.examples.get_path('columbus'))
col.cluster('azpRTabu', ['HOVAL', 'CRIME'], 2, dissolve=1)

Which prints out the following output:

Getting variables
Variables successfully extracted
Running original AZP-R-Tabu algorithm (Openshaw and Rao, 1995)
Number of areas:  49
Number of regions:  2
Constructing regions
initial Solution:  [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0]
initial O.F:  24864.1208571
Performing local search
FINAL SOLUTION:  [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0]
FINAL OF:  24572.9644776
Done
Adding variables
Done
Dissolving lines
Problem: Amount of assigned regions does not match number of areas
Regions: [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0]
Done
JuancaDuque commented 8 years ago

Dear Dani, I just tried the following code and it worked:

import clusterpy col = clusterpy.importArcData("clusterpy/data_examples/columbus") col.exportArcData("testOutput/columbus") col.cluster('azpRTabu', ['HOVAL', 'CRIME'], 2, dissolve=1) col.results[0].exportArcData("testOutput/ColDiss")

JuancaDuque commented 8 years ago

Juans-iMac:CP juanduque$ python testDissolve.py ClusterPy: Library of spatially constrained clustering algorithms Some functions are not available, reason: No module named Polygon Some functions are not available, reason: No module named Polygon Loading clusterpy/data_examples/columbus.dbf Loading clusterpy/data_examples/columbus.shp Done Writing ESRI files Writing DBF file Done ESRI files created Getting variables Variables successfully extracted Running original AZP-R-Tabu algorithm (Openshaw and Rao, 1995) Number of areas: 49 Number of regions: 2 Constructing regions initial Solution: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0] initial O.F: 24864.1208571 Performing local search FINAL SOLUTION: [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0] FINAL OF: 24572.9644776 Done Adding variables Done Dissolving lines Done Writing ESRI files Writing DBF file Done ESRI files created Juans-iMac:CP juanduque$