com.reades.mapthing
Class Polygons

java.lang.Object
  extended by com.reades.mapthing.Generic
      extended by com.reades.mapthing.Polygons
All Implemented Interfaces:
Serializable

public class Polygons
extends Generic
implements Serializable

Creates polygons from a Polygon shape file in ArcGIS.

Issues to be tested/implemented:

See Also:
Serialized Form

Field Summary
 boolean DEBUG
           
 
Constructor Summary
Polygons(BoundingBox b,  f)
          Usually used to instantiate a Polygon object from within the general feature collection of the shape file so that it can be manipulated separately from the other polygons.
Polygons(BoundingBox b, SimpleFeature f)
          Usually used to instantiate a Polygon object from within the processing of the shape file so that it can be manipulated separately from the other polygons.
Polygons(BoundingBox b, String r)
          Instantiate the GeoLine object with a BoundingBox and String.
 
Method Summary
 ArrayList<Coordinate[]> getCoordinates()
          Returns the raw SimpleFeature coordinates associated with the polygons as an ArrayList of coordinate arrays.
 ArrayList<Node[]> getCoordinates(PApplet a)
          Return an ArrayList, each row of which contains an array of Nodes.
 HashMap<Integer,Polygons> getPolygonsWithId(String idField)
          Return a HashMap which contains all of the polygons keyed on the named ID field.
 boolean isClosed()
          Check whether polygons should be drawn closed or open.
 boolean isClosed(boolean c)
          Specify whether polygons should be drawn closed or open.
 void project(PApplet a)
          Draws all of the vertices contained in a Polygon object loaded from a file.
 void project(PApplet a, PGraphics p)
          Draws all of the vertices contained in a Polygon object loaded from a file.
 void projectValues(PApplet a, float min, float max)
          Apply a color scale to the the polygons so that it is possible to represent the values in a useful way.
 void reverse()
          Reverses the order of the points in a polygon.
 void transformCoordinates(PApplet a)
          Called before you can display the polygons in a Processing sketch.
 
Methods inherited from class com.reades.mapthing.Generic
appendNearestFeatures, getBounds, getCentroids, getFeatures, getMultipleFeaturesById, getMultipleFeaturesById, getMultipleFeaturesById, getMultipleFeaturesByPattern, getMultipleFeaturesByPattern, getMultipleFeaturesByPattern, getMultipleFeaturesByValue, getProjection, getProjection, interpolateColor, map, setColorScale, setColorScale, setColourScale, setColourScale, setGlobalSimplificationThreshold, setLabelField, setLabelField, setLocalSimplificationThreshold, setValueField, setValueField
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public boolean DEBUG
Constructor Detail

Polygons

public Polygons(BoundingBox b,
                String r)
Instantiate the GeoLine object with a BoundingBox and String. Depending on whether the String ends in .csv or .shp we will employ the appropriate tool to open and read the data.

Parameters:
b - the bounding box of the default view
r - a String that allows us to determine the type of resource to open

Polygons

public Polygons(BoundingBox b,
                 f)
Usually used to instantiate a Polygon object from within the general feature collection of the shape file so that it can be manipulated separately from the other polygons. Note that this isn't guaranteed to return a viable object (in terms of it being one that can be displayed on the screen) and that it could be NULL.

Parameters:
b - the bounding box of the parent Polygons object
f - the feature collection used to instantiate the new object

Polygons

public Polygons(BoundingBox b,
                SimpleFeature f)
Usually used to instantiate a Polygon object from within the processing of the shape file so that it can be manipulated separately from the other polygons.

Parameters:
b - the bounding box of the parent Polygons object
f - the Simple Feature used to instantiate the new object
Method Detail

transformCoordinates

public void transformCoordinates(PApplet a)
Called before you can display the polygons in a Processing sketch. It simply passes in the height and width of the sketch so that we can remap the coordinates of the shape file into the plain of the sketch itself.

Parameters:
a - the Processing PApplet object

getPolygonsWithId

public HashMap<Integer,Polygons> getPolygonsWithId(String idField)
Return a HashMap which contains all of the polygons keyed on the named ID field. This would be useful if you wanted selectively colour or otherwise adjust the display of the polygons based on some external data input.

Returns:
HashMap

getCoordinates

public ArrayList<Node[]> getCoordinates(PApplet a)
Return an ArrayList, each row of which contains an array of Nodes. The idea is that each array represents a separate polygon that can be drawn in the sketch. The simplest case is to then just pass the entire ArrayList straight to the drawPolygons() method in GeoPApplet.

Returns:
An ArrayList of Node arrays

getCoordinates

public ArrayList<Coordinate[]> getCoordinates()
Returns the raw SimpleFeature coordinates associated with the polygons as an ArrayList of coordinate arrays. You can use these to manipulate the coordinates in any way you like as they have not been mapped on to the space of the sketch.

Returns:
ArrayList

isClosed

public boolean isClosed(boolean c)
Specify whether polygons should be drawn closed or open. If closed, then a line connecting the last point in the polygon to the first point will be drawn. If open, then no connecting line will be drawn (though the latter could still look the same if there is a redundant point at the end of the polygon coordinates that is the same as the first coordinate).


isClosed

public boolean isClosed()
Check whether polygons should be drawn closed or open. If closed, then a line connecting the last point in the polygon to the first point will be drawn. If open, then no connecting line will be drawn (though the latter could still look the same if there is a redundant point at the end of the polygon coordinates that is the same as the first coordinate).


project

public void project(PApplet a)
Draws all of the vertices contained in a Polygon object loaded from a file. The simplest way to work with this method is to set the color, fill, and stroke in your sketch and then just call this function by passing it the Applet instance (probably by saying: object.project(this).

Parameters:
a - a Processing PApplet object

projectValues

public void projectValues(PApplet a,
                          float min,
                          float max)
Apply a color scale to the the polygons so that it is possible to represent the values in a useful way.

Parameters:
a - a Processing PApplet object
min - the minimum value of the value field (I will try to make this automatic in later releases)
max - the maximum value of the value field (I will try to make this automatic in later releases)

project

public void project(PApplet a,
                    PGraphics p)

Draws all of the vertices contained in a Polygon object loaded from a file. This one differs from the version without a PGraphics object in that it allows you to use the graphics object as a buffer and won't write directly to the Applet view.

The simplest way to work with this method is to set the color, fill, and stroke in your sketch and then just call this function by passing it the Applet and Graphics instances

Note that if you want the image to appear right on top of the coordinates then you will need to call "imageMode(CENTER)" in your sketch first.

Parameters:
a - a Processing PApplet object
p - a Processing PGraphics object

reverse

public void reverse()

Reverses the order of the points in a polygon. Note that this will only do something if you have already called transformCoordinates or project once (since it only works on the points that have been mapped into the Processing sketch.



Processing library MapThing by Jon Reades. (C) 2013