Table Of Contents

Previous topic

clusterPy 0.9.9 Beta version

Next topic

Creating data

This Page

Importing data

Load an existing project

clusterpy0_9_9.clusterpy.core.inputs.load(filename)

Load a ClusterPy project (<file>.CP)

Parameters:
  • filename (string) – filename without extension
Return type:

Layer

Returns:

CP project

Description

With clusterPy you can save your layer objects on a .cp file, which can be reopened in the future using this function.

Examples

import clusterpy
lay = clusterpy.new()
lay.save("lay")
layer = clusterpy.load("lay")

Import an ESRI shape file

clusterpy0_9_9.clusterpy.core.inputs.importArcData(filename)

Creates a new Layer from a shapefile (<file>.shp)

Parameters:
  • filename (string) – filename without extension
Return type:

Layer (CP project)

Description

ESRI shapefile is a binary file used to save and transport maps. During the last times it has become the most used format for the spatial scientists around the world.

On clusterPy’s “data_examples” folder you can find some shapefiles. To load a shapefile in clusterPy just follow the example bellow.

Example

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

Import geometry of a .shp file

clusterpy0_9_9.clusterpy.core.inputs.importShape(shapefile)

Reads the geographic information stored in a shape file and returns them in python objects.

Parameters:
  • shapefile (string) – path to shapefile including the extension “.shp”
Return type:

tuple (coordinates(List), Wqueen(Dict), Wrook(Dict)).

Example

import clusterpy
chinaAreas = clusterpy.importShape("clusterpy/data_examples/china.shp")

Import extra variables

From a dbf

clusterpy0_9_9.clusterpy.core.inputs.importDBF(filename)

Get variables from a dbf file.

Parameters:
  • filename (string) – name of the file (String) including “.dbf”
Return type:

tuple (dbf file Data, fieldNames and fieldSpecs).

Example

import clusterpy
chinaData = clusterpy.importDBF("clusterpy/data_examples/china.dbf")

From a csv

clusterpy0_9_9.clusterpy.core.inputs.importCSV(filename, header=True)

Get variables from a csv file.

Parameters:
  • filename (string) – name of the file (String)
  • header (Boolean or None) – Boolean, which is True if the csv have headers.
Return type:

tuple (csv file Data, fieldnames).

Example

import clusterpy
chinaData = clusterpy.importCSV("clusterpy/data_examples/china.csv")