Table Of Contents

Previous topic

AMOEBA [Alstadt_Getis2006], [Duque_Alstadt_Velasquez_Franco_Betancourt2010]

Next topic

contribution guide

This Page

Exporting Layer

Export to ESRI shape file

Layer.exportArcData(filename)

Creates an ESRI shapefile from a clusterPy’s layer.

Parameters:
  • filename (string) – shape file name to create, without “.shp”

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportArcData("china")

Export to a python object

Layer.save(filename)

Save the Layer on a CP file

Parameters:
  • filename (string) – project name to create

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.save('china')

Exporting data

To DBF

Layer.exportDBFY(fileName, *args)

Exports the database file

Parameters:
  • fileName (string) – dbf file name to create, without “.dbf”
  • args (tuple) – variables subset to be exported

Examples

import clusterpy
clusterpy.importArcData("clusterpy/data_examples/china")
china.exportDBFY("china")

To CSV

Layer.exportCSVY(fileName, *args)

Exports layers data on .csv file

Parameters:
  • fileName (string) – csv file name to create, without “.csv”
  • args (tuple) – variables subset to be exported

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportCSVY("ChinaCSV")

To python object

Layer.exportCPY(filename, *args)

Exports a .CP dictionary with the data

Parameters:
  • filename (string) – cp file name to create, without “.cp”
  • args (tuple) – variables subset to be exported

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportCPY("ChinaCPY")

Exporting contiguity matrix

To CSV

Layer.exportCSVW(fileName, wtype='rook', idVariable='ID', grade=1, diag=1, standarize=False)

Exports the nth contiguity W matrix on a csv file

Parameters:
  • fileName (string) – csv file name to create, without “.csv”
  • wtype (string) – w type to export, default is ‘rook’
  • grade (integer) – w contiguity grade to export, default is 1
  • idVariable (string) – id variable fieldName, default is ‘ID’
  • diag (integer) – diagonal elements
  • standarize (boolean) – True to standardize the variables.

Examples Writing 1st contiguity matrix

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportCSVW("chinaW", wtype='rook', grade=1)

Writing 2nd contiguity matrix

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportCSVW("chinaW", wtype='rook', grade=2)

To python object

Layer.exportCPW(filename, wtype='rook')

Exports a .cp dictionary with the W contiguity matrix

Parameters:
  • filename (string) – cp file name to create, without “.cp”
  • wtype (string) – w type to export, default is ‘rook’

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportCPW("filename",wtype='queen')

Exporting results

Export region to area dictionary

Layer.exportRegions2area(filename)

export region2area results

Parameters:
  • filename (string) – csv file name to create, without “.csv”

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.exportRegions2area('region2area')

Export a summary of the solutions of the executed algorithms to a Layer

Layer.exportOutputs(filename)

Exports outputs of the last executed algorithm to a csv file. If no algorithm has been ran, you wil get an error message.

Parameters:
  • filename (string) – csv file name to create, without “.csv”

Examples

import clusterpy
china = clusterpy.importArcData("clusterpy/data_examples/china")
china.cluster('geoSom', ['Y1991'], 10, 10, alphaType='quadratic', fileName="oLayer", dissolve=1)
china.exportOutputs("outputs")

Export dissolved solutions

After an algorith execution, with dissolve=1, the dissolved layer is saved in the attribute Layer.results. The first algorithm that you run with dissolve=1 will have a child layer in layer.results[0]; the second algorithm that you run with dissolve=1 will be in layer.results[1], and so on. This structure allows you to export a dissolved layer as a shapefile just using exportArcData.

Example 1

import clusterpy
instance = clusterpy.createGrid(3, 3)
instance.generateData("SAR", 'rook', 2, 0.9)
instance.exportArcData("testOutput/arisel_3_input")
instance.cluster('arisel', ['SAR1', 'SAR2'], 3, wType='queen', std=1, inits=1, initialSolution=[0, 0, 1, 0, 1, 1, 2, 2, 2], convTabu=5, tabuLength=5, dissolve=1)
instance.results[0].exportArcData("testOutput/arisel_solution")

Example 2

import clusterpy
calif = clusterpy.importArcData("clusterpy/data_examples/CA_Polygons")
calif.fieldNames
calif.dataOperation("g70_01 = float(POP2001 - POP1970) / POP1970")
calif.exportArcData("testOutput/arisel_5_input")
calif.cluster('arisel', ['g70_01'], 15, inits= 4, dissolve=1)
calif.results[0].exportArcData("testOutput/arisel_solution")
calif.cluster('arisel', ['g70_01'], 15, inits= 4, dissolve=1)
calif.results[1].exportArcData("testOutput/arisel_solution2")