ch.epfl.scapetoad
Class CartogramGrid

java.lang.Object
  extended by ch.epfl.scapetoad.CartogramGrid

public class CartogramGrid
extends java.lang.Object

The cartogram grid class represents the grid which is overlaid on all the layers and which is used for the deformation computation. The grid has nodes and cells. Each node has x/y-coordinates, and each cell has a density value.


Method Summary
 void computeOriginalDensityValuesWithLayer(Layer layer, java.lang.String attrName, boolean attrIsDensityValue)
          Computes the density value given a layer and an attribute name.
 void conformToConstrainedDeformation()
          Corrects the grid for corresponding the constrained deformation information computed by the prepareGridForConstrainedDeformation method.
 double coordinateXForOriginalCellIndex(int i)
          Converts a grid cell index in x direction into real world x coordinate.
 double coordinateYForOriginalCellIndex(int j)
          Converts a grid cell index in y direction into real world y coordinate.
 Envelope envelope()
          Returns the grid's bounding box.
 void fillRegularDensityGrid(double[][] densityGrid, double minX, double maxX, double minY, double maxY)
          Fills a regular grid with the mean density.
 double getMaximumDensity()
          Returns the current maximum density value of the grid.
 double getMinimumDensity()
          Returns the current minimum density value of the grid.
 double[][] getXCoordinates()
          Returns the x coordinates array.
 double[][] getYCoordinates()
          Returns the y coordinates array.
 double meanDensityError()
          Returns the mean density error.
 int originalCellIndexForCoordinateX(double x)
          Converts the provided x coordinate into the grid's cell index.
 int originalCellIndexForCoordinateY(double y)
          Converts the provided y coordinate into the grid's cell index.
 void prepareGridForConstrainedDeformation(java.util.Vector layers)
          Prepares the original grid for a constrained deformation process.
 Coordinate[] projectCoordinates(Coordinate[] coords)
          Projects a coordinate sequence using this grid.
 Coordinate[] projectLineSegment(Coordinate c1, Coordinate c2)
          Projects a line segment.
 double[] projectPoint(double x, double y)
          Projects one point using this grid.
 Coordinate projectPointAsCoordinate(double x, double y)
          Projects one point using this grid.
 void scaleDensityValues(double minValue, double maxValue)
          Scales the density values given the minimum and maximum value.
 void updateDensityValues()
          Updates the current density values.
 void writeToShapefile(java.lang.String shapefile)
          Writes the grid into the specified shape file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

envelope

public Envelope envelope()
Returns the grid's bounding box.

Returns:
an Envelope representing the bounding box.

getXCoordinates

public double[][] getXCoordinates()
Returns the x coordinates array.


getYCoordinates

public double[][] getYCoordinates()
Returns the y coordinates array.


computeOriginalDensityValuesWithLayer

public void computeOriginalDensityValuesWithLayer(Layer layer,
                                                  java.lang.String attrName,
                                                  boolean attrIsDensityValue)
                                           throws java.lang.InterruptedException
Computes the density value given a layer and an attribute name.

Parameters:
layer - the master layer
attrName - the name of the master attribute
attrIsDensityValue - is true if the master attribute is a density value, and false if it is a population value.
Throws:
java.lang.InterruptedException

prepareGridForConstrainedDeformation

public void prepareGridForConstrainedDeformation(java.util.Vector layers)
Prepares the original grid for a constrained deformation process. After this preparation, the grid can be deformed using a cartogram algorithm. After this deformation, the grid can be corrected using the constrained deformation information by a call to the CartogramGrid method conformToConstrainedDeformation.

Parameters:
layers - a Vector containing the constrained layer names.

conformToConstrainedDeformation

public void conformToConstrainedDeformation()
Corrects the grid for corresponding the constrained deformation information computed by the prepareGridForConstrainedDeformation method.


scaleDensityValues

public void scaleDensityValues(double minValue,
                               double maxValue)
Scales the density values given the minimum and maximum value.

Parameters:
minValue - the new minimum value for the densities.
maxValue - the new maximum value for the densities.

originalCellIndexForCoordinateX

public int originalCellIndexForCoordinateX(double x)
Converts the provided x coordinate into the grid's cell index.

Parameters:
x - the real world x coordinate.
Returns:
the cell index in x direction.

originalCellIndexForCoordinateY

public int originalCellIndexForCoordinateY(double y)
Converts the provided y coordinate into the grid's cell index.

Parameters:
y - the real world y coordinate.
Returns:
the cell index in y direction.

coordinateXForOriginalCellIndex

public double coordinateXForOriginalCellIndex(int i)
Converts a grid cell index in x direction into real world x coordinate. The coordinate of the cell's lower left corner is returned.

Parameters:
i - the cell index in x direction.
Returns:
the x coordinate of the cell's lower left corner.

coordinateYForOriginalCellIndex

public double coordinateYForOriginalCellIndex(int j)
Converts a grid cell index in y direction into real world y coordinate. The coordinate of the cell's lower left corner is returned.

Parameters:
i - the cell index in y direction.
Returns:
the y coordinate of the cell's lower left corner.

writeToShapefile

public void writeToShapefile(java.lang.String shapefile)
Writes the grid into the specified shape file.

Parameters:
shapefile - the path to the shape file.

meanDensityError

public double meanDensityError()
Returns the mean density error. The density error is the squared difference between the current and the desired (optimal) density.

Returns:
the mean density error

updateDensityValues

public void updateDensityValues()
Updates the current density values.


fillRegularDensityGrid

public void fillRegularDensityGrid(double[][] densityGrid,
                                   double minX,
                                   double maxX,
                                   double minY,
                                   double maxY)
Fills a regular grid with the mean density. If there is no information, the mean density for the whole grid is assumed to be the desired value.


projectPoint

public double[] projectPoint(double x,
                             double y)
Projects one point using this grid.

Parameters:
x - the x coordinate of the point to project.
y - the y coordinate of the point to project.
Returns:
a double array with the coordinates of the projected point.

projectPointAsCoordinate

public Coordinate projectPointAsCoordinate(double x,
                                           double y)
Projects one point using this grid.

Parameters:
x - the x coordinate of the point to project.
y - the y coordinate of the point to project.
Returns:
a Coordinate with the projected point.

projectLineSegment

public Coordinate[] projectLineSegment(Coordinate c1,
                                       Coordinate c2)
Projects a line segment. Returns two or more coordinates.


projectCoordinates

public Coordinate[] projectCoordinates(Coordinate[] coords)
Projects a coordinate sequence using this grid.


getMinimumDensity

public double getMinimumDensity()
Returns the current minimum density value of the grid.

Returns:
the minimum density value.

getMaximumDensity

public double getMaximumDensity()
Returns the current maximum density value of the grid.

Returns:
the maximum density value.