ch.epfl.scapetoad
Class CartogramLayer

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

public class CartogramLayer
extends java.lang.Object


Constructor Summary
CartogramLayer()
           
 
Method Summary
static void addAttribute(Layer lyr, java.lang.String name, AttributeType type)
          Adds a new attribute to an existing layer.
static void addDensityAttribute(Layer layer, java.lang.String populationAttr, java.lang.String densityAttr)
          Adds a new attribute containing the density value for a given attribute.
static void cleanAttributeValues(Layer layer, java.lang.String attrName)
          Checks the attribute values for invalid values and replaces them with a zero value.
static double computeCartogramSizeError(Layer cartogramLayer, java.lang.String cartogramAttribute, Layer originalLayer, java.lang.String errorAttribute)
          Computes the cartogram size error and stores it in the layer's attribute with the provided name.
static Geometry contour(Layer layer)
          Computes the contour of this layer.
static FeatureSchema copyFeatureSchema(FeatureSchema fs)
          Creates a new FeatureSchema using the provided FeatureSchema.
static double maxValueForAttribute(Layer layer, java.lang.String attrName)
          Returns the maximum value for the given attribute.
static double meanDensityWithAttribute(Layer layer, java.lang.String attrName)
          Computes the mean value for the given attribute weighted by the feature area.
static double meanValueForAttribute(Layer layer, java.lang.String attrName)
          Returns the mean value for the given attribute.
static double minValueForAttribute(Layer layer, java.lang.String attrName)
          Returns the minimum value for the given attribute.
static double percentileForAttribute(Layer layer, java.lang.String attrName, int n)
          Returns the n-th percentile of the provided attribute.
static Layer projectLayerWithGrid(Layer lyr, CartogramGrid grid)
          Projects a layer using a cartogram grid.
static void regularizeLayer(Layer lyr, double maxlen)
          Regularizes a layer.
static void replaceAttributeValue(Layer layer, java.lang.String attrName, double oldValue, double newValue)
          Replaces a double attribute value with another.
static void snapLayer(Layer lyr, double snappingDistance, Envelope snapRegion)
          Snaps all points of the layer to a grid with given cell size.
static double standardDeviationForAttribute(Layer layer, java.lang.String attrName)
          Computes the standard deviation of the provided attribute.
static double sumForAttribute(Layer layer, java.lang.String attrName)
          Computes the sum of the provided attribute.
static double totalArea(Layer layer)
          Computes the total area of all features in this layer.
static double varianceForAttribute(Layer layer, java.lang.String attrName)
          Computes the variance of the provided attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CartogramLayer

public CartogramLayer()
Method Detail

addAttribute

public static void addAttribute(Layer lyr,
                                java.lang.String name,
                                AttributeType type)
Adds a new attribute to an existing layer.

Parameters:
lyr - the layer to which we should add the new attribute.
name - the name of the new attribute.
type - the type of the new attribute.

addDensityAttribute

public static void addDensityAttribute(Layer layer,
                                       java.lang.String populationAttr,
                                       java.lang.String densityAttr)
Adds a new attribute containing the density value for a given attribute.

Parameters:
populationAttr - the name of the (existing) attribute for which we shall compute the density.
densityAttr - the name of the new density attribute.

meanDensityWithAttribute

public static double meanDensityWithAttribute(Layer layer,
                                              java.lang.String attrName)
Computes the mean value for the given attribute weighted by the feature area.


meanValueForAttribute

public static double meanValueForAttribute(Layer layer,
                                           java.lang.String attrName)
Returns the mean value for the given attribute.


minValueForAttribute

public static double minValueForAttribute(Layer layer,
                                          java.lang.String attrName)
Returns the minimum value for the given attribute.


maxValueForAttribute

public static double maxValueForAttribute(Layer layer,
                                          java.lang.String attrName)
Returns the maximum value for the given attribute.


sumForAttribute

public static double sumForAttribute(Layer layer,
                                     java.lang.String attrName)
Computes the sum of the provided attribute.


varianceForAttribute

public static double varianceForAttribute(Layer layer,
                                          java.lang.String attrName)
Computes the variance of the provided attribute.


standardDeviationForAttribute

public static double standardDeviationForAttribute(Layer layer,
                                                   java.lang.String attrName)
Computes the standard deviation of the provided attribute.


percentileForAttribute

public static double percentileForAttribute(Layer layer,
                                            java.lang.String attrName,
                                            int n)
Returns the n-th percentile of the provided attribute.

Parameters:
n - the percentile, must be between 0 and 100.

replaceAttributeValue

public static void replaceAttributeValue(Layer layer,
                                         java.lang.String attrName,
                                         double oldValue,
                                         double newValue)
Replaces a double attribute value with another.


totalArea

public static double totalArea(Layer layer)
Computes the total area of all features in this layer.


contour

public static Geometry contour(Layer layer)
Computes the contour of this layer.

Parameters:
layer - the layer for which we should compute the layer.
Returns:
the contour as a Geometry.

regularizeLayer

public static void regularizeLayer(Layer lyr,
                                   double maxlen)
Regularizes a layer. This means the length of all line segments does not exceed a given value. In the case of a too long line segment, the line is repeatedly divided in two until the length is less than the given value.

Parameters:
lyr - the layer to regularize.
maxlen - the maximum length of the line segments.

snapLayer

public static void snapLayer(Layer lyr,
                             double snappingDistance,
                             Envelope snapRegion)
Snaps all points of the layer to a grid with given cell size.

Parameters:
lyr - the layer to snap.
snappingDistance - the size of the grid cells.
snapRegion - a envelope with the snapping region. This enables the snapping to the same grid over several different layers.

projectLayerWithGrid

public static Layer projectLayerWithGrid(Layer lyr,
                                         CartogramGrid grid)
Projects a layer using a cartogram grid. Returns the projected layer.


computeCartogramSizeError

public static double computeCartogramSizeError(Layer cartogramLayer,
                                               java.lang.String cartogramAttribute,
                                               Layer originalLayer,
                                               java.lang.String errorAttribute)
Computes the cartogram size error and stores it in the layer's attribute with the provided name. The size error is computed as follows: err = 100 * ((areaOptimal * Sum(areaReal)) / (areaReal * Sum(areaOptimal))) where err : the size error areaOptimal : the optimal or theoretical area of a polygon areaReal : the current area of a polygon

Returns:
the mean size error.

cleanAttributeValues

public static void cleanAttributeValues(Layer layer,
                                        java.lang.String attrName)
Checks the attribute values for invalid values and replaces them with a zero value. This method works only with double value attributes.


copyFeatureSchema

public static FeatureSchema copyFeatureSchema(FeatureSchema fs)
Creates a new FeatureSchema using the provided FeatureSchema.

Returns:
a new FeatureSchema