sick of the horribly ugly formatting in this file. My eyes just can't take it anymore!

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@934860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2010-04-16 13:15:34 +00:00
parent ea9cc21c5d
commit 5a10e41aa8
1 changed files with 80 additions and 83 deletions

View File

@ -17,16 +17,16 @@
package org.apache.lucene.spatial.tier; package org.apache.lucene.spatial.tier;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.spatial.geometry.FloatLatLng;
import org.apache.lucene.spatial.geometry.LatLng;
import org.apache.lucene.spatial.geometry.shape.LLRect;
import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter; import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter;
import org.apache.lucene.spatial.tier.projections.IProjector; import org.apache.lucene.spatial.tier.projections.IProjector;
import org.apache.lucene.spatial.tier.projections.SinusoidalProjector; import org.apache.lucene.spatial.tier.projections.SinusoidalProjector;
import org.apache.lucene.spatial.geometry.LatLng;
import org.apache.lucene.spatial.geometry.FloatLatLng; import java.math.BigDecimal;
import org.apache.lucene.spatial.geometry.shape.LLRect; import java.math.RoundingMode;
/** /**
@ -44,26 +44,25 @@ public class CartesianPolyFilterBuilder {
private IProjector projector = new SinusoidalProjector(); private IProjector projector = new SinusoidalProjector();
private final String tierPrefix; private final String tierPrefix;
private int minTier; private int minTier;
private int maxTier; private int maxTier;
/** /**
* * @param tierPrefix The prefix for the name of the fields containing the tier info
* @param tierPrefix The prefix for the name of the fields containing the tier info
* @param minTierIndexed The minimum tier level indexed * @param minTierIndexed The minimum tier level indexed
* @param maxTierIndexed The maximum tier level indexed * @param maxTierIndexed The maximum tier level indexed
*/ */
public CartesianPolyFilterBuilder( String tierPrefix, int minTierIndexed, int maxTierIndexed ) { public CartesianPolyFilterBuilder(String tierPrefix, int minTierIndexed, int maxTierIndexed) {
this.tierPrefix = tierPrefix; this.tierPrefix = tierPrefix;
this.minTier = minTierIndexed; this.minTier = minTierIndexed;
this.maxTier = maxTierIndexed; this.maxTier = maxTierIndexed;
} }
public Shape getBoxShape(double latitude, double longitude, double miles) public Shape getBoxShape(double latitude, double longitude, double miles) {
{
if (miles < MILES_FLOOR) { if (miles < MILES_FLOOR) {
miles = MILES_FLOOR; miles = MILES_FLOOR;
} }
LLRect box1 = LLRect.createBox( new FloatLatLng( latitude, longitude ), miles, miles ); LLRect box1 = LLRect.createBox(new FloatLatLng(latitude, longitude), miles, miles);
LatLng ll = box1.getLowerLeft(); LatLng ll = box1.getLowerLeft();
LatLng ur = box1.getUpperRight(); LatLng ur = box1.getUpperRight();
@ -72,97 +71,96 @@ public class CartesianPolyFilterBuilder {
double longY = ur.getLng(); double longY = ur.getLng();
double longX = ll.getLng(); double longX = ll.getLng();
double longX2 = 0.0; double longX2 = 0.0;
//These two if checks setup us up to deal with issues around the prime meridian and the 180th meridian //These two if checks setup us up to deal with issues around the prime meridian and the 180th meridian
//In these two cases, we need to get tiles (tiers) from the lower left up to the meridian and then //In these two cases, we need to get tiles (tiers) from the lower left up to the meridian and then
//from the meridan to the upper right //from the meridan to the upper right
//Are we crossing the 180 deg. longitude, if so, we need to do some special things //Are we crossing the 180 deg. longitude, if so, we need to do some special things
if (ur.getLng() < 0.0 && ll.getLng() > 0.0) { if (ur.getLng() < 0.0 && ll.getLng() > 0.0) {
longX2 = ll.getLng(); longX2 = ll.getLng();
longX = -180.0; longX = -180.0;
} }
//are we crossing the prime meridian (0 degrees)? If so, we need to account for it and boxes on both sides //are we crossing the prime meridian (0 degrees)? If so, we need to account for it and boxes on both sides
if (ur.getLng() > 0.0 && ll.getLng() < 0.0) { if (ur.getLng() > 0.0 && ll.getLng() < 0.0) {
longX2 = ll.getLng(); longX2 = ll.getLng();
longX = 0.0; longX = 0.0;
} }
//System.err.println("getBoxShape:"+latY+"," + longY); //System.err.println("getBoxShape:"+latY+"," + longY);
//System.err.println("getBoxShape:"+latX+"," + longX); //System.err.println("getBoxShape:"+latX+"," + longX);
CartesianTierPlotter ctp = new CartesianTierPlotter(2, projector,tierPrefix); CartesianTierPlotter ctp = new CartesianTierPlotter(2, projector, tierPrefix);
int bestFit = ctp.bestFit(miles); int bestFit = ctp.bestFit(miles);
if (bestFit < minTier){ if (bestFit < minTier) {
bestFit = minTier; bestFit = minTier;
} else if (bestFit > maxTier){ } else if (bestFit > maxTier) {
bestFit = maxTier; bestFit = maxTier;
} }
ctp = new CartesianTierPlotter(bestFit, projector,tierPrefix); ctp = new CartesianTierPlotter(bestFit, projector, tierPrefix);
Shape shape = new Shape(ctp.getTierFieldName()); Shape shape = new Shape(ctp.getTierFieldName());
// generate shape // generate shape
// iterate from startX->endX // iterate from startX->endX
// iterate from startY -> endY // iterate from startY -> endY
// shape.add(currentLat.currentLong); // shape.add(currentLat.currentLong);
//for the edge cases (prime meridian and the 180th meridian), this call handles all tiles East of the meridian //for the edge cases (prime meridian and the 180th meridian), this call handles all tiles East of the meridian
//for all other cases, it handles the whole set of tiles //for all other cases, it handles the whole set of tiles
shape = getShapeLoop(shape,ctp,latX,longX,latY,longY); shape = getShapeLoop(shape, ctp, latX, longX, latY, longY);
if (longX2 != 0.0) { if (longX2 != 0.0) {
if (longX == 0.0) { if (longX == 0.0) {
longX = longX2; longX = longX2;
longY = 0.0; longY = 0.0;
//handles the lower left longitude to the prime meridian //handles the lower left longitude to the prime meridian
//shape = getShapeLoop(shape, ctp, latX, longX, latY, longY); //shape = getShapeLoop(shape, ctp, latX, longX, latY, longY);
} else { } else {
//this clause handles the lower left longitude up to the 180 meridian //this clause handles the lower left longitude up to the 180 meridian
longX = longX2; longX = longX2;
longY = 180.0; longY = 180.0;
} }
shape = getShapeLoop(shape, ctp, latX, longX, latY, longY); shape = getShapeLoop(shape, ctp, latX, longX, latY, longY);
//System.err.println("getBoxShape2:"+latY+"," + longY); //System.err.println("getBoxShape2:"+latY+"," + longY);
//System.err.println("getBoxShape2:"+latX+"," + longX); //System.err.println("getBoxShape2:"+latX+"," + longX);
} }
return shape; return shape;
} }
public Shape getShapeLoop(Shape shape, CartesianTierPlotter ctp, double latX, double longX, double latY, double longY) public Shape getShapeLoop(Shape shape, CartesianTierPlotter ctp, double latX, double longX, double latY, double longY) {
{
//System.err.println("getShapeLoop:"+latY+"," + longY); //System.err.println("getShapeLoop:"+latY+"," + longY);
//System.err.println("getShapeLoop:"+latX+"," + longX); //System.err.println("getShapeLoop:"+latX+"," + longX);
double beginAt = ctp.getTierBoxId(latX, longX); double beginAt = ctp.getTierBoxId(latX, longX);
double endAt = ctp.getTierBoxId(latY, longY); double endAt = ctp.getTierBoxId(latY, longY);
if (beginAt > endAt){ if (beginAt > endAt) {
double tmp = beginAt; double tmp = beginAt;
beginAt = endAt; beginAt = endAt;
endAt = tmp; endAt = tmp;
} }
double tierVert = ctp.getTierVerticalPosDivider(); double tierVert = ctp.getTierVerticalPosDivider();
//System.err.println(" | "+ beginAt+" | "+ endAt); //System.err.println(" | "+ beginAt+" | "+ endAt);
double startX = beginAt - (beginAt %1); double startX = beginAt - (beginAt % 1);
double startY = beginAt - startX ; //should give a whole number double startY = beginAt - startX; //should give a whole number
double endX = endAt - (endAt %1); double endX = endAt - (endAt % 1);
double endY = endAt -endX; //should give a whole number double endY = endAt - endX; //should give a whole number
int scale = (int)Math.log10(tierVert); int scale = (int) Math.log10(tierVert);
endY = new BigDecimal(endY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue(); endY = new BigDecimal(endY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();
startY = new BigDecimal(startY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue(); startY = new BigDecimal(startY).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();
double xInc = 1.0d / tierVert; double xInc = 1.0d / tierVert;
xInc = new BigDecimal(xInc).setScale(scale, RoundingMode.HALF_EVEN).doubleValue(); xInc = new BigDecimal(xInc).setScale(scale, RoundingMode.HALF_EVEN).doubleValue();
//System.err.println("go from startX:"+startX+" to:" + endX); //System.err.println("go from startX:"+startX+" to:" + endX);
for (; startX <= endX; startX++){ for (; startX <= endX; startX++) {
double itY = startY; double itY = startY;
//System.err.println("go from startY:"+startY+" to:" + endY); //System.err.println("go from startY:"+startY+" to:" + endY);
while (itY <= endY){ while (itY <= endY) {
//create a boxId //create a boxId
// startX.startY // startX.startY
double boxId = startX + itY ; double boxId = startX + itY;
shape.addBox(boxId); shape.addBox(boxId);
//System.err.println("----"+startX+" and "+itY); //System.err.println("----"+startX+" and "+itY);
//System.err.println("----"+boxId); //System.err.println("----"+boxId);
@ -176,8 +174,7 @@ public class CartesianPolyFilterBuilder {
return shape; return shape;
} }
public Filter getBoundingArea(double latitude, double longitude, double miles) public Filter getBoundingArea(double latitude, double longitude, double miles) {
{
Shape shape = getBoxShape(latitude, longitude, miles); Shape shape = getBoxShape(latitude, longitude, miles);
return new CartesianShapeFilter(shape, shape.getTierId()); return new CartesianShapeFilter(shape, shape.getTierId());
} }