com.reades.mapthing
Class BoundingBox

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

public class BoundingBox
extends Object
implements Serializable

An implementation of a bounding box for Processing sketches. We use this to specify the default viewable area of the sketch in terms of its geographical coordinates (North, East, South, and West) so that we can easily remap geographical coordinates on to the plain of the sketch itself. We also need to handle projections -- right now we'll do it a fairly simplistic way just to get this thing out the door, but in time it might be nice to get a little smarter about enabling people to do things in more sophisticated ways.

See Also:
Serialized Form

Field Summary
 boolean DEBUG
           
static int osgb
           
static int wgs
           
 
Constructor Summary
BoundingBox(float n, float e, float s, float w)
          The default constructor creates a bounding box that assumes standard lat/long coordinates.
BoundingBox(int p, float n, float e, float s, float w)
          Right now there's not much 'smarts' behind the use of the projection, but in future releases I plan to make this much more relevant by allowing you to use multiple projections and have the code be clever enough to reproject everything on the fly so that it 'just works' without your having to do a lot of faffing about on your own.
 
Method Summary
 float getEast()
           
 float getNorth()
           
 int getProjection()
           
 float getSouth()
           
 float getWest()
           
 int heightFromWidth(int h)
           
 boolean isEqual(BoundingBox b)
           
 boolean isEqual(BoundingBox b, float margin)
           
 float mapToScreenHeight()
           
 float mapToScreenWidth()
           
 float mapToScreenX()
           
 float mapToScreenY()
           
 void setContext(BoundingBox c, int w, int h)
           
 void setProjection(int p)
          Use this if you need to manually re-set the projection for some reason.
 int widthFromHeight(int w)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

osgb

public static final int osgb
See Also:
Constant Field Values

wgs

public static final int wgs
See Also:
Constant Field Values

DEBUG

public boolean DEBUG
Constructor Detail

BoundingBox

public BoundingBox(float n,
                   float e,
                   float s,
                   float w)
The default constructor creates a bounding box that assumes standard lat/long coordinates. So using this constructor with OSGB coordinates would give... interesting... results. If you want to use anything else then you will have to use the form of the constructor that takes a projection value. To make things easy for those of you in the UK you can just use the public osgb integer in this class.

Parameters:
n - the northern edge of the intended map
e - the eastern edge of the intended map
s - the southern edge of the intended map
w - the western edge of the intended map

BoundingBox

public BoundingBox(int p,
                   float n,
                   float e,
                   float s,
                   float w)
Right now there's not much 'smarts' behind the use of the projection, but in future releases I plan to make this much more relevant by allowing you to use multiple projections and have the code be clever enough to reproject everything on the fly so that it 'just works' without your having to do a lot of faffing about on your own. For now, however, you *must* use the same projection for everything and we assume a system that maps pretty cleanly on to x and y coordinates. So consider this method a fairly useless extension *for the time being* since we only store and don't really do much with the projection string. But if you want to specify a particular projection then you will need to tell us what one you're using in the standard EPSG/OGC WKT form (go to http://spatialreference.org/ and then pick 'OGC WKT' as the format and look for the *last* 'AUTHORITY' declaration in the PROJCS command). The default (if you don't specify a reference) is WGS84, but because I do a lot of work in the UK I've made it easy to use OSGB coordinates too. For everything else you're on your own right now.

Parameters:
p - the projection integer taken from OGC WKT authority declaration
n - the northern edge of the intended map
e - the eastern edge of the intended map
s - the southern edge of the intended map
w - the western edge of the intended map
Method Detail

setContext

public void setContext(BoundingBox c,
                       int w,
                       int h)

mapToScreenX

public float mapToScreenX()

mapToScreenY

public float mapToScreenY()

mapToScreenWidth

public float mapToScreenWidth()

mapToScreenHeight

public float mapToScreenHeight()

getEast

public float getEast()

getWest

public float getWest()

getNorth

public float getNorth()

getSouth

public float getSouth()

getProjection

public int getProjection()

isEqual

public boolean isEqual(BoundingBox b)

isEqual

public boolean isEqual(BoundingBox b,
                       float margin)

setProjection

public void setProjection(int p)
Use this if you need to manually re-set the projection for some reason. You might find this useful if you have no idea what projection your files are in and want to load a shape file first and then pull the projection metadata from there.

Parameters:
p - An OGC WKT format integer (4326 is WGS86 lat/long, 27700 is OSGB 1936, etc.)

widthFromHeight

public int widthFromHeight(int w)

heightFromWidth

public int heightFromWidth(int h)


Processing library MapThing by Jon Reades. (C) 2013