com.reades.mapthing
Class Generic

java.lang.Object
  extended by com.reades.mapthing.Generic
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Lines, Points, Polygons

public class Generic
extends Object
implements Serializable

This serves as a Generic template and super-class for implementations of various entity-drawing classes.

You wouldn't call this directly, but it is used by the sub-classes to do things like open shape files (and save a reference to the FeatureCollection object, and to map the geographic coordinates on to the plane of the Processing sketch window).

Author:
jon@reades.com Features to implement:

Package designed to hold objects used to translate between Shape and CSV files, and Processing's PShape, PImage and other sketch drawing classes.

I am deeply indebted for the CSV code to the GeoTools example available here: http://docs.geotools.org/stable/userguide/examples/csv2shp.html

I should also definitely acknowledge the input of Camilo Vargas, without which this would never have happened!

See Also:
Serialized Form

Field Summary
 boolean DEBUG
           
 
Constructor Summary
Generic(BoundingBox b,  f)
          A default implementation.
Generic(BoundingBox b, SimpleFeature f)
          A default implementation.
 
Method Summary
 void appendNearestFeatures(Generic gs, double maxDistance)
          Incomplete implementation -- this is supposed to allow you to select features falling within a particular distance of a polygon, but as yet I've not quite figured how to do it properly.
 ReferencedEnvelope getBounds()
          Get the boundary envelope of the shape file itself
  getCentroids()
          Returns the centroids of an object in a Processing sketch.
  getFeatures()
          Retrieves all features contained in the data source and returns them as a FeatureCollection.
  getMultipleFeaturesById(String field, Set<String> ids)
          Deprecated.
  getMultipleFeaturesById(String field, String id)
          Deprecated.
  getMultipleFeaturesById(String field, String[] ids)
          Deprecated.
  getMultipleFeaturesByPattern(String field, Set<String> ids)
          Retrieves all features identified by a particular id in a given field of the shape file and then returns them as a FeatureCollection.
  getMultipleFeaturesByPattern(String field, String id)
          Retrieves the set of features identified by a particular 'id' in a given field of a shape file and then returns it as a FeatureCollection.
  getMultipleFeaturesByPattern(String field, String[] ids)
          Retrieves all features identified by a particular id in a given field of the shape file and then returns them as a FeatureCollection.
  getMultipleFeaturesByValue(String field, double min)
          Select a set of attributes using a double-precision value instead of a SQL-like string.
 int getProjection()
           
 int getProjection( f)
           
 int interpolateColor(PApplet a, float value, float min, float max)
           
 float map(float x1, float xMin, float xMax, float xRemapMin, float xRemapMax)
          Used by all classes to map their contents on to the plane of the sketch.
 void setColorScale(int lowColor, int highColor, int numberOfSteps)
          Apply a scale that will be used for values or categories within this object.
 void setColorScale(int lowColor, int midColor, int highColor, int numberOfSteps)
          Apply a scale that will be used for values or categories within this object.
 void setColourScale(int lowColour, int highColour, int numberOfSteps)
          Apply a scale that will be used for values or categories within this object.
 void setColourScale(int lowColour, int midColour, int highColour, int numberOfSteps)
          Apply a scale that will be used for values or categories within this object.
 void setGlobalSimplificationThreshold(double d)
          Used by the Lines and Polygons objects to implement various types of simplification appropriate to the object being displayed.
 void setLabelField(int fieldId)
          Specify the column position that contains the values that you want to use as a label in your Processing sketch.
 void setLabelField(String fieldName)
          Specify the name of the column that contains the values (i.e.
 void setLocalSimplificationThreshold(double d)
          Used by the Lines and Polygons objects to implement various types of simplification appropriate to the object being displayed.
 void setValueField(int fieldId)
          Specify the column position that contains the values that you want to use in your Processing sketch.
 void setValueField(String fieldName)
          Specify the name of the column that contains the values (i.e.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public boolean DEBUG
Constructor Detail

Generic

public Generic(BoundingBox b,
                f)

A default implementation. Often used to instantiate polygons and lines from within the shape file as separate, draw-able entities within the sketch.

Parameters:
b - the BoundingBox object defining the default view
f - the FeatureCollection used to instantiate the object

Generic

public Generic(BoundingBox b,
               SimpleFeature f)

A default implementation. Often used to instantiate polygons and lines from within the shape file as separate, draw-able entities within the sketch. Note that we create a FeatureCollection even though there's only one feature contained within it. This is to ensure consistency in handling objects across the pipeline.

Parameters:
b - the BoundingBox object defining the default view
f - the SimpleFeature retrieved from the shape file
Method Detail

setLocalSimplificationThreshold

public void setLocalSimplificationThreshold(double d)

Used by the Lines and Polygons objects to implement various types of simplification appropriate to the object being displayed. This works in the units of the shape file itself, so in the case of OSGB-mapped shapes it would be metres.

Note that we have two types of simplifcation here: this one works on each object individually, while the other method works on them all simultaneously.

Parameters:
d - the distance over which to simplify
See Also:
setGlobalSimplificationThreshold

setGlobalSimplificationThreshold

public void setGlobalSimplificationThreshold(double d)

Used by the Lines and Polygons objects to implement various types of simplification appropriate to the object being displayed. This works in the units of the shape file itself, so in the case of OSGB-mapped shapes it would be metres.

Note that we have two types of simplifcation here: this one works on them all at once, while the other method works on each one individually.

Parameters:
d - the distance over which to simplify
See Also:
setLocalSimplificationThreshold

getCentroids

public  getCentroids()
Returns the centroids of an object in a Processing sketch. This essentially clones the Points, Polygons, or Lines object so that you can use both in your sketch with the same reference features.


map

public float map(float x1,
                 float xMin,
                 float xMax,
                 float xRemapMin,
                 float xRemapMax)

Used by all classes to map their contents on to the plane of the sketch. So we translate between the range of the shape file and range of the viewport we want to work with. Note that this can produce remapped values that are negative, below xRemapMin, or exceed xRemapMax.

Parameters:
x1 - the input position along the x- or y-axis
xMin - the expected minimum value of the range from which x1 is drawn
xMax - the expected maximum value of the range from which x1 is drawn
xRemapMin - what we are mapping xMin on to
xRemapMax - what we are mapping xMax on to
Returns:
A float indicating the new value of x1

getMultipleFeaturesByPattern

public  getMultipleFeaturesByPattern(String field,
                                          String id)

Retrieves the set of features identified by a particular 'id' in a given field of a shape file and then returns it as a FeatureCollection. Note that it makes no assumptions about the type of feature returned, you must take care of this yourself.

The main thing that this offers is the ability to retrieve results based on a 'LIKE' query. So if you pass in '%Greater%' as the 'id', and CITY_NAME as the field, then you might get back 'Greater London', 'Greater Manchester', etc.

Returns:
FeatureCollection

getMultipleFeaturesById

public  getMultipleFeaturesById(String field,
                                     String id)
Deprecated. I've kept this for backwards-compatibility with anyone who tried out version 1.0 but I intend to remove this down the line since the method name is less clear.

Parameters:
field -
id -
Returns:
FeatureCollection

getMultipleFeaturesByPattern

public  getMultipleFeaturesByPattern(String field,
                                          String[] ids)

Retrieves all features identified by a particular id in a given field of the shape file and then returns them as a FeatureCollection. Note that it makes no assumptions about the type of feature returned, you must take care of this yourself.

The principal difference between this and the version that takes a Set is that the return values will ordered by the input array.

Returns:
FeatureCollection

getMultipleFeaturesById

public  getMultipleFeaturesById(String field,
                                     String[] ids)
Deprecated. I've kept this for backwards-compatibility with anyone who tried out version 1.0 but I intend to remove this down the line since the method name is less clear.

Parameters:
field -
ids -
Returns:
FeatureCollection

getMultipleFeaturesByPattern

public  getMultipleFeaturesByPattern(String field,
                                          Set<String> ids)

Retrieves all features identified by a particular id in a given field of the shape file and then returns them as a FeatureCollection. Note that it makes no assumptions about the type of feature returned, you must take care of this yourself.

The principal difference between this and the version that takes a String[] is that the return values will not necessarily be ordered in any particular way. So if the order of the rows in the Shape file are meaningful in some way then you should use the other method instead.

Returns:
FeatureCollection

getMultipleFeaturesById

public  getMultipleFeaturesById(String field,
                                     Set<String> ids)
Deprecated. I've kept this for backwards-compatibility with anyone who tried out version 1.0 but I intend to remove this down the line since the method name is less clear.

Parameters:
field -
ids -
Returns:
FeatureCollection

getMultipleFeaturesByValue

public  getMultipleFeaturesByValue(String field,
                                        double min)
Select a set of attributes using a double-precision value instead of a SQL-like string. This works for, say, selecting countries whose area is greater than 'min' so that you only label the largest ones.

Parameters:
field - the name of the column in which the values can be found
min - the minimum value which must be exceeded for the feature to be selected
Returns:
FeatureCollection

getFeatures

public  getFeatures()
Retrieves all features contained in the data source and returns them as a FeatureCollection. This is the best way to get at the underlying GeoTools data if you want to do something more sophisticated that isn't yet implemented in the main codebase.

Returns:
FeatureIterator

getBounds

public ReferencedEnvelope getBounds()
Get the boundary envelope of the shape file itself

Returns:
A ReferenceEnvelop object

setLabelField

public void setLabelField(String fieldName)
Specify the name of the column that contains the values (i.e. place names or country names) that you want to use as a label in your Processing sketch.

Parameters:
fieldName -

setLabelField

public void setLabelField(int fieldId)
Specify the column position that contains the values that you want to use as a label in your Processing sketch. This will automatically skip over the features themselves, but you'll need to use trial-and-error to figure out which field contains the values you want (although they should come in the order in which they're specified in the shape file or CSV file).

Parameters:
fieldId -

setValueField

public void setValueField(String fieldName)
Specify the name of the column that contains the values (i.e. numbers or categories) that you want to use in your Processing sketch.

Parameters:
fieldName -

setValueField

public void setValueField(int fieldId)
Specify the column position that contains the values that you want to use in your Processing sketch. This will automatically skip over the features themselves, but you'll need to use trial-and-error to figure out which field contains the values you want (although they should come in the order in which they're specified in the shape file or CSV file).

Parameters:
fieldId -

setColorScale

public void setColorScale(int lowColor,
                          int highColor,
                          int numberOfSteps)
Apply a scale that will be used for values or categories within this object. The idea here is that you can set a single color scale and use it on different values while the code takes care of coloring it for you.

Parameters:
lowColor -
highColor -
numberOfSteps -

setColourScale

public void setColourScale(int lowColour,
                           int highColour,
                           int numberOfSteps)
Apply a scale that will be used for values or categories within this object. The idea here is that you can set a single colour scale and use it on different values while the code takes care of colouring it for you.

Parameters:
lowColour -
highColour -
numberOfSteps -

setColorScale

public void setColorScale(int lowColor,
                          int midColor,
                          int highColor,
                          int numberOfSteps)
Apply a scale that will be used for values or categories within this object. The idea here is that you can set a single color scale and use it on different values while the code takes care of coloring it for you.

Parameters:
lowColor -
midColor -
highColor -
numberOfSteps -

setColourScale

public void setColourScale(int lowColour,
                           int midColour,
                           int highColour,
                           int numberOfSteps)
Apply a scale that will be used for values or categories within this object. The idea here is that you can set a single colour scale and use it on different values while the code takes care of colouring it for you.

Parameters:
lowColour - a Processing color object representing the low-value colour
midColour - a Processing color object representing the mid-value colour
highColour - a Processing color object representing the high-value colour
numberOfSteps -

interpolateColor

public int interpolateColor(PApplet a,
                            float value,
                            float min,
                            float max)

getProjection

public int getProjection()

getProjection

public int getProjection( f)

appendNearestFeatures

public void appendNearestFeatures(Generic gs,
                                  double maxDistance)
Incomplete implementation -- this is supposed to allow you to select features falling within a particular distance of a polygon, but as yet I've not quite figured how to do it properly.



Processing library MapThing by Jon Reades. (C) 2013