uk.me.parabola.imgfmt.app.trergn
Class Subdivision

java.lang.Object
  extended by uk.me.parabola.imgfmt.app.trergn.Subdivision

public class Subdivision
extends java.lang.Object

The map is divided into areas, depending on the zoom level. These are known as subdivisions. A subdivision 'belongs' to a zoom level and cannot be interpreted correctly without knowing the bitsPerCoord of the associated zoom level. Subdivisions also form a tree as subdivisions are further divided at lower levels. The subdivisions need to know their child divisions because this information is represented in the map.

Author:
Steve Ratcliffe

Method Summary
static Subdivision createEmptySubdivision(int number)
          Create a subdivision that only contains the number.
 Polyline createLine(java.lang.String name, java.lang.String ref)
           
 Point createPoint(java.lang.String name)
           
 Polygon createPolygon(java.lang.String name)
           
 Subdivision createSubdivision(InternalFiles ifiles, Area area, Zoom zoom)
          Create a subdivision at a given zoom level.
 void endDivision()
           
 int getEndRgnPointer()
           
 int getLatitude()
           
 int getLongitude()
           
protected  int getMask()
          Get the shift mask.
 int getNumber()
           
 int getResolution()
          Get the resolution of this division.
 int getShift()
          Get the shift value, that is the number of bits to left shift by for values that need to be saved shifted in the file.
 int getStartRgnPointer()
           
 Zoom getZoom()
           
 boolean hasIndPoints()
           
 boolean hasNextLevel()
           
 boolean hasPoints()
           
 boolean hasPolygons()
           
 boolean hasPolylines()
           
 boolean needsIndPointPtr()
          Needed if it exists and is not first, ie there is a points section.
 boolean needsPolygonPtr()
          As this is last in the list it is needed if it exists and there is another section.
 boolean needsPolylinePtr()
          Needed if it exists and is not first, ie there is a points or indexed points section.
static Subdivision readSubdivision(Zoom zoom, SubdivData subdivData)
           
 int roundLatToLocalShifted(int absval)
          Convert an absolute Lat to a local, shifted value
 int roundLonToLocalShifted(int absval)
          Convert an absolute Lon to a local, shifted value
 void setHasIndPoints(boolean hasIndPoints)
           
 void setHasPoints(boolean hasPoints)
           
 void setHasPolygons(boolean hasPolygons)
           
 void setHasPolylines(boolean hasPolylines)
           
 void setLast(boolean last)
           
 void setNumber(int n)
           
 void setPolylineNumber(Polyline pl)
           
 void setStartRgnPointer(int startRgnPointer)
           
 void startDivision()
           
 void startIndPoints()
          We are starting to draw the lines.
 void startLines()
          We are starting to draw the lines.
 void startPoints()
          We are starting to draw the points.
 void startShapes()
          We are starting to draw the shapes.
static Subdivision topLevelSubdivision(InternalFiles ifiles, Area area, Zoom zoom)
          This should be called only once per map to create the top level subdivision.
 java.lang.String toString()
           
 void write(ImgFileWriter file)
          Format this record to the file.
 void writeExtTypeOffsetsRecord(ImgFileWriter file)
           
 void writeLastExtTypeOffsetsRecord(ImgFileWriter file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createSubdivision

public Subdivision createSubdivision(InternalFiles ifiles,
                                     Area area,
                                     Zoom zoom)
Create a subdivision at a given zoom level.

Parameters:
ifiles - The RGN and LBL ifiles.
area - The (unshifted) area that the subdivision covers.
zoom - The zoom level that this division occupies.
Returns:
A new subdivision.

topLevelSubdivision

public static Subdivision topLevelSubdivision(InternalFiles ifiles,
                                              Area area,
                                              Zoom zoom)
This should be called only once per map to create the top level subdivision. The top level subdivision covers the whole map and it must be empty.

Parameters:
ifiles - The LBL and RGN ifiles.
area - The area bounded by the map.
zoom - The zoom level which must be the highest (least detailed) zoom in the map.
Returns:
The new subdivision.

createEmptySubdivision

public static Subdivision createEmptySubdivision(int number)
Create a subdivision that only contains the number. This is only used when reading cities and similar such usages that do not really require the full subdivision to be present.

Parameters:
number - The subdivision number.
Returns:
An empty subdivision. Any operation other than getting the subdiv number is likely to fail.

readSubdivision

public static Subdivision readSubdivision(Zoom zoom,
                                          SubdivData subdivData)

getZoom

public Zoom getZoom()

getShift

public final int getShift()
Get the shift value, that is the number of bits to left shift by for values that need to be saved shifted in the file. Related to the resolution.

Returns:
The shift value. It is 24 minus the number of bits per coord.
See Also:
getResolution()

getMask

protected int getMask()
Get the shift mask. The bits that will be lost due to the resolution shift level.

Returns:
A bit mask with the lower shift bits set.

getResolution

public final int getResolution()
Get the resolution of this division. Resolution goes from 1 to 24 and the higher the number the more detail there is.

Returns:
The resolution.

write

public void write(ImgFileWriter file)
Format this record to the file.

Parameters:
file - The file to write to.

createPoint

public Point createPoint(java.lang.String name)

createLine

public Polyline createLine(java.lang.String name,
                           java.lang.String ref)

setPolylineNumber

public void setPolylineNumber(Polyline pl)

createPolygon

public Polygon createPolygon(java.lang.String name)

setNumber

public void setNumber(int n)

setLast

public void setLast(boolean last)

setStartRgnPointer

public void setStartRgnPointer(int startRgnPointer)

getStartRgnPointer

public int getStartRgnPointer()

getEndRgnPointer

public int getEndRgnPointer()

getLongitude

public int getLongitude()

getLatitude

public int getLatitude()

setHasPoints

public void setHasPoints(boolean hasPoints)

setHasIndPoints

public void setHasIndPoints(boolean hasIndPoints)

setHasPolylines

public void setHasPolylines(boolean hasPolylines)

setHasPolygons

public void setHasPolygons(boolean hasPolygons)

hasPoints

public boolean hasPoints()

hasIndPoints

public boolean hasIndPoints()

hasPolylines

public boolean hasPolylines()

hasPolygons

public boolean hasPolygons()

needsIndPointPtr

public boolean needsIndPointPtr()
Needed if it exists and is not first, ie there is a points section.

Returns:
true if pointer needed

needsPolylinePtr

public boolean needsPolylinePtr()
Needed if it exists and is not first, ie there is a points or indexed points section.

Returns:
true if pointer needed.

needsPolygonPtr

public boolean needsPolygonPtr()
As this is last in the list it is needed if it exists and there is another section.

Returns:
true if pointer needed.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hasNextLevel

public boolean hasNextLevel()

startDivision

public void startDivision()

endDivision

public void endDivision()

writeExtTypeOffsetsRecord

public void writeExtTypeOffsetsRecord(ImgFileWriter file)

writeLastExtTypeOffsetsRecord

public void writeLastExtTypeOffsetsRecord(ImgFileWriter file)

getNumber

public int getNumber()

startPoints

public void startPoints()
We are starting to draw the points. These must be done first.


startIndPoints

public void startIndPoints()
We are starting to draw the lines. These must be done before polygons.


startLines

public void startLines()
We are starting to draw the lines. These must be done before polygons.


startShapes

public void startShapes()
We are starting to draw the shapes. This is done last.


roundLatToLocalShifted

public int roundLatToLocalShifted(int absval)
Convert an absolute Lat to a local, shifted value


roundLonToLocalShifted

public int roundLonToLocalShifted(int absval)
Convert an absolute Lon to a local, shifted value