You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Lance Java <la...@googlemail.com> on 2011/12/31 17:52:51 UTC

Spatial Search

Hi, I am new to Lucene and I am trying to use spatial search. I have
googled and found a few people talking about it. I can't find any working
examples so was hoping that someone on this list could help me.

I have attached a test case to this email which adds all of the London
train stations (latitude / longitude) to an index and then performs 4
queries to find all stations that are 1, 2, 3 and 4 miles from Liverpool
St. Station.

At the moment, the test case is not working and returns all 409 stations
for each of the four queries (1,2,3 & 4 miles). I was hoping that someone
with some spatial search knowledge could tweak the test case so that it
works (ie more stations are returned for the 4 mile radius than for 1 mile)

Any help would be greatly appreciated.

Thanks,
Lance.


-------------------------------
SpatialSearchTest.java
-------------------------------
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.spatial.tier.DistanceQueryBuilder;
import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter;
import org.apache.lucene.spatial.tier.projections.IProjector;
import org.apache.lucene.spatial.tier.projections.SinusoidalProjector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.NumericUtils;
import org.junit.Test;

public class SpatialSearchTest {
public static class LuceneHelper {
    private static final String LAT_FIELD = "lat";
    private static final String LON_FIELD = "lon";
    private static final String TIER_PREFIX_FIELD = "_localTier";
    private double maxMiles = 25;
    private double minMiles = 1; // anything lower than 1 mile will just
give tier 15
    // see
http://www.nsshutdown.com/projects/lucene/whitepaper/locallucene_v2.html
    private IProjector projector = new SinusoidalProjector();
    private CartesianTierPlotter ctp0 = new CartesianTierPlotter(0,
projector, TIER_PREFIX_FIELD);
    //startTier is 14 for 25 miles, 15 for 1 miles in lucene 3.0
    private int startTier = ctp0.bestFit(maxMiles);
    private int endTier = ctp0.bestFit(minMiles);
    public void addLocation(Directory dir, String name, double lat, double
lon) throws IOException{
        Document doc = new Document();
        doc.add(new Field("name", name, Field.Store.YES, Index.ANALYZED));
        doc.add(new Field("metafile", "doc", Store.YES, Index.ANALYZED));
        addSpatialLcnFields(lat, lon, doc);
        IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(),
MaxFieldLength.UNLIMITED);
        writer.addDocument(doc);
        writer.commit();
        writer.close();
    }

    private void addSpatialLcnFields(double lat, double lon, Document
document){
        document.add(new Field(LAT_FIELD,
NumericUtils.doubleToPrefixCoded(lat), Field.Store.YES,
Field.Index.NOT_ANALYZED));
        document.add(new Field(LON_FIELD,
NumericUtils.doubleToPrefixCoded(lon), Field.Store.YES,
Field.Index.NOT_ANALYZED));
        for(int tier = startTier ; tier<= endTier; tier++){
            CartesianTierPlotter ctp = new CartesianTierPlotter(tier,
projector, TIER_PREFIX_FIELD);
            double boxId = ctp.getTierBoxId(lat, lon);
            document.add(new Field(ctp.getTierFieldName(),
NumericUtils.doubleToPrefixCoded(boxId), Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));
        }
    }

    public List<String> getNamesWithin(Directory dir, double lat, double
lng, double miles) throws Exception {
        IndexSearcher searcher = new IndexSearcher(dir);
        DistanceQueryBuilder dq = new DistanceQueryBuilder(lat, lng, miles,
LAT_FIELD, LON_FIELD, TIER_PREFIX_FIELD, false, startTier, endTier);
        Query tq = new TermQuery(new Term("metafile", "doc"));
        TopDocs hits = searcher.search(dq.getQuery(tq), Integer.MAX_VALUE);
        List<String> names = new ArrayList<String>();
        for(int i =0; i<hits.scoreDocs.length; i++){
            Document doc = searcher.doc(hits.scoreDocs[i].doc);
            names.add(doc.get("name"));
        }
        return names;
    }
}

    @Test
    public void testTubeStations() throws Exception {
    LuceneHelper sle = new LuceneHelper();
        Directory dir = new RAMDirectory();

        createTubeStations(sle, dir);
        double liverpoolStLat = 51.517598273919;
        double liverpoolStLng = -0.082235212309326;
        for (int i = 1; i < 5; ++ i) {
            List<String> names = sle.getNamesWithin(dir, liverpoolStLat,
liverpoolStLng, i);
        System.out.println(String.format("%s tube stations are %s miles
from liverpool st", names.size(), i));
            System.out.println(names.toString());
        System.out.println("------------------------------");
        }
    }

private void createTubeStations(LuceneHelper helper, Directory dir) throws
Exception {
helper.addLocation(dir, "Abbey Wood (zone 4)",51.49078408041,
0.12028637127604);
helper.addLocation(dir, "Acton (zone 3)",51.516886963398,
-0.26767554257793);
helper.addLocation(dir, "Acton Central (zone 2)",51.508757812012,
-0.26341579231596);
helper.addLocation(dir, "Acton Town (zone 3)",51.503071476856,
-0.2802882961706);
helper.addLocation(dir, "Albany Park (zone 5)",51.435815590189,
0.12645902197803);
helper.addLocation(dir, "Aldgate (zone 1)",51.514342387502,
-0.075612503707184);
helper.addLocation(dir, "Aldgate East (zone 1)",51.515081631079,
-0.072987053548915);
helper.addLocation(dir, "Alexandra Palace (zone 3)",51.598262836895,
-0.1201345367387);
helper.addLocation(dir, "All Saints (zone 2)",51.510476925464,
-0.012610477634);
helper.addLocation(dir, "Alperton (zone 4)",51.541209310632,
-0.2995013414547);
helper.addLocation(dir, "Amersham (zone 9)",51.674129392062,
-0.60649933056891);
helper.addLocation(dir, "Anerley (zone 4)",51.412516725364,
-0.065122723194277);
helper.addLocation(dir, "Angel (zone 1)",51.532968028132,
-0.10556703413728);
helper.addLocation(dir, "Angel Road (zone 4)",51.612420325055,
-0.048718479404686);
helper.addLocation(dir, "Archway (zone 40604)",51.565490550156,
-0.13510715160572);
helper.addLocation(dir, "Arnos Grove (zone 4)",51.616230157665,
-0.13425577761924);
helper.addLocation(dir, "Arsenal (zone 2)",51.558541388156,
-0.10548551071377);
helper.addLocation(dir, "Baker Street (zone 1)",51.523129639184,
-0.15688978273689);
helper.addLocation(dir, "Balham (zone 3)",51.443182580239,
-0.15267077683302);
helper.addLocation(dir, "Bank (zone 1)",51.513347072699,
-0.088985715325045);
helper.addLocation(dir, "Banstead (zone 6)",51.329293148535,
-0.21311798536959);
helper.addLocation(dir, "Barbican (zone 1)",51.520215295016,
-0.097707167852645);
helper.addLocation(dir, "Barking (zone 4)",51.539521102884,
0.0808460268962);
helper.addLocation(dir, "Barkingside (zone 4)",51.585850602534,
0.088491071171579);
helper.addLocation(dir, "Barnehurst (zone 6)",51.464780266606,
0.16096241569889);
helper.addLocation(dir, "Barnes (zone 3)",51.467127801887,
-0.24201866806989);
helper.addLocation(dir, "Barnes Bridge (zone 3)",51.472228083132,
-0.25234822148068);
helper.addLocation(dir, "Barons Court (zone 2)",51.490228707652,
-0.21341574380466);
helper.addLocation(dir, "Battersea Park (zone 2)",51.477318340776,
-0.14810936441775);
helper.addLocation(dir, "Bayswater (zone 1)",51.512111310915,
-0.18788716574986);
helper.addLocation(dir, "Beckenham Hill (zone 4)",51.424626059454,
-0.016481381251057);
helper.addLocation(dir, "Beckenham Junction (zone 4)",51.410941644002,
-0.025687362710869);
helper.addLocation(dir, "Beckton (zone 3)",51.514376621471,
0.061539705886513);
helper.addLocation(dir, "Beckton Park (zone 3)",51.508900786453,
0.054836346093653);
helper.addLocation(dir, "Becontree (zone 5)",51.539585393148,
0.12689470862039);
helper.addLocation(dir, "Bellingham (zone 3)",51.433864895434,
-0.020397386684838);
helper.addLocation(dir, "Belmont (zone 5)",51.344119948481,
-0.19947489773285);
helper.addLocation(dir, "Belsize Park (zone 2)",51.550190897304,
-0.1639600723677);
helper.addLocation(dir, "Belvedere (zone 5)",51.491958983909,
0.15204819376851);
helper.addLocation(dir, "Bermondsey (zone 2)",51.497960787629,
-0.064315686265478);
helper.addLocation(dir, "Berrylands (zone 5)",51.398768439892,
-0.28030710499701);
helper.addLocation(dir, "Bethnal Green (zone 2)",51.527191747482,
-0.055377698622437);
helper.addLocation(dir, "Bethnal Green Rail (zone 2)",51.524282746211,
-0.059999330521283);
helper.addLocation(dir, "Bexley (zone 6)",51.440814511828,
0.14821829873454);
helper.addLocation(dir, "Bexleyheath (zone 5)",51.463549940694,
0.13337735793409);
helper.addLocation(dir, "Bickley (zone 5)",51.400379563229,
0.044318404705676);
helper.addLocation(dir, "Birkbeck (zone 4)",51.403863100681,
-0.0562718615037);
helper.addLocation(dir, "Blackfriars (zone 1)",51.511586939902,
-0.10298097717171);
helper.addLocation(dir, "Blackheath (zone 3)",51.465408009363,
0.0083509882498168);
helper.addLocation(dir, "Blackhorse Road (zone 3)",51.585776631411,
-0.039611280026926);
helper.addLocation(dir, "Blackwall (zone 2)",51.507831540895,
-0.0072207589795153);
helper.addLocation(dir, "Bond Street (zone 1)",51.513797542631,
-0.14959920109132);
helper.addLocation(dir, "Borough (zone 1)",51.501048880447,
-0.094182918403389);
helper.addLocation(dir, "Boston Manor (zone 4)",51.495765574642,
-0.32473278589022);
helper.addLocation(dir, "Bounds Green (zone 40636)",51.607031935983,
-0.12416262739225);
helper.addLocation(dir, "Bow Church (zone 2)",51.527615205643,
-0.020485486059214);
helper.addLocation(dir, "Bow Road (zone 2)",51.527041809222,
-0.024345177705763);
helper.addLocation(dir, "Bowes Park (zone 3,4)",51.607249528898,
-0.11977778086817);
helper.addLocation(dir, "Brent Cross (zone 3)",51.576599240756,
-0.21332141198154);
helper.addLocation(dir, "Brentford (zone 4)",51.487536344613,
-0.30960813639036);
helper.addLocation(dir, "Brimsdown (zone 5)",51.655244617739,
-0.03107782337368);
helper.addLocation(dir, "Brixton (zone 2)",51.462736815606,
-0.11453770490964);
helper.addLocation(dir, "Brockley (zone 2)",51.464749666688,
-0.03773385721419);
helper.addLocation(dir, "Bromley North (zone 4)",51.408942308516,
0.017249827752461);
helper.addLocation(dir, "Bromley South (zone 5)",51.400001286054,
0.017373953488859);
helper.addLocation(dir, "Bromley-by-Bow (zone 2,3)",51.52484020109,
-0.01166796209473);
helper.addLocation(dir, "Brondesbury (zone 2)",51.545262386773,
-0.20282406710345);
helper.addLocation(dir, "Brondesbury Park (zone 2)",51.540325391085,
-0.21045952961905);
helper.addLocation(dir, "Bruce Grove (zone 3)",51.594011254361,
-0.070384555517657);
helper.addLocation(dir, "Buckhurst Hill (zone 5)",51.626576654655,
0.046726985755);
helper.addLocation(dir, "Burnt Oak (zone 4)",51.602551943784,
-0.26431627556888);
helper.addLocation(dir, "Bush Hill Park (zone 5)",51.641481967261,
-0.069265963311165);
helper.addLocation(dir, "Caledonian Road (zone 2)",51.547885455043,
-0.11834644235876);
helper.addLocation(dir, "Caledonian Road & Barnsbury (zone
2)",51.543284589046, -0.11519043865212);
helper.addLocation(dir, "Cambridge Heath (zone 2)",51.532059770708,
-0.05718878628523);
helper.addLocation(dir, "Camden Road (zone 2)",51.541851250779,
-0.13918869492503);
helper.addLocation(dir, "Camden Town (zone 2)",51.539969369251,
-0.14243796405007);
helper.addLocation(dir, "Canada Water (zone 2)",51.498168417556,
-0.05079271714472);
helper.addLocation(dir, "Canary Wharf (zone 2)",51.503578406232,
-0.019452434600173);
helper.addLocation(dir, "Canning Town (zone 3)",51.513870285695,
0.0083200415480822);
helper.addLocation(dir, "Cannon Street (zone 1)",51.511362099463,
-0.090236118885105);
helper.addLocation(dir, "Canonbury (zone 2)",51.548188396024,
-0.092559776199295);
helper.addLocation(dir, "Canons Park (zone 5)",51.607650605221,
-0.29437715826231);
helper.addLocation(dir, "Carpenders Park (zone 7)",51.628186764519,
-0.38581487914664);
helper.addLocation(dir, "Carshalton (zone 5)",51.368426385593,
-0.16638396492825);
helper.addLocation(dir, "Carshalton Beeches (zone 5)",51.357386860957,
-0.16948196651609);
helper.addLocation(dir, "Castle Bar Park (zone 4)",51.522973705473,
-0.33148966489625);
helper.addLocation(dir, "Catford (zone 3)",51.44426491475,
-0.026524111698793);
helper.addLocation(dir, "Catford Bridge (zone 3)",51.444694627575,
-0.024807488912048);
helper.addLocation(dir, "Chadwell Heath (zone 5)",51.568046861857,
0.12891553745986);
helper.addLocation(dir, "Chalfont & Latimer (zone 8)",51.667907547721,
-0.56105332039672);
helper.addLocation(dir, "Chalk Farm (zone 2)",51.544149104848,
-0.15371865256093);
helper.addLocation(dir, "Chancery Lane (zone 1)",51.518494029809,
-0.11194761724718);
helper.addLocation(dir, "Charing Cross (zone 1)",51.508358644804,
-0.12478853109718);
helper.addLocation(dir, "Charlton (zone 3)",51.486834983914,
0.030956045084626);
helper.addLocation(dir, "Cheam (zone 5)",51.355460268652,
-0.21419692461334);
helper.addLocation(dir, "Chelsfield (zone 6)",51.35626456871,
0.10899847900884);
helper.addLocation(dir, "Chesham (zone 9)",51.705380095434,
-0.61141518839627);
helper.addLocation(dir, "Chessington North (zone 6)",51.364243478778,
-0.30046176722378);
helper.addLocation(dir, "Chessington South (zone 6)",51.356704567744,
-0.30707466141954);
helper.addLocation(dir, "Chigwell (zone 4)",51.617857862487,
0.076193656688014);
helper.addLocation(dir, "Chislehurst (zone 5)",51.40559840083,
0.057506196205783);
helper.addLocation(dir, "Chiswick (zone 3)",51.480781526773,
-0.2669989236265);
helper.addLocation(dir, "Chiswick Park (zone 3)",51.494370746332,
-0.26772251965492);
helper.addLocation(dir, "Chorleywood (zone 7)",51.654265989674,
-0.51831947385278);
helper.addLocation(dir, "City Thameslink (zone 1)",51.513935079961,
-0.10360404036727);
helper.addLocation(dir, "Clapham Common (zone 2)",51.4618036863,
-0.13830051012379);
helper.addLocation(dir, "Clapham High Street (zone 2)",51.465469529402,
-0.13245010905033);
helper.addLocation(dir, "Clapham Junction (zone 2)",51.464366804651,
-0.17030060907001);
helper.addLocation(dir, "Clapham North (zone 2)",51.464916230409,
-0.12989566953588);
helper.addLocation(dir, "Clapham South (zone 2,3)",51.452676506748,
-0.1479696801021);
helper.addLocation(dir, "Clapton (zone 2)",51.561569094453,
-0.057475034590784);
helper.addLocation(dir, "Clock House (zone 4)",51.408540565451,
-0.040687716905021);
helper.addLocation(dir, "Cobham & Stoke D'Abernon (zone )",51.31834723919,
-0.38902199845314);
helper.addLocation(dir, "Cockfosters (zone 5)",51.652024496788,
-0.14990225857042);
helper.addLocation(dir, "Colindale (zone 4)",51.595230546294,
-0.25027310932225);
helper.addLocation(dir, "Colliers Wood (zone 3)",51.418759208995,
-0.17740072104762);
helper.addLocation(dir, "Coulsdon South (zone 6)",51.315800960535,
-0.1378887436247);
helper.addLocation(dir, "Covent Garden (zone 1)",51.512760249622,
-0.1244924862088);
helper.addLocation(dir, "Crayford (zone 6)",51.448546734577,
0.17851710444575);
helper.addLocation(dir, "Crews Hill (zone 6)",51.684474623566,
-0.10682963790553);
helper.addLocation(dir, "Crofton Park (zone 3)",51.455179296249,
-0.036532191514461);
helper.addLocation(dir, "Crossharbour & London Arena (zone
2)",51.495839980525, -0.014918409980624);
helper.addLocation(dir, "Crouch Hill (zone 3)",51.571327111387,
-0.11711885796196);
helper.addLocation(dir, "Croxley (zone 7)",51.647005333911,
-0.44158934771671);
helper.addLocation(dir, "Crystal Palace (zone 40636)",51.418170359941,
-0.072592854062748);
helper.addLocation(dir, "Custom House (zone 3)",51.509622053058,
0.025786917726712);
helper.addLocation(dir, "Cutty Sark for Maritime Greenwich (zone
2)",51.481944468688, -0.01056746798363);
helper.addLocation(dir, "Cyprus (zone 3)",51.508526572883,
0.063855162939039);
helper.addLocation(dir, "Dagenham Dock (zone 5)",51.526287178504,
0.14504542671488);
helper.addLocation(dir, "Dagenham East (zone 5)",51.544187318113,
0.16584784999223);
helper.addLocation(dir, "Dagenham Heathway (zone 5)",51.541211772284,
0.14769413756505);
helper.addLocation(dir, "Dalston Kingsland (zone 2)",51.548667827094,
-0.076212502172009);
helper.addLocation(dir, "Dartford (zone )",51.447399615703,
0.21809793611023);
helper.addLocation(dir, "Debden (zone 6)",51.645491990883,
0.083815925291538);
helper.addLocation(dir, "Denmark Hill (zone 2)",51.468200650033,
-0.090973475173744);
helper.addLocation(dir, "Deptford (zone 2)",51.478890086282,
-0.026181921788286);
helper.addLocation(dir, "Deptford Bridge (zone 40604)",51.474476774061,
-0.022038032405853);
helper.addLocation(dir, "Devons Road (zone 2)",51.522258469272,
-0.017993342742124);
helper.addLocation(dir, "Dollis Hill (zone 3)",51.551850619529,
-0.23878334100376);
helper.addLocation(dir, "Drayton Green (zone 4)",51.516004715297,
-0.32959685045955);
helper.addLocation(dir, "Drayton Park (zone 2)",51.553078319423,
-0.10575577858654);
helper.addLocation(dir, "Ealing Broadway (zone 3)",51.51486201146,
-0.30199597251937);
helper.addLocation(dir, "Ealing Common (zone 3)",51.510248690463,
-0.28713701041592);
helper.addLocation(dir, "Earls Court (zone 1,2)",51.491356695274,
-0.19429940765557);
helper.addLocation(dir, "Earlsfield (zone 3)",51.442238829835,
-0.18725830238926);
helper.addLocation(dir, "East Acton (zone 2)",51.516263444214,
-0.2480978154307);
helper.addLocation(dir, "East Croydon (zone 5)",51.37571611266,
-0.091849130629116);
helper.addLocation(dir, "East Dulwich (zone 2)",51.461625592168,
-0.080422179162408);
helper.addLocation(dir, "East Finchley (zone 3)",51.587332564437,
-0.16472945405368);
helper.addLocation(dir, "East Ham (zone 3,4)",51.539246158049,
0.051530710126145);
helper.addLocation(dir, "East India (zone 2,3)",51.508684006054,
-0.0023559243798497);
helper.addLocation(dir, "East Putney (zone 2,3)",51.458879808899,
-0.21098384278422);
helper.addLocation(dir, "Eastcote (zone 5)",51.576551871493,
-0.39680887105797);
helper.addLocation(dir, "Eden Park (zone 5)",51.390796105685,
-0.026655345425249);
helper.addLocation(dir, "Edgware (zone 5)",51.614229655466,
-0.27507922607818);
helper.addLocation(dir, "Edgware Road (Bakerloo) (zone 1)",51.520645381678,
-0.17052514070378);
helper.addLocation(dir, "Edgware Road (Circle/District/H&C) (zone
1)",51.51999806318, -0.1676538436008);
helper.addLocation(dir, "Edmonton Green (zone 4)",51.625115709648,
-0.061624575457523);
helper.addLocation(dir, "Elephant & Castle (zone 1,2)",51.495849394281,
-0.10072431173602);
helper.addLocation(dir, "Elm Park (zone 6)",51.549124559422,
0.19726710182967);
helper.addLocation(dir, "Elmers End (zone 4)",51.398291114164,
-0.049449459806297);
helper.addLocation(dir, "Elmstead Woods (zone 4)",51.417080625514,
0.044243721084371);
helper.addLocation(dir, "Elstree & Borehamwood (zone 6)",51.652875609998,
-0.27981416681958);
helper.addLocation(dir, "Eltham (zone 4)",51.455662213853,
0.052343698204214);
helper.addLocation(dir, "Elverson Road (zone 2,3)",51.468372191483,
-0.016801981736488);
helper.addLocation(dir, "Embankment (zone 1)",51.507312509276,
-0.12235292981979);
helper.addLocation(dir, "Emerson Park (zone 6)",51.569114881318,
0.22023736048149);
helper.addLocation(dir, "Enfield Chase (zone 5)",51.652722121848,
-0.090689752730328);
helper.addLocation(dir, "Enfield Lock (zone 6)",51.670846125012,
-0.02837661157186);
helper.addLocation(dir, "Enfield Town (zone 5)",51.651970081543,
-0.079315469569566);
helper.addLocation(dir, "Epping (zone 6)",51.69368615157, 0.11384001852178);
helper.addLocation(dir, "Epsom Downs (zone 6)",51.323659467583,
-0.23895587775184);
helper.addLocation(dir, "Erith (zone 6)",51.481647653094, 0.17427568781302);
helper.addLocation(dir, "Essex Road (zone 2)",51.540633322162,
-0.096351108662094);
helper.addLocation(dir, "Euston (zone 1)",51.528664346375,
-0.13328205840994);
helper.addLocation(dir, "Euston Square (zone 1)",51.528664346375,
-0.13328205840994);
helper.addLocation(dir, "Ewell East (zone 6)",51.345243905271,
-0.24148864560939);
helper.addLocation(dir, "Ewell West (zone 6)",51.349991173131,
-0.25707477581385);
helper.addLocation(dir, "Fairlop (zone 4)",51.59610953153,
0.090607714208087);
helper.addLocation(dir, "Falconwood (zone 4)",51.459085786225,
0.078524084551238);
helper.addLocation(dir, "Farringdon (zone 1)",51.520195700647,
-0.10482865117184);
helper.addLocation(dir, "Feltham (zone 6)",51.44787922275,
-0.40981009327567);
helper.addLocation(dir, "Fenchurch Street (zone 1)",51.511566715013,
-0.078539744740966);
helper.addLocation(dir, "Finchley Central (zone 4)",51.600903273752,
-0.19320620063466);
helper.addLocation(dir, "Finchley Road (zone 2)",51.547096220268,
-0.18003614128656);
helper.addLocation(dir, "Finchley Road & Frognal (zone 2)",51.550119520279,
-0.18363678247277);
helper.addLocation(dir, "Finsbury Park (zone 2)",51.564635458062,
-0.10586706135916);
helper.addLocation(dir, "Forest Gate (zone 3)",51.54931611531,
0.024203511499168);
helper.addLocation(dir, "Forest Hill (zone 3)",51.439308318386,
-0.053314119078799);
helper.addLocation(dir, "Fulham Broadway (zone 2)",51.480260927016,
-0.19552976561085);
helper.addLocation(dir, "Fulwell (zone 6)",51.433942607741,
-0.34942414136408);
helper.addLocation(dir, "Gallions Reach (zone 3)",51.509034130657,
0.071789801687878);
helper.addLocation(dir, "Gants Hill (zone 4)",51.576552943422,
0.066098526398209);
helper.addLocation(dir, "Gidea Park (zone 6)",51.581865720882,
0.20599141081423);
helper.addLocation(dir, "Gipsy Hill (zone 3)",51.424469532451,
-0.083820786846549);
helper.addLocation(dir, "Gloucester Road (zone 1)",51.494499579725,
-0.18352915689619);
helper.addLocation(dir, "Golders Green (zone 3)",51.572215556655,
-0.19482013198437);
helper.addLocation(dir, "Goldhawk Road (zone 2)",51.502076993967,
-0.22738960127533);
helper.addLocation(dir, "Goodge Street (zone 1)",51.520613125487,
-0.13479327927061);
helper.addLocation(dir, "Goodmayes (zone 4)",51.566180968146,
0.11174407958328);
helper.addLocation(dir, "Gordon Hill (zone 5)",51.663502248565,
-0.09445884360504);
helper.addLocation(dir, "Gospel Oak (zone 2)",51.555405311264,
-0.15128661069808);
helper.addLocation(dir, "Grange Hill (zone 4)",51.613480413753,
0.092286969949084);
helper.addLocation(dir, "Grange Park (zone 5)",51.642623088692,
-0.09729997426098);
helper.addLocation(dir, "Great Portland Street (zone 1)",51.52378881305,
-0.14394701338886);
helper.addLocation(dir, "Green Park (zone 1)",51.506760501463,
-0.14246316907526);
helper.addLocation(dir, "Greenford (zone 4)",51.541980112836,
-0.34586432267848);
helper.addLocation(dir, "Greenwich (zone 40604)",51.477547665535,
-0.014848686252722);
helper.addLocation(dir, "Grove Park (zone 4)",51.430432640396,
0.022612884710894);
helper.addLocation(dir, "Gunnersbury (zone 3)",51.491863444709,
-0.27514973411264);
helper.addLocation(dir, "Hackbridge (zone 4)",51.377860917901,
-0.15386483218978);
helper.addLocation(dir, "Hackney Central (zone 2)",51.547257451286,
-0.055575092639468);
helper.addLocation(dir, "Hackney Downs (zone 2)",51.549078092042,
-0.060170685150219);
helper.addLocation(dir, "Hackney Wick (zone 2)",51.543558409072,
-0.025245084630728);
helper.addLocation(dir, "Hadley Wood (zone 6)",51.668402892286,
-0.17656673195017);
helper.addLocation(dir, "Hainault (zone 4)",51.602845314928,
0.094122987217226);
helper.addLocation(dir, "Hammersmith (District) (zone 2)",51.491819802914,
-0.22284652701972);
helper.addLocation(dir, "Hammersmith (Met.) (zone 2)",51.493483379174,
-0.22462575515926);
helper.addLocation(dir, "Hampstead (zone 2)",51.556542616677,
-0.17800013773286);
helper.addLocation(dir, "Hampstead Heath (zone 3)",51.555199944256,
-0.16455176144825);
helper.addLocation(dir, "Hampton (zone 6)",51.415879597557,
-0.37212087604547);
helper.addLocation(dir, "Hampton Court (zone 6)",51.40229391894,
-0.34274277866957);
helper.addLocation(dir, "Hampton Wick (zone 6)",51.414640080192,
-0.31308923226487);
helper.addLocation(dir, "Hanger Lane (zone 3)",51.530072069094,
-0.29298173181915);
helper.addLocation(dir, "Hanwell (zone 4)",51.512185998837,
-0.33803747641273);
helper.addLocation(dir, "Harlesden (zone 3)",51.536258358843,
-0.25748125850322);
helper.addLocation(dir, "Harold Wood (zone 6)",51.593202188506,
0.2342185071783);
helper.addLocation(dir, "Harringay (zone 3)",51.577357921799,
-0.10519382370901);
helper.addLocation(dir, "Harringay Green Lanes (zone 3)",51.57714590447,
-0.098202962998489);
helper.addLocation(dir, "Harrow & Wealdstone (zone 5)",51.592594673236,
-0.33423825163137);
helper.addLocation(dir, "Harrow-on-the-Hill (zone 5)",51.579388159582,
-0.33698708805734);
helper.addLocation(dir, "Hatch End (zone 6)",51.609828548789,
-0.36916434211502);
helper.addLocation(dir, "Hatton Cross (zone 5,6)",51.466685355642,
-0.42336616986103);
helper.addLocation(dir, "Haydons Road (zone 3)",51.425457340854,
-0.18891497843117);
helper.addLocation(dir, "Hayes (zone 5)",51.37573670506, 0.010157017878448);
helper.addLocation(dir, "Hayes and Harlington (zone 5)",51.50304912563,
-0.42062749859031);
helper.addLocation(dir, "Headstone Lane (zone 5)",51.602499669538,
-0.35689307782418);
helper.addLocation(dir, "Heathrow Terminal 4 (zone 6)",51.45978048411,
-0.44771519861354);
helper.addLocation(dir, "Heathrow Terminals 1 2 3 (zone 6)",51.47128945567,
-0.45239283063262);
helper.addLocation(dir, "Hendon Central (zone 3,4)",51.583133074092,
-0.2267197095034);
helper.addLocation(dir, "Herne Hill (zone 40604)",51.453991381788,
-0.10254851838021);
helper.addLocation(dir, "Heron Quays (zone 2)",51.503386571015,
-0.021939126563571);
helper.addLocation(dir, "High Barnet (zone 5)",51.651688276705,
-0.19415092780429);
helper.addLocation(dir, "High Street Kensington (zone 1)",51.500729468384,
-0.19155165303998);
helper.addLocation(dir, "Highams Park (zone 4)",51.608355993014,
-0.00012084723573169);
helper.addLocation(dir, "Highbury & Islington (zone 2)",51.546495518926,
-0.10406772078143);
helper.addLocation(dir, "Highgate (zone 3)",51.57764663481,
-0.14692043327249);
helper.addLocation(dir, "Hillingdon (zone 6)",51.55377757066,
-0.44988357245777);
helper.addLocation(dir, "Hither Green (zone 3)",51.452401721767,
-0.00095652287067613);
helper.addLocation(dir, "Holborn (zone 1)",51.517235749261,
-0.11982609759457);
helper.addLocation(dir, "Holland Park (zone 2)",51.507146508744,
-0.20654337129402);
helper.addLocation(dir, "Holloway Road (zone 2)",51.55281611672,
-0.11292127587712);
helper.addLocation(dir, "Homerton (zone 2)",51.546595450822,
-0.038497927971748);
helper.addLocation(dir, "Honor Oak Park (zone 3)",51.450648245652,
-0.044138732242293);
helper.addLocation(dir, "Hornchurch (zone 6)",51.554355082156,
0.21894141805997);
helper.addLocation(dir, "Hornsey (zone 3)",51.586474864733,
-0.11180120639571);
helper.addLocation(dir, "Hounslow (zone 5)",51.46250486146,
-0.36178186366717);
helper.addLocation(dir, "Hounslow Central (zone 4)",51.470925810282,
-0.36594373417825);
helper.addLocation(dir, "Hounslow East (zone 4)",51.473707937461,
-0.35526092596841);
helper.addLocation(dir, "Hounslow West (zone 5)",51.473105762632,
-0.38569323300198);
helper.addLocation(dir, "Hyde Park Corner (zone 1)",51.502584030904,
-0.15245970877887);
helper.addLocation(dir, "Ickenham (zone 6)",51.560825107127,
-0.44156508942605);
helper.addLocation(dir, "Ilford (zone 4)",51.559142232556,
0.06869961398625);
helper.addLocation(dir, "Imperial Wharf (zone 2)",51.474938948929,
-0.18282310826897);
helper.addLocation(dir, "Island Gardens (zone 2)",51.487950088882,
-0.010478902499309);
helper.addLocation(dir, "Isleworth (zone 4)",51.475037464523,
-0.33731436875817);
helper.addLocation(dir, "Kenley (zone 6)",51.324600324285,
-0.10120536334161);
helper.addLocation(dir, "Kennington (zone 2)",51.488662470707,
-0.10505621257104);
helper.addLocation(dir, "Kensal Green (zone 2)",51.530524241234,
-0.22469897011847);
helper.addLocation(dir, "Kensal Rise (zone 2)",51.53421509119,
-0.22080656353585);
helper.addLocation(dir, "Kensington (Olympia) (zone 2)",51.497879724483,
-0.21036483866639);
helper.addLocation(dir, "Kent House (zone 4)",51.412717664303,
-0.045801176185629);
helper.addLocation(dir, "Kentish Town (zone 2)",51.550009538423,
-0.14045684366827);
helper.addLocation(dir, "Kentish Town West (zone 2)",51.546547987029,
-0.14674199079293);
helper.addLocation(dir, "Kenton (zone 4)",51.581496322037,
-0.31520243664979);
helper.addLocation(dir, "Kew Bridge (zone 3)",51.49000465091,
-0.28883209363752);
helper.addLocation(dir, "Kew Gardens (zone 3,4)",51.476789170755,
-0.28536661446493);
helper.addLocation(dir, "Kidbrooke (zone 3)",51.462690183933,
0.028314631821257);
helper.addLocation(dir, "Kilburn (zone 2)",51.546944459981,
-0.20461829997264);
helper.addLocation(dir, "Kilburn High Road (zone 2)",51.537267764059,
-0.19109868962017);
helper.addLocation(dir, "Kilburn Park (zone 2)",51.535135560206,
-0.19395164168612);
helper.addLocation(dir, "King George V (zone 3)",51.502008599189,
0.062220618931645);
helper.addLocation(dir, "King's Cross (zone 1)",51.53079820546,
-0.12274200728123);
helper.addLocation(dir, "Kings Cross St. Pancras (zone 1)",51.530312476892,
-0.12385771561154);
helper.addLocation(dir, "Kingsbury (zone 4)",51.584876550714,
-0.27858717715014);
helper.addLocation(dir, "Kingston (zone 6)",51.412641800653,
-0.30112666341862);
helper.addLocation(dir, "Knightsbridge (zone 1)",51.501354916808,
-0.16065008131194);
helper.addLocation(dir, "Knockholt (zone 6)",51.345751922698,
0.13084539482109);
helper.addLocation(dir, "Ladbroke Grove (zone 2)",51.517210698742,
-0.21018376269161);
helper.addLocation(dir, "Ladywell (zone 3)",51.45619213691,
-0.019230010500554);
helper.addLocation(dir, "Lambeth North (zone 1)",51.499129959063,
-0.11175385704735);
helper.addLocation(dir, "Lancaster Gate (zone 1)",51.511890964101,
-0.17541552045722);
helper.addLocation(dir, "Langdon Park (zone 2)",51.518883939693,
-0.015199388573999);
helper.addLocation(dir, "Latimer Road (zone 2)",51.513958124663,
-0.21744525733064);
helper.addLocation(dir, "Lee (zone 3)",51.449458517716, 0.013379080898623);
helper.addLocation(dir, "Leicester Square (zone 1)",51.511291196842,
-0.12822773962177);
helper.addLocation(dir, "Lewisham (zone 40604)",51.464880714235,
-0.012418307529155);
helper.addLocation(dir, "Leyton (zone 3)",51.55813227051,
-0.0064509088011814);
helper.addLocation(dir, "Leyton Midland Road (zone 3)",51.569364239801,
-0.0080519210997184);
helper.addLocation(dir, "Leytonstone (zone 3,4)",51.568522287449,
0.009154878018083);
helper.addLocation(dir, "Leytonstone High Road (zone 3)",51.563807342647,
0.0082688934065806);
helper.addLocation(dir, "Limehouse (zone 2)",51.512312167848,
-0.039365669438682);
helper.addLocation(dir, "Liverpool Street (zone 1)",51.517598273919,
-0.082235212309326);
helper.addLocation(dir, "London Bridge (zone 1)",51.504674357597,
-0.085991192281661);
helper.addLocation(dir, "London City Airport (zone 3)",51.50368965775,
0.047887121033287);
helper.addLocation(dir, "London Fields (zone 2)",51.540718847663,
-0.057685269137809);
helper.addLocation(dir, "Loughborough Junction (zone 2)",51.46667891193,
-0.10248294761392);
helper.addLocation(dir, "Loughton (zone 6)",51.641570470369,
0.055293528321119);
helper.addLocation(dir, "Lower Sydenham (zone 4)",51.424846846074,
-0.033315960742811);
helper.addLocation(dir, "Maida Vale (zone 2)",51.529995078969,
-0.18541823310956);
helper.addLocation(dir, "Malden Manor (zone 4)",51.384609567544,
-0.26110604834896);
helper.addLocation(dir, "Manor House (zone 40604)",51.570747151453,
-0.095670549505162);
helper.addLocation(dir, "Manor Park (zone 3,4)",51.552854343905,
0.045738291167029);
helper.addLocation(dir, "Mansion House (zone 1)",51.512091761163,
-0.094183249527509);
helper.addLocation(dir, "Marble Arch (zone 1)",51.513965510738,
-0.15855680746603);
helper.addLocation(dir, "Maryland (zone 3)",51.545668269809,
0.0056960730233714);
helper.addLocation(dir, "Marylebone (zone 1)",51.522396687994,
-0.16347815242029);
helper.addLocation(dir, "Maze Hill (zone 3)",51.483013655604,
0.0032192958995991);
helper.addLocation(dir, "Mile End (zone 2)",51.525310973905,
-0.032651671918221);
helper.addLocation(dir, "Mill Hill Broadway (zone 4)",51.612871158046,
-0.24952262850911);
helper.addLocation(dir, "Mill Hill East (zone 4)",51.608316669912,
-0.20988127429344);
helper.addLocation(dir, "Mitcham Eastfields (zone 3)",51.408383928225,
-0.15398734320935);
helper.addLocation(dir, "Mitcham Junction (zone 4)",51.39304258672,
-0.15742227287945);
helper.addLocation(dir, "Monument (zone 1)",51.510630425959,
-0.086173905918798);
helper.addLocation(dir, "Moor Park (zone 6,7)",51.629930718133,
-0.4328985822977);
helper.addLocation(dir, "Moorgate (zone 1)",51.518437149414,
-0.08900327764505);
helper.addLocation(dir, "Morden (zone 4)",51.402185984981,
-0.19483760810466);
helper.addLocation(dir, "Morden South (zone 4)",51.396307721608,
-0.20028719027858);
helper.addLocation(dir, "Mornington Crescent (zone 2)",51.534362233874,
-0.1387299346061);
helper.addLocation(dir, "Mortlake (zone 3)",51.468167968359,
-0.26718891965297);
helper.addLocation(dir, "Motspur Park (zone 4)",51.395319655441,
-0.23942537454861);
helper.addLocation(dir, "Mottingham (zone 4)",51.439824969906,
0.050338587672779);
helper.addLocation(dir, "Mudchute (zone 2)",51.491236186648,
-0.014945543221677);
helper.addLocation(dir, "Neasden (zone 3)",51.554627747213,
-0.25010062378951);
helper.addLocation(dir, "New Barnet (zone 5)",51.648536790554,
-0.17295526264108);
helper.addLocation(dir, "New Beckenham (zone 4)",51.41670555246,
-0.035290571074268);
helper.addLocation(dir, "New Cross (zone 2)",51.476429418617,
-0.032264414494673);
helper.addLocation(dir, "New Cross Gate (zone 2)",51.475264932486,
-0.039514655295107);
helper.addLocation(dir, "New Eltham (zone 4)",51.437690651019,
0.070459003212279);
helper.addLocation(dir, "New Malden (zone 4)",51.403555937615,
-0.25620373217155);
helper.addLocation(dir, "New Southgate (zone 4)",51.614093683634,
-0.14299533557942);
helper.addLocation(dir, "Newbury Park (zone 4)",51.575638344309,
0.090317586010402);
helper.addLocation(dir, "Norbiton (zone 5)",51.411909385349,
-0.28418557131983);
helper.addLocation(dir, "Norbury (zone 3)",51.411188517406,
-0.12278502535626);
helper.addLocation(dir, "North Acton (zone 2,3)",51.523432458806,
-0.25971511616691);
helper.addLocation(dir, "North Dulwich (zone 40604)",51.454481818931,
-0.087904290624922);
helper.addLocation(dir, "North Ealing (zone 3)",51.517622323819,
-0.28897914280262);
helper.addLocation(dir, "North Greenwich (zone 2,3)",51.500255151591,
0.0036006636371896);
helper.addLocation(dir, "North Harrow (zone 5)",51.584631342978,
-0.3626185623764);
helper.addLocation(dir, "North Sheen (zone 3)",51.465419645874,
-0.28638307337002);
helper.addLocation(dir, "North Wembley (zone 4)",51.562396328364,
-0.30393379535805);
helper.addLocation(dir, "Northfields (zone 3)",51.500491708619,
-0.31505041439224);
helper.addLocation(dir, "Northolt (zone 5)",51.548212945697,
-0.36842617615208);
helper.addLocation(dir, "Northolt Park (zone 5)",51.557619094925,
-0.35941977403748);
helper.addLocation(dir, "Northwick Park (zone 4)",51.5785087266,
-0.31818496289702);
helper.addLocation(dir, "Northwood (zone 6)",51.611213662308,
-0.42382334746562);
helper.addLocation(dir, "Northwood Hills (zone 6)",51.600802695129,
-0.40929692189409);
helper.addLocation(dir, "Norwood Junction (zone 4)",51.396954330829,
-0.075195484483074);
helper.addLocation(dir, "Notting Hill Gate (zone 1,2)",51.509375359878,
-0.1959072111467);
helper.addLocation(dir, "Nunhead (zone 2)",51.466579990247,
-0.053665348737765);
helper.addLocation(dir, "Oakleigh Park (zone 4)",51.637676382963,
-0.16618051866214);
helper.addLocation(dir, "Oakwood (zone 5)",51.64763797617,
-0.1318390886991);
helper.addLocation(dir, "Old Street (zone 1)",51.525581481862,
-0.087608545343845);
helper.addLocation(dir, "Orpington (zone 6)",51.373520035814,
0.089043266168332);
helper.addLocation(dir, "Osterley (zone 4)",51.481216852781,
-0.3520816978192);
helper.addLocation(dir, "Oval (zone 2)",51.481412613811, -0.11330667730935);
helper.addLocation(dir, "Oxford Circus (zone 1)",51.515223419245,
-0.14082176208955);
helper.addLocation(dir, "Paddington (zone 1)",51.515393806532,
-0.17572234283505);
helper.addLocation(dir, "Palmers Green (zone 4)",51.618786761028,
-0.11025805805573);
helper.addLocation(dir, "Park Royal (zone 3)",51.526834054645,
-0.28491450496891);
helper.addLocation(dir, "Parsons Green (zone 2)",51.474960176772,
-0.20111009589714);
helper.addLocation(dir, "Peckham Rye (zone 2)",51.469511372801,
-0.069969158361951);
helper.addLocation(dir, "Penge East (zone 4)",51.41997535513,
-0.054480885538245);
helper.addLocation(dir, "Penge West (zone 4)",51.418062935027,
-0.060631385884983);
helper.addLocation(dir, "Perivale (zone 4)",51.536341860358,
-0.32305600630537);
helper.addLocation(dir, "Petts Wood (zone 5)",51.388598981243,
0.074494399194959);
helper.addLocation(dir, "Piccadilly Circus (zone 1)",51.509696764476,
-0.13369718974012);
helper.addLocation(dir, "Pimlico (zone 1)",51.489552877924,
-0.1330938573102);
helper.addLocation(dir, "Pinner (zone 5)",51.592361724428,
-0.38120935690424);
helper.addLocation(dir, "Plaistow (zone 3)",51.531288332324,
0.017795056275962);
helper.addLocation(dir, "Plumstead (zone 4)",51.489792413595,
0.084314017745385);
helper.addLocation(dir, "Ponders End (zone 5)",51.642730695,
-0.034510654933282);
helper.addLocation(dir, "Pontoon Dock (zone 3)",51.502216211037,
0.033340112607835);
helper.addLocation(dir, "Poplar (zone 2)",51.507588072081,
-0.017261086484836);
helper.addLocation(dir, "Preston Road (zone 4)",51.572103763883,
-0.29495758553154);
helper.addLocation(dir, "Prince Regent (zone 3)",51.509434545079,
0.033502981448267);
helper.addLocation(dir, "Pudding Mill Lane (zone 2,3)",51.53432785535,
-0.012754096692901);
helper.addLocation(dir, "Purley (zone 6)",51.337363567516,
-0.11359916443804);
helper.addLocation(dir, "Purley Oaks (zone 6)",51.346989351539,
-0.098800976652713);
helper.addLocation(dir, "Putney (zone 2,3)",51.460952556568,
-0.21658898147399);
helper.addLocation(dir, "Putney Bridge (zone 2)",51.467865362703,
-0.20935102262327);
helper.addLocation(dir, "Queens Park (zone 2)",51.534312675201,
-0.20478373421795);
helper.addLocation(dir, "Queens Road Peckham (zone 2)",51.474284715779,
-0.057340582526957);
helper.addLocation(dir, "Queensbury (zone 4)",51.593883010111,
-0.28631716346916);
helper.addLocation(dir, "Queenstown Road (zone 2)",51.47495914471,
-0.14734091559888);
helper.addLocation(dir, "Queensway (zone 1)",51.510449255439,
-0.18740549543317);
helper.addLocation(dir, "Radlett (zone )",51.685413310275,
-0.31797317069656);
helper.addLocation(dir, "Rainham (zone 6)",51.517340491331,
0.19070638530502);
helper.addLocation(dir, "Ravensbourne (zone 4)",51.413870378956,
-0.0069234381730423);
helper.addLocation(dir, "Ravenscourt Park (zone 2)",51.494068008984,
-0.23595483065011);
helper.addLocation(dir, "Rayners Lane (zone 5)",51.575396777398,
-0.371046385824);
helper.addLocation(dir, "Raynes Park (zone 4)",51.409375373186,
-0.22989856350727);
helper.addLocation(dir, "Rectory Road (zone 2)",51.558763484573,
-0.068371241749211);
helper.addLocation(dir, "Redbridge (zone 4)",51.576366911264,
0.045408472505876);
helper.addLocation(dir, "Reedham (zone 6)",51.331441727656,
-0.12338827286968);
helper.addLocation(dir, "Regents Park (zone 1)",51.52381069054,
-0.14532999904559);
helper.addLocation(dir, "Richmond (zone 4)",51.463232922347,
-0.30172474133933);
helper.addLocation(dir, "Rickmansworth (zone 7)",51.640323072212,
-0.47367013575456);
helper.addLocation(dir, "Riddlesdown (zone 6)",51.332674842588,
-0.099479315537562);
helper.addLocation(dir, "Roding Valley (zone 4)",51.616956440142,
0.044040648415103);
helper.addLocation(dir, "Romford (zone 6)",51.574641568849,
0.18306970022131);
helper.addLocation(dir, "Rotherhithe (zone 2)",51.501594510808,
-0.052951891484305);
helper.addLocation(dir, "Royal Albert (zone 3)",51.508493863562,
0.045191552169371);
helper.addLocation(dir, "Royal Oak (zone 2)",51.518294375269,
-0.18880926348942);
helper.addLocation(dir, "Royal Victoria (zone 3)",51.509055232332,
0.017979819853408);
helper.addLocation(dir, "Ruislip (zone 6)",51.57216197222,
-0.42122049909957);
helper.addLocation(dir, "Ruislip Gardens (zone 5)",51.559960227907,
-0.40927968814014);
helper.addLocation(dir, "Ruislip Manor (zone 6)",51.573451624726,
-0.41283492710738);
helper.addLocation(dir, "Russell Square (zone 1)",51.523013052867,
-0.12457578611157);
helper.addLocation(dir, "Sanderstead (zone 6)",51.34824626461,
-0.093694143249397);
helper.addLocation(dir, "Selhurst (zone 4)",51.39218578041,
-0.089884666539009);
helper.addLocation(dir, "Seven Kings (zone 4)",51.563993339397,
0.096333999350604);
helper.addLocation(dir, "Seven Sisters (zone 3)",51.583362168372,
-0.0724523920649);
helper.addLocation(dir, "Shadwell (zone 2)",51.51130016173,
-0.056904799137598);
helper.addLocation(dir, "Shepherds Bush (zone 2)",51.50453217729,
-0.21850475368199);
helper.addLocation(dir, "Shepherds Bush Market (zone 2)",51.505880735504,
-0.22738608723774);
helper.addLocation(dir, "Shoreditch (zone 2)",51.522709102713,
-0.070906418527321);
helper.addLocation(dir, "Shortlands (zone 4)",51.40560236593,
0.0027819191560382);
helper.addLocation(dir, "Sidcup (zone 5)",51.43439844437, 0.10332974285774);
helper.addLocation(dir, "Silver Street (zone 4)",51.615242486372,
-0.072575300701906);
helper.addLocation(dir, "Slade Green (zone 6)",51.467747631244,
0.19053278174752);
helper.addLocation(dir, "Sloane Square (zone 1)",51.492359782932,
-0.1564744555002);
helper.addLocation(dir, "Smitham (zone 6)",51.322452969178,
-0.13433270854947);
helper.addLocation(dir, "Snaresbrook (zone 4)",51.580891270601,
0.021478357761873);
helper.addLocation(dir, "South Acton (zone 3)",51.499685861011,
-0.27020080333496);
helper.addLocation(dir, "South Bermondsey (zone 2)",51.487676621549,
-0.054740420692279);
helper.addLocation(dir, "South Croydon (zone 5)",51.362750208796,
-0.092503001948904);
helper.addLocation(dir, "South Ealing (zone 3)",51.501644057917,
-0.30702584019952);
helper.addLocation(dir, "South Hampstead (zone 2)",51.541476868984,
-0.1783567825076);
helper.addLocation(dir, "South Harrow (zone 5)",51.564680211138,
-0.35187954635816);
helper.addLocation(dir, "South Kensington (zone 1)",51.494071386411,
-0.17390862058942);
helper.addLocation(dir, "South Kenton (zone 4)",51.571044486824,
-0.30812855062663);
helper.addLocation(dir, "South Merton (zone 4)",51.403240579864,
-0.20553592740103);
helper.addLocation(dir, "South Quay (zone 2)",51.500863608239,
-0.018446287979256);
helper.addLocation(dir, "South Ruislip (zone 5)",51.55689035096,
-0.39910148824501);
helper.addLocation(dir, "South Tottenham (zone 3)",51.580402594532,
-0.071841526783666);
helper.addLocation(dir, "South Wimbledon (zone 40636)",51.41536073293,
-0.19196016848772);
helper.addLocation(dir, "South Woodford (zone 4)",51.591552612383,
0.027957511681624);
helper.addLocation(dir, "Southall (zone 4)",51.505956957579,
-0.37869678379695);
helper.addLocation(dir, "Southbury (zone 5)",51.648433731335,
-0.052968859157203);
helper.addLocation(dir, "Southfields (zone 3)",51.444883338258,
-0.20659499856664);
helper.addLocation(dir, "Southgate (zone 4)",51.63237586338,
-0.12775560097809);
helper.addLocation(dir, "Southwark (zone 1)",51.503853632869,
-0.10578053394541);
helper.addLocation(dir, "St Helier (zone 4)",51.389912187517,
-0.19900022218424);
helper.addLocation(dir, "St James Street (zone 3)",51.580608667586,
-0.032790131848525);
helper.addLocation(dir, "St Johns (zone 2)",51.468975297065,
-0.023226267171585);
helper.addLocation(dir, "St Margarets (zone 4)",51.455206030249,
-0.32130985776381);
helper.addLocation(dir, "St Mary Cray (zone 6)",51.394759394244,
0.10723227089692);
helper.addLocation(dir, "St Pancras (zone 1)",51.530554416571,
-0.12549136793246);
helper.addLocation(dir, "St. James's Park (zone 1)",51.499609810342,
-0.13386435110426);
helper.addLocation(dir, "St. Johns Wood (zone 2)",51.534854431713,
-0.17405042505482);
helper.addLocation(dir, "St. Pauls (zone 1)",51.51483530739,
-0.097556591574387);
helper.addLocation(dir, "Stamford Brook (zone 2)",51.494449997347,
-0.24523190696758);
helper.addLocation(dir, "Stamford Hill (zone 3)",51.574447612615,
-0.076653913978365);
helper.addLocation(dir, "Stanmore (zone 5)",51.6196734807,
-0.30308485086488);
helper.addLocation(dir, "Stepney Green (zone 2)",51.521995838874,
-0.047368111957746);
helper.addLocation(dir, "Stockwell (zone 2)",51.472159270341,
-0.12283190859196);
helper.addLocation(dir, "Stoke Newington (zone 2)",51.564637618307,
-0.072320969849242);
helper.addLocation(dir, "Stonebridge Park (zone 3)",51.54398658738,
-0.27538602336732);
helper.addLocation(dir, "Stoneleigh (zone 5)",51.363364082259,
-0.248695295654);
helper.addLocation(dir, "Stratford (zone 3)",51.541692579295,
-0.0037372234417709);
helper.addLocation(dir, "Stratford International (zone 3)",51.54480853536,
-0.0087640154463654);
helper.addLocation(dir, "Strawberry Hill (zone 5)",51.439747873261,
-0.33960334587097);
helper.addLocation(dir, "Streatham (zone 3)",51.425845878375,
-0.13231111566835);
helper.addLocation(dir, "Streatham Common (zone 3)",51.418984686908,
-0.13571178617484);
helper.addLocation(dir, "Streatham Hill (zone 3)",51.438460380547,
-0.1276670964405);
helper.addLocation(dir, "Sudbury & Harrow Road (zone 4)",51.554493821699,
-0.31591182033013);
helper.addLocation(dir, "Sudbury Hill (zone 4)",51.557339600086,
-0.33637769283987);
helper.addLocation(dir, "Sudbury Hill Harrow (zone 4)",51.558342313079,
-0.33543227050831);
helper.addLocation(dir, "Sudbury Town (zone 4)",51.551397480891,
-0.31632906529511);
helper.addLocation(dir, "Sundridge Park (zone 4)",51.413393796204,
0.020379486210958);
helper.addLocation(dir, "Surbiton (zone 6)",51.392599569913,
-0.3043701893312);
helper.addLocation(dir, "Surrey Quays (zone 2)",51.493266862158,
-0.047515585346921);
helper.addLocation(dir, "Sutton (zone 5)",51.359506158142,
-0.19128765090448);
helper.addLocation(dir, "Sutton Common (zone 4)",51.375554718505,
-0.19690554710689);
helper.addLocation(dir, "Swiss Cottage (zone 2)",51.543034867714,
-0.17561218648329);
helper.addLocation(dir, "Sydenham (zone 3)",51.427341258001,
-0.055074289357489);
helper.addLocation(dir, "Sydenham Hill (zone 3)",51.432575896828,
-0.080215824663043);
helper.addLocation(dir, "Syon Lane (zone 4)",51.481474727333,
-0.32648063620347);
helper.addLocation(dir, "Teddington (zone 6)",51.424497537357,
-0.3326909565597);
helper.addLocation(dir, "Temple (zone 1)",51.51104062071,
-0.11371134239066);
helper.addLocation(dir, "Thames Ditton (zone 6)",51.388616113023,
-0.33827846842909);
helper.addLocation(dir, "Theydon Bois (zone 6)",51.672552069981,
0.10290519530392);
helper.addLocation(dir, "Thornton Heath (zone 4)",51.398481089859,
-0.10041879260042);
helper.addLocation(dir, "Tolworth (zone 5)",51.376843349784,
-0.27960574939507);
helper.addLocation(dir, "Tooting (zone 3)",51.419896651766,
-0.16098809293112);
helper.addLocation(dir, "Tooting Bec (zone 3)",51.435838083172,
-0.15968610811001);
helper.addLocation(dir, "Tooting Broadway (zone 3)",51.42704916499,
-0.16867014599257);
helper.addLocation(dir, "Tottenham Court Road (zone 1)",51.51621088565,
-0.13109602942553);
helper.addLocation(dir, "Tottenham Hale (zone 3)",51.587997785049,
-0.060173390466137);
helper.addLocation(dir, "Totteridge & Whetstone (zone 4)",51.63024674119,
-0.17933981753571);
helper.addLocation(dir, "Tower Gateway (zone 1)",51.510392650922,
-0.074395469530797);
helper.addLocation(dir, "Tower Hill (zone 1)",51.510394282129,
-0.076686790760475);
helper.addLocation(dir, "Tufnell Park (zone 2)",51.556440814333,
-0.13772775294192);
helper.addLocation(dir, "Tulse Hill (zone 3)",51.4397974399,
-0.10510812362275);
helper.addLocation(dir, "Turkey Street (zone 6)",51.672653666247,
-0.047215472250329);
helper.addLocation(dir, "Turnham Green (zone 2)",51.495181971972,
-0.25451016527384);
helper.addLocation(dir, "Turnpike Lane (zone 3)",51.590358146027,
-0.1027906082273);
helper.addLocation(dir, "Twickenham (zone 5)",51.450250987135,
-0.32884583782433);
helper.addLocation(dir, "Upminster (zone 6)",51.558763325208,
0.2514152239117);
helper.addLocation(dir, "Upminster Bridge (zone 6)",51.557718771685,
0.23455631120919);
helper.addLocation(dir, "Upney (zone 4)",51.538405634701, 0.10154616057314);
helper.addLocation(dir, "Upper Holloway (zone 2)",51.563623319983,
-0.12909493917319);
helper.addLocation(dir, "Upper Warlingham (zone 6)",51.308772263619,
-0.077467317417935);
helper.addLocation(dir, "Upton Park (zone 3)",51.536628195871,
0.034556255633226);
helper.addLocation(dir, "Uxbridge (zone 6)",51.546454564696,
-0.47708714109832);
helper.addLocation(dir, "Vauxhall (zone 1,2)",51.485735816391,
-0.12381555294752);
helper.addLocation(dir, "Victoria (zone 1)",51.496423969876,
-0.14390630306143);
helper.addLocation(dir, "Waddon (zone 5)",51.367379270921,
-0.11737971383443);
helper.addLocation(dir, "Wallington (zone 5)",51.360331562347,
-0.15084947457103);
helper.addLocation(dir, "Walthamstow Central (zone 3)",51.583018115291,
-0.019926114372123);
helper.addLocation(dir, "Walthamstow Queens Road (zone 3)",51.581546193899,
-0.0238295131434);
helper.addLocation(dir, "Wandsworth Common (zone 3)",51.446365623898,
-0.16352259346247);
helper.addLocation(dir, "Wandsworth Road (zone 2)",51.470223218762,
-0.13902328072857);
helper.addLocation(dir, "Wandsworth Town (zone 2)",51.461034098277,
-0.18789564563536);
helper.addLocation(dir, "Wanstead (zone 4)",51.574902145755,
0.028774900468403);
helper.addLocation(dir, "Wanstead Park (zone 3)",51.551778074703,
0.026404363778733);
helper.addLocation(dir, "Wapping (zone 2)",51.504340322706,
-0.055846408737992);
helper.addLocation(dir, "Warren Street (zone 1)",51.524580005085,
-0.13826391949985);
helper.addLocation(dir, "Warwick Avenue (zone 2)",51.523104457076,
-0.18293888140664);
helper.addLocation(dir, "Waterloo (zone 1)",51.503146653078,
-0.11324484659974);
helper.addLocation(dir, "Watford (zone 7)",51.657605146891,
-0.41725555293253);
helper.addLocation(dir, "Welling (zone 4)",51.464777075182,
0.10178943179171);
helper.addLocation(dir, "Wembley Central (zone 4)",51.551864816194,
-0.29637790641578);
helper.addLocation(dir, "Wembley Park (zone 4)",51.563322491915,
-0.27922812839087);
helper.addLocation(dir, "Wembley Stadium (zone 4)",51.554654605186,
-0.28603202522583);
helper.addLocation(dir, "West Acton (zone 3)",51.517770184208,
-0.28064276561988);
helper.addLocation(dir, "West Brompton (zone 2)",51.487328938205,
-0.19552441152812);
helper.addLocation(dir, "West Croydon (zone 5)",51.378552186111,
-0.1020199266263);
helper.addLocation(dir, "West Drayton (zone 6)",51.510071275994,
-0.47216168972777);
helper.addLocation(dir, "West Dulwich (zone 3)",51.440911831895,
-0.090658290563767);
helper.addLocation(dir, "West Ealing (zone 3)",51.513625243955,
-0.31976854613702);
helper.addLocation(dir, "West Finchley (zone 4)",51.609262750488,
-0.1889026706526);
helper.addLocation(dir, "West Ham (zone 3)",51.52852551818,
0.0053318072586749);
helper.addLocation(dir, "West Hampstead (zone 2)",51.547474356007,
-0.19111216622603);
helper.addLocation(dir, "West Hampstead Thameslink (zone
2)",51.548629145744, -0.19252310000093);
helper.addLocation(dir, "West Harrow (zone 5)",51.578924280955,
-0.35383226807134);
helper.addLocation(dir, "West India Quay (zone 2)",51.506762659668,
-0.020568040587805);
helper.addLocation(dir, "West Kensington (zone 2)",51.490109387233,
-0.20618929345907);
helper.addLocation(dir, "West Norwood (zone 3)",51.431241127782,
-0.10317475212492);
helper.addLocation(dir, "West Ruislip (zone 6)",51.569587924657,
-0.43784571956141);
helper.addLocation(dir, "West Silvertown (zone 3)",51.502884431544,
0.022260451989289);
helper.addLocation(dir, "West Sutton (zone 5)",51.366150159758,
-0.20463018612991);
helper.addLocation(dir, "West Wickham (zone 5)",51.381284202527,
-0.014561963270977);
helper.addLocation(dir, "Westbourne Park (zone 2)",51.520988865484,
-0.20086810419124);
helper.addLocation(dir, "Westcombe Park (zone 3)",51.484508893293,
0.017760099794534);
helper.addLocation(dir, "Westferry (zone 2)",51.509638150617,
-0.026308729670621);
helper.addLocation(dir, "Westminster (zone 1)",51.501401606172,
-0.12498767440679);
helper.addLocation(dir, "White City (zone 2)",51.512232464701,
-0.22461752326457);
helper.addLocation(dir, "White Hart Lane (zone 3)",51.605034779059,
-0.07085588920127);
helper.addLocation(dir, "Whitechapel (zone 2)",51.519587792346,
-0.059406074587337);
helper.addLocation(dir, "Whitton (zone 5)",51.449588234079,
-0.35766767257282);
helper.addLocation(dir, "Whyteleafe (zone 6)",51.309929327757,
-0.081120820529126);
helper.addLocation(dir, "Whyteleafe South (zone 6)",51.30348981231,
-0.076698171894698);
helper.addLocation(dir, "Willesden Green (zone 2,3)",51.549373313232,
-0.22239318421442);
helper.addLocation(dir, "Willesden Junction (zone 3)",51.532233992929,
-0.2438947288224);
helper.addLocation(dir, "Wimbledon (zone 3)",51.421107869794,
-0.20664845638008);
helper.addLocation(dir, "Wimbledon Chase (zone 3)",51.409530957999,
-0.21407539384331);
helper.addLocation(dir, "Wimbledon Park (zone 3)",51.434580976538,
-0.19917189150183);
helper.addLocation(dir, "Winchmore Hill (zone 4)",51.633886871044,
-0.10090248655044);
helper.addLocation(dir, "Wood Green (zone 3)",51.597453741251,
-0.10951215426353);
helper.addLocation(dir, "Wood Street (zone 4)",51.586669943719,
-0.0019394662016431);
helper.addLocation(dir, "Woodford (zone 4)",51.607201839663,
0.034070640659794);
helper.addLocation(dir, "Woodgrange Park (zone 3,4)",51.549052529247,
0.044586916011772);
helper.addLocation(dir, "Woodmansterne (zone 6)",51.319018597795,
-0.154247780889);
helper.addLocation(dir, "Woodside Park (zone 4)",51.617868422141,
-0.185411063095);
helper.addLocation(dir, "Woolwich Arsenal (zone 4)",51.489907107526,
0.069208307647642);
helper.addLocation(dir, "Woolwich Dockyard (zone 3)",51.491107787563,
0.054626749936269);
helper.addLocation(dir, "Worcester Park (zone 4)",51.381104516868,
-0.24556092484593);
}
}

Re: Spatial Search

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
Lance Java wrote
> 
> Hi, I'm trying to keep this a lucene only project rather than bring in
> solr
> which, as I understand, needs to run in a separate web container. I'd like
> to use a single webapp for my project as I'm unsure of the implications of
> hosting such a project on the cloud.
> 

By the way, Solr does not need to run in a separate web container; it is
merely a recommendation for larger installations.  Simply deploy it as a
web-app; Solr's WAR is ready and waiting.  And if you're hung up on that
(which you shouldn't be), Solr can be embedded.  IMO very few projects would
be better served working with Lucene directly instead of Solr (or Solr's
Lucene based competitors).

~ David Smiley

-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3625962.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
Amir,

CachedDistanceValueSource is indeed poorly named; I need to get renaming it
on the TODO list; I've identified this before.  Calculating the distance is
computationally cheap enough to calculate for the X number of results
(top-20-ish) you are returning in your search results to not bother trying
to cache it, although I don't rule out caching it at some point.

On timing... know that the Lucene spatial module was committed in ~March,
and there has been steady work lately on various components involved
(Spatial4j, Lucene spatial module, Solr adapters).  I *really* want to get
this nailed down for Lucene/Solr 4.  There is a big difference between
simply having working code (that is only partially tested but seems to
work), and addressing documentation, full testing, and consensus on the API
between interested parties (e.g. Chris, Ryan, and me.).  The last bit,
consensus, is what bogs things down, in my experience.

Specifically about the 1/distance thing... not sure when that'll happen,
maybe in a couple weeks.  Maybe.  I created a JIRA issue so you can start
watching it to be notified of progress:
https://issues.apache.org/jira/browse/LUCENE-4208

~ David

-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3994211.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by Amir <am...@snappify.co>.
Thanks heaps for the quick reply David... 
Computing the distance on the client is not an issue, however I was
wondering as you are already computing the distances, there is any caching
mechanism that I could retrieve the computed values. I looked into
CachedDistanceValueSource class etc, but apparently there are for caching
shapes. 

I reckon 1/distance makes much more sense specially when combining geo query
with other queries. Do you mind if I ask when do you plan to apply this
change? I'm using your library in the production environment :D so I'm super
interested in the updates.

Another question is sorting, do you have any tips for sorting?

--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3994049.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
Amir,
  The geo query's score happens to be the distance but I don't expect that
to remain so.  I plan for it to be 1/distance which is a better relevancy
value -- a "score" is supposed to be about relevancy after all.  If you want
to get the distance for a search result, I recommend calculating it on the
client.  It's not hard; you can find code samples for the Haversine
algorithm all over the web.  I want to eventually add a Solr function that
can return the distance in the search results, and even pre-filter the
values by the query shape -- useful for multi-value geo.

~ David

-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3993925.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by amir <am...@snappify.co>.
Hi David,
I'm implementing a project using your RecursivePrefixTreeStrategy and it
works fine when I'm only querying 
based on the geo field as I can sort and can get the distance from the score
of the results. However I couldn't figure out how to sort and get the
distance when I combine the geoquery with another query through
booleanquery. I do really appreciate if you could give me a little help to
get the distance value and sort the items based on their distance....

Amir


--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3993824.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
I have a couple comments on your code after briefly looking through it.

* If you want to work with miles, initialize SimpleSpatialContext with
DistanceUnits.MILES.  I see you chose KM but your leading statistics are in
miles.  Perhaps that is the reason for the discrepency in your numbers.
* You are not supposed to instantiate Shape instances directly, the spatial
context is a factory for them.  It will also do some important argument
normalization (e.g. ensuring lat-lon is within proper boundaries).
* You are initializing GeohashPrefixTree using the maximum detail possible
(roughly double precision).  I suspect you don't actually need that level of
accuracy.  Look at SpatialPrefixTreeStrategy.initMaxLevels() for code that
chooses a value based on a target fraction of your chosen units (e.g.
miles).  If you want to hard-code a specific value only good for geohashes,
you could alternatively look up a value in a table of precision on geohashes
on wikipedia.

Keep in mind that LSP is subject to change at will; it hasn't been
officially released yet.  The remaining issues I see for a first release are
enumerated here: 
http://code.google.com/p/lucene-spatial-playground/wiki/Tasks  The "Extras /
demo related" part arguably doesn't count.

~ David Smiley

-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3629480.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by Lance Java <la...@googlemail.com>.
Hi David, thanks for the pointers... I was able to get a working test case
with your pride and joy!

Here are the results with RecursivePrefixTreeStrategy
14 tube stations are 1 miles from liverpool st
31 tube stations are 2 miles from liverpool st
58 tube stations are 3 miles from liverpool st
98 tube stations are 4 miles from liverpool st

Compared with the results using
http://www.java-community.de/archives/156-Spatial-search-with-Lucene.html<http://www.java-community.de/archives/156-Spatial-search-with-Lucene.htmlto>
20 tube stations are 1 miles from liverpool st
47 tube stations are 2 miles from liverpool st
92 tube stations are 3 miles from liverpool st
138 tube stations are 4 miles from liverpool st

There are some slight differences in the numbers which I might take a look
at if I get some time

Here is the code for anyone interested:

===============


import java.io.IOException;
import java.util.List;

import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.spatial.SpatialMatchConcern;
import org.apache.lucene.spatial.base.context.SpatialContext;
import org.apache.lucene.spatial.base.context.simple.SimpleSpatialContext;
import org.apache.lucene.spatial.base.prefix.geohash.GeohashPrefixTree;
import org.apache.lucene.spatial.base.query.SpatialArgs;
import org.apache.lucene.spatial.base.query.SpatialOperation;
import org.apache.lucene.spatial.base.shape.Circle;
import org.apache.lucene.spatial.base.shape.Point;
import org.apache.lucene.spatial.base.shape.Shape;
import org.apache.lucene.spatial.base.shape.simple.CircleImpl;
import org.apache.lucene.spatial.base.shape.simple.PointImpl;
import org.apache.lucene.spatial.strategy.SimpleSpatialFieldInfo;
import org.apache.lucene.spatial.strategy.SpatialStrategy;
import
org.apache.lucene.spatial.strategy.prefix.RecursivePrefixTreeStrategy;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import org.junit.Test;
import org.testng.collections.Lists;

public class SpatialSearchTest3 {
    public static class LuceneHelper {
        private SimpleSpatialFieldInfo fieldInfo = new
SimpleSpatialFieldInfo(getClass().getSimpleName());
        private boolean storeShape = true;
        private SpatialContext spatialContext = SimpleSpatialContext.GEO_KM;
        private int maxLength = GeohashPrefixTree.getMaxLevelsPossible();
        private SpatialStrategy<SimpleSpatialFieldInfo> strategy = new
RecursivePrefixTreeStrategy(new GeohashPrefixTree(spatialContext, maxLength
));
        private Version TEST_VERSION_CURRENT = Version.LUCENE_40;
        private int maxDocs = 1000;

        public void addLocation(Directory dir, String name, double lat,
double lng) throws IOException {
            Document doc = new Document();
            doc.add(new Field("name", name, StringField.TYPE_STORED));
            //doc.add(new Field("metafile", "doc",
StringField.TYPE_STORED));
            Shape shape = new PointImpl(lat, lng);
            for (IndexableField f : strategy.createFields(fieldInfo, shape,
true, storeShape)) {
                if (f != null) { // null if incompatibleGeometry && ignore
                    doc.add(f);
                }
            }
            IndexWriterConfig writerConfig = new
IndexWriterConfig(TEST_VERSION_CURRENT, new
WhitespaceAnalyzer(TEST_VERSION_CURRENT));
            IndexWriter writer = new IndexWriter(dir, writerConfig);
            writer.addDocument(doc);
            writer.commit();
            writer.close();
        }

        public List<String> getNamesWithin(Directory dir, double lat,
double lng, double kms) throws Exception {
            //SpatialMatchConcern concern = SpatialMatchConcern.FILTER;
            Point point = new PointImpl(lat, lng);
            Circle circle = new CircleImpl(point, kms, spatialContext);
            SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin,
circle);
            Query query = strategy.makeQuery(args, fieldInfo);
            IndexReader reader = IndexReader.open(dir);
            IndexSearcher searcher = new IndexSearcher(reader);
            TopDocs topDocs = searcher.search(query, maxDocs);
            List<String> names = Lists.newArrayList();
            for (int i = 0; i < topDocs.scoreDocs.length; i++) {
                ScoreDoc scoreDoc = topDocs.scoreDocs[i];
                Document doc = searcher.doc(scoreDoc.doc);
                names.add(doc.get("name"));
            }
            return names;
        }
    }

    @Test
    public void testTubeStations() throws Exception {
        LuceneHelper sle = new LuceneHelper();
        Directory dir = new RAMDirectory();

        createTubeStations(sle, dir);
        double liverpoolStLat = 51.517598273919;
        double liverpoolStLng = -0.082235212309326;
        for (int i = 1; i < 5; ++i) {
            double kms = i * 1.609344;
            List<String> names = sle.getNamesWithin(dir, liverpoolStLat,
liverpoolStLng, kms);
            System.out.println(String.format("%s tube stations are %s miles
from liverpool st", names.size(), i));
            //System.out.println(names.toString());
            System.out.println("------------------------------");
        }
    }

    private void createTubeStations(LuceneHelper helper, Directory dir)
throws Exception {
        helper.addLocation(dir, "Abbey Wood (zone 4)", 51.49078408041,
0.12028637127604);
        helper.addLocation(dir, "Acton (zone 3)", 51.516886963398,
-0.26767554257793);
        helper.addLocation(dir, "Acton Central (zone 2)", 51.508757812012,
-0.26341579231596);
        helper.addLocation(dir, "Acton Town (zone 3)", 51.503071476856,
-0.2802882961706);
        helper.addLocation(dir, "Albany Park (zone 5)", 51.435815590189,
0.12645902197803);
        helper.addLocation(dir, "Aldgate (zone 1)", 51.514342387502,
-0.075612503707184);
        helper.addLocation(dir, "Aldgate East (zone 1)", 51.515081631079,
-0.072987053548915);
        helper.addLocation(dir, "Alexandra Palace (zone 3)",
51.598262836895, -0.1201345367387);
        helper.addLocation(dir, "All Saints (zone 2)", 51.510476925464,
-0.012610477634);
        helper.addLocation(dir, "Alperton (zone 4)", 51.541209310632,
-0.2995013414547);
        helper.addLocation(dir, "Amersham (zone 9)", 51.674129392062,
-0.60649933056891);
        helper.addLocation(dir, "Anerley (zone 4)", 51.412516725364,
-0.065122723194277);
        helper.addLocation(dir, "Angel (zone 1)", 51.532968028132,
-0.10556703413728);
        helper.addLocation(dir, "Angel Road (zone 4)", 51.612420325055,
-0.048718479404686);
        helper.addLocation(dir, "Archway (zone 40604)", 51.565490550156,
-0.13510715160572);
        helper.addLocation(dir, "Arnos Grove (zone 4)", 51.616230157665,
-0.13425577761924);
        helper.addLocation(dir, "Arsenal (zone 2)", 51.558541388156,
-0.10548551071377);
        helper.addLocation(dir, "Baker Street (zone 1)", 51.523129639184,
-0.15688978273689);
        helper.addLocation(dir, "Balham (zone 3)", 51.443182580239,
-0.15267077683302);
        helper.addLocation(dir, "Bank (zone 1)", 51.513347072699,
-0.088985715325045);
        helper.addLocation(dir, "Banstead (zone 6)", 51.329293148535,
-0.21311798536959);
        helper.addLocation(dir, "Barbican (zone 1)", 51.520215295016,
-0.097707167852645);
        helper.addLocation(dir, "Barking (zone 4)", 51.539521102884,
0.0808460268962);
        helper.addLocation(dir, "Barkingside (zone 4)", 51.585850602534,
0.088491071171579);
        helper.addLocation(dir, "Barnehurst (zone 6)", 51.464780266606,
0.16096241569889);
        helper.addLocation(dir, "Barnes (zone 3)", 51.467127801887,
-0.24201866806989);
        helper.addLocation(dir, "Barnes Bridge (zone 3)", 51.472228083132,
-0.25234822148068);
        helper.addLocation(dir, "Barons Court (zone 2)", 51.490228707652,
-0.21341574380466);
        helper.addLocation(dir, "Battersea Park (zone 2)", 51.477318340776,
-0.14810936441775);
        helper.addLocation(dir, "Bayswater (zone 1)", 51.512111310915,
-0.18788716574986);
        helper.addLocation(dir, "Beckenham Hill (zone 4)", 51.424626059454,
-0.016481381251057);
        helper.addLocation(dir, "Beckenham Junction (zone 4)",
51.410941644002, -0.025687362710869);
        helper.addLocation(dir, "Beckton (zone 3)", 51.514376621471,
0.061539705886513);
        helper.addLocation(dir, "Beckton Park (zone 3)", 51.508900786453,
0.054836346093653);
        helper.addLocation(dir, "Becontree (zone 5)", 51.539585393148,
0.12689470862039);
        helper.addLocation(dir, "Bellingham (zone 3)", 51.433864895434,
-0.020397386684838);
        helper.addLocation(dir, "Belmont (zone 5)", 51.344119948481,
-0.19947489773285);
        helper.addLocation(dir, "Belsize Park (zone 2)", 51.550190897304,
-0.1639600723677);
        helper.addLocation(dir, "Belvedere (zone 5)", 51.491958983909,
0.15204819376851);
        helper.addLocation(dir, "Bermondsey (zone 2)", 51.497960787629,
-0.064315686265478);
        helper.addLocation(dir, "Berrylands (zone 5)", 51.398768439892,
-0.28030710499701);
        helper.addLocation(dir, "Bethnal Green (zone 2)", 51.527191747482,
-0.055377698622437);
        helper.addLocation(dir, "Bethnal Green Rail (zone 2)",
51.524282746211, -0.059999330521283);
        helper.addLocation(dir, "Bexley (zone 6)", 51.440814511828,
0.14821829873454);
        helper.addLocation(dir, "Bexleyheath (zone 5)", 51.463549940694,
0.13337735793409);
        helper.addLocation(dir, "Bickley (zone 5)", 51.400379563229,
0.044318404705676);
        helper.addLocation(dir, "Birkbeck (zone 4)", 51.403863100681,
-0.0562718615037);
        helper.addLocation(dir, "Blackfriars (zone 1)", 51.511586939902,
-0.10298097717171);
        helper.addLocation(dir, "Blackheath (zone 3)", 51.465408009363,
0.0083509882498168);
        helper.addLocation(dir, "Blackhorse Road (zone 3)",
51.585776631411, -0.039611280026926);
        helper.addLocation(dir, "Blackwall (zone 2)", 51.507831540895,
-0.0072207589795153);
        helper.addLocation(dir, "Bond Street (zone 1)", 51.513797542631,
-0.14959920109132);
        helper.addLocation(dir, "Borough (zone 1)", 51.501048880447,
-0.094182918403389);
        helper.addLocation(dir, "Boston Manor (zone 4)", 51.495765574642,
-0.32473278589022);
        helper.addLocation(dir, "Bounds Green (zone 40636)",
51.607031935983, -0.12416262739225);
        helper.addLocation(dir, "Bow Church (zone 2)", 51.527615205643,
-0.020485486059214);
        helper.addLocation(dir, "Bow Road (zone 2)", 51.527041809222,
-0.024345177705763);
        helper.addLocation(dir, "Bowes Park (zone 3,4)", 51.607249528898,
-0.11977778086817);
        helper.addLocation(dir, "Brent Cross (zone 3)", 51.576599240756,
-0.21332141198154);
        helper.addLocation(dir, "Brentford (zone 4)", 51.487536344613,
-0.30960813639036);
        helper.addLocation(dir, "Brimsdown (zone 5)", 51.655244617739,
-0.03107782337368);
        helper.addLocation(dir, "Brixton (zone 2)", 51.462736815606,
-0.11453770490964);
        helper.addLocation(dir, "Brockley (zone 2)", 51.464749666688,
-0.03773385721419);
        helper.addLocation(dir, "Bromley North (zone 4)", 51.408942308516,
0.017249827752461);
        helper.addLocation(dir, "Bromley South (zone 5)", 51.400001286054,
0.017373953488859);
        helper.addLocation(dir, "Bromley-by-Bow (zone 2,3)",
51.52484020109, -0.01166796209473);
        helper.addLocation(dir, "Brondesbury (zone 2)", 51.545262386773,
-0.20282406710345);
        helper.addLocation(dir, "Brondesbury Park (zone 2)",
51.540325391085, -0.21045952961905);
        helper.addLocation(dir, "Bruce Grove (zone 3)", 51.594011254361,
-0.070384555517657);
        helper.addLocation(dir, "Buckhurst Hill (zone 5)", 51.626576654655,
0.046726985755);
        helper.addLocation(dir, "Burnt Oak (zone 4)", 51.602551943784,
-0.26431627556888);
        helper.addLocation(dir, "Bush Hill Park (zone 5)", 51.641481967261,
-0.069265963311165);
        helper.addLocation(dir, "Caledonian Road (zone 2)",
51.547885455043, -0.11834644235876);
        helper.addLocation(dir, "Caledonian Road & Barnsbury (zone 2)",
51.543284589046, -0.11519043865212);
        helper.addLocation(dir, "Cambridge Heath (zone 2)",
51.532059770708, -0.05718878628523);
        helper.addLocation(dir, "Camden Road (zone 2)", 51.541851250779,
-0.13918869492503);
        helper.addLocation(dir, "Camden Town (zone 2)", 51.539969369251,
-0.14243796405007);
        helper.addLocation(dir, "Canada Water (zone 2)", 51.498168417556,
-0.05079271714472);
        helper.addLocation(dir, "Canary Wharf (zone 2)", 51.503578406232,
-0.019452434600173);
        helper.addLocation(dir, "Canning Town (zone 3)", 51.513870285695,
0.0083200415480822);
        helper.addLocation(dir, "Cannon Street (zone 1)", 51.511362099463,
-0.090236118885105);
        helper.addLocation(dir, "Canonbury (zone 2)", 51.548188396024,
-0.092559776199295);
        helper.addLocation(dir, "Canons Park (zone 5)", 51.607650605221,
-0.29437715826231);
        helper.addLocation(dir, "Carpenders Park (zone 7)",
51.628186764519, -0.38581487914664);
        helper.addLocation(dir, "Carshalton (zone 5)", 51.368426385593,
-0.16638396492825);
        helper.addLocation(dir, "Carshalton Beeches (zone 5)",
51.357386860957, -0.16948196651609);
        helper.addLocation(dir, "Castle Bar Park (zone 4)",
51.522973705473, -0.33148966489625);
        helper.addLocation(dir, "Catford (zone 3)", 51.44426491475,
-0.026524111698793);
        helper.addLocation(dir, "Catford Bridge (zone 3)", 51.444694627575,
-0.024807488912048);
        helper.addLocation(dir, "Chadwell Heath (zone 5)", 51.568046861857,
0.12891553745986);
        helper.addLocation(dir, "Chalfont & Latimer (zone 8)",
51.667907547721, -0.56105332039672);
        helper.addLocation(dir, "Chalk Farm (zone 2)", 51.544149104848,
-0.15371865256093);
        helper.addLocation(dir, "Chancery Lane (zone 1)", 51.518494029809,
-0.11194761724718);
        helper.addLocation(dir, "Charing Cross (zone 1)", 51.508358644804,
-0.12478853109718);
        helper.addLocation(dir, "Charlton (zone 3)", 51.486834983914,
0.030956045084626);
        helper.addLocation(dir, "Cheam (zone 5)", 51.355460268652,
-0.21419692461334);
        helper.addLocation(dir, "Chelsfield (zone 6)", 51.35626456871,
0.10899847900884);
        helper.addLocation(dir, "Chesham (zone 9)", 51.705380095434,
-0.61141518839627);
        helper.addLocation(dir, "Chessington North (zone 6)",
51.364243478778, -0.30046176722378);
        helper.addLocation(dir, "Chessington South (zone 6)",
51.356704567744, -0.30707466141954);
        helper.addLocation(dir, "Chigwell (zone 4)", 51.617857862487,
0.076193656688014);
        helper.addLocation(dir, "Chislehurst (zone 5)", 51.40559840083,
0.057506196205783);
        helper.addLocation(dir, "Chiswick (zone 3)", 51.480781526773,
-0.2669989236265);
        helper.addLocation(dir, "Chiswick Park (zone 3)", 51.494370746332,
-0.26772251965492);
        helper.addLocation(dir, "Chorleywood (zone 7)", 51.654265989674,
-0.51831947385278);
        helper.addLocation(dir, "City Thameslink (zone 1)",
51.513935079961, -0.10360404036727);
        helper.addLocation(dir, "Clapham Common (zone 2)", 51.4618036863,
-0.13830051012379);
        helper.addLocation(dir, "Clapham High Street (zone 2)",
51.465469529402, -0.13245010905033);
        helper.addLocation(dir, "Clapham Junction (zone 2)",
51.464366804651, -0.17030060907001);
        helper.addLocation(dir, "Clapham North (zone 2)", 51.464916230409,
-0.12989566953588);
        helper.addLocation(dir, "Clapham South (zone 2,3)",
51.452676506748, -0.1479696801021);
        helper.addLocation(dir, "Clapton (zone 2)", 51.561569094453,
-0.057475034590784);
        helper.addLocation(dir, "Clock House (zone 4)", 51.408540565451,
-0.040687716905021);
        helper.addLocation(dir, "Cobham & Stoke D'Abernon (zone )",
51.31834723919, -0.38902199845314);
        helper.addLocation(dir, "Cockfosters (zone 5)", 51.652024496788,
-0.14990225857042);
        helper.addLocation(dir, "Colindale (zone 4)", 51.595230546294,
-0.25027310932225);
        helper.addLocation(dir, "Colliers Wood (zone 3)", 51.418759208995,
-0.17740072104762);
        helper.addLocation(dir, "Coulsdon South (zone 6)", 51.315800960535,
-0.1378887436247);
        helper.addLocation(dir, "Covent Garden (zone 1)", 51.512760249622,
-0.1244924862088);
        helper.addLocation(dir, "Crayford (zone 6)", 51.448546734577,
0.17851710444575);
        helper.addLocation(dir, "Crews Hill (zone 6)", 51.684474623566,
-0.10682963790553);
        helper.addLocation(dir, "Crofton Park (zone 3)", 51.455179296249,
-0.036532191514461);
        helper.addLocation(dir, "Crossharbour & London Arena (zone 2)",
51.495839980525, -0.014918409980624);
        helper.addLocation(dir, "Crouch Hill (zone 3)", 51.571327111387,
-0.11711885796196);
        helper.addLocation(dir, "Croxley (zone 7)", 51.647005333911,
-0.44158934771671);
        helper.addLocation(dir, "Crystal Palace (zone 40636)",
51.418170359941, -0.072592854062748);
        helper.addLocation(dir, "Custom House (zone 3)", 51.509622053058,
0.025786917726712);
        helper.addLocation(dir, "Cutty Sark for Maritime Greenwich (zone
2)", 51.481944468688, -0.01056746798363);
        helper.addLocation(dir, "Cyprus (zone 3)", 51.508526572883,
0.063855162939039);
        helper.addLocation(dir, "Dagenham Dock (zone 5)", 51.526287178504,
0.14504542671488);
        helper.addLocation(dir, "Dagenham East (zone 5)", 51.544187318113,
0.16584784999223);
        helper.addLocation(dir, "Dagenham Heathway (zone 5)",
51.541211772284, 0.14769413756505);
        helper.addLocation(dir, "Dalston Kingsland (zone 2)",
51.548667827094, -0.076212502172009);
        helper.addLocation(dir, "Dartford (zone )", 51.447399615703,
0.21809793611023);
        helper.addLocation(dir, "Debden (zone 6)", 51.645491990883,
0.083815925291538);
        helper.addLocation(dir, "Denmark Hill (zone 2)", 51.468200650033,
-0.090973475173744);
        helper.addLocation(dir, "Deptford (zone 2)", 51.478890086282,
-0.026181921788286);
        helper.addLocation(dir, "Deptford Bridge (zone 40604)",
51.474476774061, -0.022038032405853);
        helper.addLocation(dir, "Devons Road (zone 2)", 51.522258469272,
-0.017993342742124);
        helper.addLocation(dir, "Dollis Hill (zone 3)", 51.551850619529,
-0.23878334100376);
        helper.addLocation(dir, "Drayton Green (zone 4)", 51.516004715297,
-0.32959685045955);
        helper.addLocation(dir, "Drayton Park (zone 2)", 51.553078319423,
-0.10575577858654);
        helper.addLocation(dir, "Ealing Broadway (zone 3)", 51.51486201146,
-0.30199597251937);
        helper.addLocation(dir, "Ealing Common (zone 3)", 51.510248690463,
-0.28713701041592);
        helper.addLocation(dir, "Earls Court (zone 1,2)", 51.491356695274,
-0.19429940765557);
        helper.addLocation(dir, "Earlsfield (zone 3)", 51.442238829835,
-0.18725830238926);
        helper.addLocation(dir, "East Acton (zone 2)", 51.516263444214,
-0.2480978154307);
        helper.addLocation(dir, "East Croydon (zone 5)", 51.37571611266,
-0.091849130629116);
        helper.addLocation(dir, "East Dulwich (zone 2)", 51.461625592168,
-0.080422179162408);
        helper.addLocation(dir, "East Finchley (zone 3)", 51.587332564437,
-0.16472945405368);
        helper.addLocation(dir, "East Ham (zone 3,4)", 51.539246158049,
0.051530710126145);
        helper.addLocation(dir, "East India (zone 2,3)", 51.508684006054,
-0.0023559243798497);
        helper.addLocation(dir, "East Putney (zone 2,3)", 51.458879808899,
-0.21098384278422);
        helper.addLocation(dir, "Eastcote (zone 5)", 51.576551871493,
-0.39680887105797);
        helper.addLocation(dir, "Eden Park (zone 5)", 51.390796105685,
-0.026655345425249);
        helper.addLocation(dir, "Edgware (zone 5)", 51.614229655466,
-0.27507922607818);
        helper.addLocation(dir, "Edgware Road (Bakerloo) (zone 1)",
51.520645381678, -0.17052514070378);
        helper.addLocation(dir, "Edgware Road (Circle/District/H&C) (zone
1)", 51.51999806318, -0.1676538436008);
        helper.addLocation(dir, "Edmonton Green (zone 4)", 51.625115709648,
-0.061624575457523);
        helper.addLocation(dir, "Elephant & Castle (zone 1,2)",
51.495849394281, -0.10072431173602);
        helper.addLocation(dir, "Elm Park (zone 6)", 51.549124559422,
0.19726710182967);
        helper.addLocation(dir, "Elmers End (zone 4)", 51.398291114164,
-0.049449459806297);
        helper.addLocation(dir, "Elmstead Woods (zone 4)", 51.417080625514,
0.044243721084371);
        helper.addLocation(dir, "Elstree & Borehamwood (zone 6)",
51.652875609998, -0.27981416681958);
        helper.addLocation(dir, "Eltham (zone 4)", 51.455662213853,
0.052343698204214);
        helper.addLocation(dir, "Elverson Road (zone 2,3)",
51.468372191483, -0.016801981736488);
        helper.addLocation(dir, "Embankment (zone 1)", 51.507312509276,
-0.12235292981979);
        helper.addLocation(dir, "Emerson Park (zone 6)", 51.569114881318,
0.22023736048149);
        helper.addLocation(dir, "Enfield Chase (zone 5)", 51.652722121848,
-0.090689752730328);
        helper.addLocation(dir, "Enfield Lock (zone 6)", 51.670846125012,
-0.02837661157186);
        helper.addLocation(dir, "Enfield Town (zone 5)", 51.651970081543,
-0.079315469569566);
        helper.addLocation(dir, "Epping (zone 6)", 51.69368615157,
0.11384001852178);
        helper.addLocation(dir, "Epsom Downs (zone 6)", 51.323659467583,
-0.23895587775184);
        helper.addLocation(dir, "Erith (zone 6)", 51.481647653094,
0.17427568781302);
        helper.addLocation(dir, "Essex Road (zone 2)", 51.540633322162,
-0.096351108662094);
        helper.addLocation(dir, "Euston (zone 1)", 51.528664346375,
-0.13328205840994);
        helper.addLocation(dir, "Euston Square (zone 1)", 51.528664346375,
-0.13328205840994);
        helper.addLocation(dir, "Ewell East (zone 6)", 51.345243905271,
-0.24148864560939);
        helper.addLocation(dir, "Ewell West (zone 6)", 51.349991173131,
-0.25707477581385);
        helper.addLocation(dir, "Fairlop (zone 4)", 51.59610953153,
0.090607714208087);
        helper.addLocation(dir, "Falconwood (zone 4)", 51.459085786225,
0.078524084551238);
        helper.addLocation(dir, "Farringdon (zone 1)", 51.520195700647,
-0.10482865117184);
        helper.addLocation(dir, "Feltham (zone 6)", 51.44787922275,
-0.40981009327567);
        helper.addLocation(dir, "Fenchurch Street (zone 1)",
51.511566715013, -0.078539744740966);
        helper.addLocation(dir, "Finchley Central (zone 4)",
51.600903273752, -0.19320620063466);
        helper.addLocation(dir, "Finchley Road (zone 2)", 51.547096220268,
-0.18003614128656);
        helper.addLocation(dir, "Finchley Road & Frognal (zone 2)",
51.550119520279, -0.18363678247277);
        helper.addLocation(dir, "Finsbury Park (zone 2)", 51.564635458062,
-0.10586706135916);
        helper.addLocation(dir, "Forest Gate (zone 3)", 51.54931611531,
0.024203511499168);
        helper.addLocation(dir, "Forest Hill (zone 3)", 51.439308318386,
-0.053314119078799);
        helper.addLocation(dir, "Fulham Broadway (zone 2)",
51.480260927016, -0.19552976561085);
        helper.addLocation(dir, "Fulwell (zone 6)", 51.433942607741,
-0.34942414136408);
        helper.addLocation(dir, "Gallions Reach (zone 3)", 51.509034130657,
0.071789801687878);
        helper.addLocation(dir, "Gants Hill (zone 4)", 51.576552943422,
0.066098526398209);
        helper.addLocation(dir, "Gidea Park (zone 6)", 51.581865720882,
0.20599141081423);
        helper.addLocation(dir, "Gipsy Hill (zone 3)", 51.424469532451,
-0.083820786846549);
        helper.addLocation(dir, "Gloucester Road (zone 1)",
51.494499579725, -0.18352915689619);
        helper.addLocation(dir, "Golders Green (zone 3)", 51.572215556655,
-0.19482013198437);
        helper.addLocation(dir, "Goldhawk Road (zone 2)", 51.502076993967,
-0.22738960127533);
        helper.addLocation(dir, "Goodge Street (zone 1)", 51.520613125487,
-0.13479327927061);
        helper.addLocation(dir, "Goodmayes (zone 4)", 51.566180968146,
0.11174407958328);
        helper.addLocation(dir, "Gordon Hill (zone 5)", 51.663502248565,
-0.09445884360504);
        helper.addLocation(dir, "Gospel Oak (zone 2)", 51.555405311264,
-0.15128661069808);
        helper.addLocation(dir, "Grange Hill (zone 4)", 51.613480413753,
0.092286969949084);
        helper.addLocation(dir, "Grange Park (zone 5)", 51.642623088692,
-0.09729997426098);
        helper.addLocation(dir, "Great Portland Street (zone 1)",
51.52378881305, -0.14394701338886);
        helper.addLocation(dir, "Green Park (zone 1)", 51.506760501463,
-0.14246316907526);
        helper.addLocation(dir, "Greenford (zone 4)", 51.541980112836,
-0.34586432267848);
        helper.addLocation(dir, "Greenwich (zone 40604)", 51.477547665535,
-0.014848686252722);
        helper.addLocation(dir, "Grove Park (zone 4)", 51.430432640396,
0.022612884710894);
        helper.addLocation(dir, "Gunnersbury (zone 3)", 51.491863444709,
-0.27514973411264);
        helper.addLocation(dir, "Hackbridge (zone 4)", 51.377860917901,
-0.15386483218978);
        helper.addLocation(dir, "Hackney Central (zone 2)",
51.547257451286, -0.055575092639468);
        helper.addLocation(dir, "Hackney Downs (zone 2)", 51.549078092042,
-0.060170685150219);
        helper.addLocation(dir, "Hackney Wick (zone 2)", 51.543558409072,
-0.025245084630728);
        helper.addLocation(dir, "Hadley Wood (zone 6)", 51.668402892286,
-0.17656673195017);
        helper.addLocation(dir, "Hainault (zone 4)", 51.602845314928,
0.094122987217226);
        helper.addLocation(dir, "Hammersmith (District) (zone 2)",
51.491819802914, -0.22284652701972);
        helper.addLocation(dir, "Hammersmith (Met.) (zone 2)",
51.493483379174, -0.22462575515926);
        helper.addLocation(dir, "Hampstead (zone 2)", 51.556542616677,
-0.17800013773286);
        helper.addLocation(dir, "Hampstead Heath (zone 3)",
51.555199944256, -0.16455176144825);
        helper.addLocation(dir, "Hampton (zone 6)", 51.415879597557,
-0.37212087604547);
        helper.addLocation(dir, "Hampton Court (zone 6)", 51.40229391894,
-0.34274277866957);
        helper.addLocation(dir, "Hampton Wick (zone 6)", 51.414640080192,
-0.31308923226487);
        helper.addLocation(dir, "Hanger Lane (zone 3)", 51.530072069094,
-0.29298173181915);
        helper.addLocation(dir, "Hanwell (zone 4)", 51.512185998837,
-0.33803747641273);
        helper.addLocation(dir, "Harlesden (zone 3)", 51.536258358843,
-0.25748125850322);
        helper.addLocation(dir, "Harold Wood (zone 6)", 51.593202188506,
0.2342185071783);
        helper.addLocation(dir, "Harringay (zone 3)", 51.577357921799,
-0.10519382370901);
        helper.addLocation(dir, "Harringay Green Lanes (zone 3)",
51.57714590447, -0.098202962998489);
        helper.addLocation(dir, "Harrow & Wealdstone (zone 5)",
51.592594673236, -0.33423825163137);
        helper.addLocation(dir, "Harrow-on-the-Hill (zone 5)",
51.579388159582, -0.33698708805734);
        helper.addLocation(dir, "Hatch End (zone 6)", 51.609828548789,
-0.36916434211502);
        helper.addLocation(dir, "Hatton Cross (zone 5,6)", 51.466685355642,
-0.42336616986103);
        helper.addLocation(dir, "Haydons Road (zone 3)", 51.425457340854,
-0.18891497843117);
        helper.addLocation(dir, "Hayes (zone 5)", 51.37573670506,
0.010157017878448);
        helper.addLocation(dir, "Hayes and Harlington (zone 5)",
51.50304912563, -0.42062749859031);
        helper.addLocation(dir, "Headstone Lane (zone 5)", 51.602499669538,
-0.35689307782418);
        helper.addLocation(dir, "Heathrow Terminal 4 (zone 6)",
51.45978048411, -0.44771519861354);
        helper.addLocation(dir, "Heathrow Terminals 1 2 3 (zone 6)",
51.47128945567, -0.45239283063262);
        helper.addLocation(dir, "Hendon Central (zone 3,4)",
51.583133074092, -0.2267197095034);
        helper.addLocation(dir, "Herne Hill (zone 40604)", 51.453991381788,
-0.10254851838021);
        helper.addLocation(dir, "Heron Quays (zone 2)", 51.503386571015,
-0.021939126563571);
        helper.addLocation(dir, "High Barnet (zone 5)", 51.651688276705,
-0.19415092780429);
        helper.addLocation(dir, "High Street Kensington (zone 1)",
51.500729468384, -0.19155165303998);
        helper.addLocation(dir, "Highams Park (zone 4)", 51.608355993014,
-0.00012084723573169);
        helper.addLocation(dir, "Highbury & Islington (zone 2)",
51.546495518926, -0.10406772078143);
        helper.addLocation(dir, "Highgate (zone 3)", 51.57764663481,
-0.14692043327249);
        helper.addLocation(dir, "Hillingdon (zone 6)", 51.55377757066,
-0.44988357245777);
        helper.addLocation(dir, "Hither Green (zone 3)", 51.452401721767,
-0.00095652287067613);
        helper.addLocation(dir, "Holborn (zone 1)", 51.517235749261,
-0.11982609759457);
        helper.addLocation(dir, "Holland Park (zone 2)", 51.507146508744,
-0.20654337129402);
        helper.addLocation(dir, "Holloway Road (zone 2)", 51.55281611672,
-0.11292127587712);
        helper.addLocation(dir, "Homerton (zone 2)", 51.546595450822,
-0.038497927971748);
        helper.addLocation(dir, "Honor Oak Park (zone 3)", 51.450648245652,
-0.044138732242293);
        helper.addLocation(dir, "Hornchurch (zone 6)", 51.554355082156,
0.21894141805997);
        helper.addLocation(dir, "Hornsey (zone 3)", 51.586474864733,
-0.11180120639571);
        helper.addLocation(dir, "Hounslow (zone 5)", 51.46250486146,
-0.36178186366717);
        helper.addLocation(dir, "Hounslow Central (zone 4)",
51.470925810282, -0.36594373417825);
        helper.addLocation(dir, "Hounslow East (zone 4)", 51.473707937461,
-0.35526092596841);
        helper.addLocation(dir, "Hounslow West (zone 5)", 51.473105762632,
-0.38569323300198);
        helper.addLocation(dir, "Hyde Park Corner (zone 1)",
51.502584030904, -0.15245970877887);
        helper.addLocation(dir, "Ickenham (zone 6)", 51.560825107127,
-0.44156508942605);
        helper.addLocation(dir, "Ilford (zone 4)", 51.559142232556,
0.06869961398625);
        helper.addLocation(dir, "Imperial Wharf (zone 2)", 51.474938948929,
-0.18282310826897);
        helper.addLocation(dir, "Island Gardens (zone 2)", 51.487950088882,
-0.010478902499309);
        helper.addLocation(dir, "Isleworth (zone 4)", 51.475037464523,
-0.33731436875817);
        helper.addLocation(dir, "Kenley (zone 6)", 51.324600324285,
-0.10120536334161);
        helper.addLocation(dir, "Kennington (zone 2)", 51.488662470707,
-0.10505621257104);
        helper.addLocation(dir, "Kensal Green (zone 2)", 51.530524241234,
-0.22469897011847);
        helper.addLocation(dir, "Kensal Rise (zone 2)", 51.53421509119,
-0.22080656353585);
        helper.addLocation(dir, "Kensington (Olympia) (zone 2)",
51.497879724483, -0.21036483866639);
        helper.addLocation(dir, "Kent House (zone 4)", 51.412717664303,
-0.045801176185629);
        helper.addLocation(dir, "Kentish Town (zone 2)", 51.550009538423,
-0.14045684366827);
        helper.addLocation(dir, "Kentish Town West (zone 2)",
51.546547987029, -0.14674199079293);
        helper.addLocation(dir, "Kenton (zone 4)", 51.581496322037,
-0.31520243664979);
        helper.addLocation(dir, "Kew Bridge (zone 3)", 51.49000465091,
-0.28883209363752);
        helper.addLocation(dir, "Kew Gardens (zone 3,4)", 51.476789170755,
-0.28536661446493);
        helper.addLocation(dir, "Kidbrooke (zone 3)", 51.462690183933,
0.028314631821257);
        helper.addLocation(dir, "Kilburn (zone 2)", 51.546944459981,
-0.20461829997264);
        helper.addLocation(dir, "Kilburn High Road (zone 2)",
51.537267764059, -0.19109868962017);
        helper.addLocation(dir, "Kilburn Park (zone 2)", 51.535135560206,
-0.19395164168612);
        helper.addLocation(dir, "King George V (zone 3)", 51.502008599189,
0.062220618931645);
        helper.addLocation(dir, "King's Cross (zone 1)", 51.53079820546,
-0.12274200728123);
        helper.addLocation(dir, "Kings Cross St. Pancras (zone 1)",
51.530312476892, -0.12385771561154);
        helper.addLocation(dir, "Kingsbury (zone 4)", 51.584876550714,
-0.27858717715014);
        helper.addLocation(dir, "Kingston (zone 6)", 51.412641800653,
-0.30112666341862);
        helper.addLocation(dir, "Knightsbridge (zone 1)", 51.501354916808,
-0.16065008131194);
        helper.addLocation(dir, "Knockholt (zone 6)", 51.345751922698,
0.13084539482109);
        helper.addLocation(dir, "Ladbroke Grove (zone 2)", 51.517210698742,
-0.21018376269161);
        helper.addLocation(dir, "Ladywell (zone 3)", 51.45619213691,
-0.019230010500554);
        helper.addLocation(dir, "Lambeth North (zone 1)", 51.499129959063,
-0.11175385704735);
        helper.addLocation(dir, "Lancaster Gate (zone 1)", 51.511890964101,
-0.17541552045722);
        helper.addLocation(dir, "Langdon Park (zone 2)", 51.518883939693,
-0.015199388573999);
        helper.addLocation(dir, "Latimer Road (zone 2)", 51.513958124663,
-0.21744525733064);
        helper.addLocation(dir, "Lee (zone 3)", 51.449458517716,
0.013379080898623);
        helper.addLocation(dir, "Leicester Square (zone 1)",
51.511291196842, -0.12822773962177);
        helper.addLocation(dir, "Lewisham (zone 40604)", 51.464880714235,
-0.012418307529155);
        helper.addLocation(dir, "Leyton (zone 3)", 51.55813227051,
-0.0064509088011814);
        helper.addLocation(dir, "Leyton Midland Road (zone 3)",
51.569364239801, -0.0080519210997184);
        helper.addLocation(dir, "Leytonstone (zone 3,4)", 51.568522287449,
0.009154878018083);
        helper.addLocation(dir, "Leytonstone High Road (zone 3)",
51.563807342647, 0.0082688934065806);
        helper.addLocation(dir, "Limehouse (zone 2)", 51.512312167848,
-0.039365669438682);
        helper.addLocation(dir, "Liverpool Street (zone 1)",
51.517598273919, -0.082235212309326);
        helper.addLocation(dir, "London Bridge (zone 1)", 51.504674357597,
-0.085991192281661);
        helper.addLocation(dir, "London City Airport (zone 3)",
51.50368965775, 0.047887121033287);
        helper.addLocation(dir, "London Fields (zone 2)", 51.540718847663,
-0.057685269137809);
        helper.addLocation(dir, "Loughborough Junction (zone 2)",
51.46667891193, -0.10248294761392);
        helper.addLocation(dir, "Loughton (zone 6)", 51.641570470369,
0.055293528321119);
        helper.addLocation(dir, "Lower Sydenham (zone 4)", 51.424846846074,
-0.033315960742811);
        helper.addLocation(dir, "Maida Vale (zone 2)", 51.529995078969,
-0.18541823310956);
        helper.addLocation(dir, "Malden Manor (zone 4)", 51.384609567544,
-0.26110604834896);
        helper.addLocation(dir, "Manor House (zone 40604)",
51.570747151453, -0.095670549505162);
        helper.addLocation(dir, "Manor Park (zone 3,4)", 51.552854343905,
0.045738291167029);
        helper.addLocation(dir, "Mansion House (zone 1)", 51.512091761163,
-0.094183249527509);
        helper.addLocation(dir, "Marble Arch (zone 1)", 51.513965510738,
-0.15855680746603);
        helper.addLocation(dir, "Maryland (zone 3)", 51.545668269809,
0.0056960730233714);
        helper.addLocation(dir, "Marylebone (zone 1)", 51.522396687994,
-0.16347815242029);
        helper.addLocation(dir, "Maze Hill (zone 3)", 51.483013655604,
0.0032192958995991);
        helper.addLocation(dir, "Mile End (zone 2)", 51.525310973905,
-0.032651671918221);
        helper.addLocation(dir, "Mill Hill Broadway (zone 4)",
51.612871158046, -0.24952262850911);
        helper.addLocation(dir, "Mill Hill East (zone 4)", 51.608316669912,
-0.20988127429344);
        helper.addLocation(dir, "Mitcham Eastfields (zone 3)",
51.408383928225, -0.15398734320935);
        helper.addLocation(dir, "Mitcham Junction (zone 4)",
51.39304258672, -0.15742227287945);
        helper.addLocation(dir, "Monument (zone 1)", 51.510630425959,
-0.086173905918798);
        helper.addLocation(dir, "Moor Park (zone 6,7)", 51.629930718133,
-0.4328985822977);
        helper.addLocation(dir, "Moorgate (zone 1)", 51.518437149414,
-0.08900327764505);
        helper.addLocation(dir, "Morden (zone 4)", 51.402185984981,
-0.19483760810466);
        helper.addLocation(dir, "Morden South (zone 4)", 51.396307721608,
-0.20028719027858);
        helper.addLocation(dir, "Mornington Crescent (zone 2)",
51.534362233874, -0.1387299346061);
        helper.addLocation(dir, "Mortlake (zone 3)", 51.468167968359,
-0.26718891965297);
        helper.addLocation(dir, "Motspur Park (zone 4)", 51.395319655441,
-0.23942537454861);
        helper.addLocation(dir, "Mottingham (zone 4)", 51.439824969906,
0.050338587672779);
        helper.addLocation(dir, "Mudchute (zone 2)", 51.491236186648,
-0.014945543221677);
        helper.addLocation(dir, "Neasden (zone 3)", 51.554627747213,
-0.25010062378951);
        helper.addLocation(dir, "New Barnet (zone 5)", 51.648536790554,
-0.17295526264108);
        helper.addLocation(dir, "New Beckenham (zone 4)", 51.41670555246,
-0.035290571074268);
        helper.addLocation(dir, "New Cross (zone 2)", 51.476429418617,
-0.032264414494673);
        helper.addLocation(dir, "New Cross Gate (zone 2)", 51.475264932486,
-0.039514655295107);
        helper.addLocation(dir, "New Eltham (zone 4)", 51.437690651019,
0.070459003212279);
        helper.addLocation(dir, "New Malden (zone 4)", 51.403555937615,
-0.25620373217155);
        helper.addLocation(dir, "New Southgate (zone 4)", 51.614093683634,
-0.14299533557942);
        helper.addLocation(dir, "Newbury Park (zone 4)", 51.575638344309,
0.090317586010402);
        helper.addLocation(dir, "Norbiton (zone 5)", 51.411909385349,
-0.28418557131983);
        helper.addLocation(dir, "Norbury (zone 3)", 51.411188517406,
-0.12278502535626);
        helper.addLocation(dir, "North Acton (zone 2,3)", 51.523432458806,
-0.25971511616691);
        helper.addLocation(dir, "North Dulwich (zone 40604)",
51.454481818931, -0.087904290624922);
        helper.addLocation(dir, "North Ealing (zone 3)", 51.517622323819,
-0.28897914280262);
        helper.addLocation(dir, "North Greenwich (zone 2,3)",
51.500255151591, 0.0036006636371896);
        helper.addLocation(dir, "North Harrow (zone 5)", 51.584631342978,
-0.3626185623764);
        helper.addLocation(dir, "North Sheen (zone 3)", 51.465419645874,
-0.28638307337002);
        helper.addLocation(dir, "North Wembley (zone 4)", 51.562396328364,
-0.30393379535805);
        helper.addLocation(dir, "Northfields (zone 3)", 51.500491708619,
-0.31505041439224);
        helper.addLocation(dir, "Northolt (zone 5)", 51.548212945697,
-0.36842617615208);
        helper.addLocation(dir, "Northolt Park (zone 5)", 51.557619094925,
-0.35941977403748);
        helper.addLocation(dir, "Northwick Park (zone 4)", 51.5785087266,
-0.31818496289702);
        helper.addLocation(dir, "Northwood (zone 6)", 51.611213662308,
-0.42382334746562);
        helper.addLocation(dir, "Northwood Hills (zone 6)",
51.600802695129, -0.40929692189409);
        helper.addLocation(dir, "Norwood Junction (zone 4)",
51.396954330829, -0.075195484483074);
        helper.addLocation(dir, "Notting Hill Gate (zone 1,2)",
51.509375359878, -0.1959072111467);
        helper.addLocation(dir, "Nunhead (zone 2)", 51.466579990247,
-0.053665348737765);
        helper.addLocation(dir, "Oakleigh Park (zone 4)", 51.637676382963,
-0.16618051866214);
        helper.addLocation(dir, "Oakwood (zone 5)", 51.64763797617,
-0.1318390886991);
        helper.addLocation(dir, "Old Street (zone 1)", 51.525581481862,
-0.087608545343845);
        helper.addLocation(dir, "Orpington (zone 6)", 51.373520035814,
0.089043266168332);
        helper.addLocation(dir, "Osterley (zone 4)", 51.481216852781,
-0.3520816978192);
        helper.addLocation(dir, "Oval (zone 2)", 51.481412613811, -
0.11330667730935);
        helper.addLocation(dir, "Oxford Circus (zone 1)", 51.515223419245,
-0.14082176208955);
        helper.addLocation(dir, "Paddington (zone 1)", 51.515393806532,
-0.17572234283505);
        helper.addLocation(dir, "Palmers Green (zone 4)", 51.618786761028,
-0.11025805805573);
        helper.addLocation(dir, "Park Royal (zone 3)", 51.526834054645,
-0.28491450496891);
        helper.addLocation(dir, "Parsons Green (zone 2)", 51.474960176772,
-0.20111009589714);
        helper.addLocation(dir, "Peckham Rye (zone 2)", 51.469511372801,
-0.069969158361951);
        helper.addLocation(dir, "Penge East (zone 4)", 51.41997535513,
-0.054480885538245);
        helper.addLocation(dir, "Penge West (zone 4)", 51.418062935027,
-0.060631385884983);
        helper.addLocation(dir, "Perivale (zone 4)", 51.536341860358,
-0.32305600630537);
        helper.addLocation(dir, "Petts Wood (zone 5)", 51.388598981243,
0.074494399194959);
        helper.addLocation(dir, "Piccadilly Circus (zone 1)",
51.509696764476, -0.13369718974012);
        helper.addLocation(dir, "Pimlico (zone 1)", 51.489552877924,
-0.1330938573102);
        helper.addLocation(dir, "Pinner (zone 5)", 51.592361724428,
-0.38120935690424);
        helper.addLocation(dir, "Plaistow (zone 3)", 51.531288332324,
0.017795056275962);
        helper.addLocation(dir, "Plumstead (zone 4)", 51.489792413595,
0.084314017745385);
        helper.addLocation(dir, "Ponders End (zone 5)", 51.642730695,
-0.034510654933282);
        helper.addLocation(dir, "Pontoon Dock (zone 3)", 51.502216211037,
0.033340112607835);
        helper.addLocation(dir, "Poplar (zone 2)", 51.507588072081,
-0.017261086484836);
        helper.addLocation(dir, "Preston Road (zone 4)", 51.572103763883,
-0.29495758553154);
        helper.addLocation(dir, "Prince Regent (zone 3)", 51.509434545079,
0.033502981448267);
        helper.addLocation(dir, "Pudding Mill Lane (zone 2,3)",
51.53432785535, -0.012754096692901);
        helper.addLocation(dir, "Purley (zone 6)", 51.337363567516,
-0.11359916443804);
        helper.addLocation(dir, "Purley Oaks (zone 6)", 51.346989351539,
-0.098800976652713);
        helper.addLocation(dir, "Putney (zone 2,3)", 51.460952556568,
-0.21658898147399);
        helper.addLocation(dir, "Putney Bridge (zone 2)", 51.467865362703,
-0.20935102262327);
        helper.addLocation(dir, "Queens Park (zone 2)", 51.534312675201,
-0.20478373421795);
        helper.addLocation(dir, "Queens Road Peckham (zone 2)",
51.474284715779, -0.057340582526957);
        helper.addLocation(dir, "Queensbury (zone 4)", 51.593883010111,
-0.28631716346916);
        helper.addLocation(dir, "Queenstown Road (zone 2)", 51.47495914471,
-0.14734091559888);
        helper.addLocation(dir, "Queensway (zone 1)", 51.510449255439,
-0.18740549543317);
        helper.addLocation(dir, "Radlett (zone )", 51.685413310275,
-0.31797317069656);
        helper.addLocation(dir, "Rainham (zone 6)", 51.517340491331,
0.19070638530502);
        helper.addLocation(dir, "Ravensbourne (zone 4)", 51.413870378956,
-0.0069234381730423);
        helper.addLocation(dir, "Ravenscourt Park (zone 2)",
51.494068008984, -0.23595483065011);
        helper.addLocation(dir, "Rayners Lane (zone 5)", 51.575396777398,
-0.371046385824);
        helper.addLocation(dir, "Raynes Park (zone 4)", 51.409375373186,
-0.22989856350727);
        helper.addLocation(dir, "Rectory Road (zone 2)", 51.558763484573,
-0.068371241749211);
        helper.addLocation(dir, "Redbridge (zone 4)", 51.576366911264,
0.045408472505876);
        helper.addLocation(dir, "Reedham (zone 6)", 51.331441727656,
-0.12338827286968);
        helper.addLocation(dir, "Regents Park (zone 1)", 51.52381069054,
-0.14532999904559);
        helper.addLocation(dir, "Richmond (zone 4)", 51.463232922347,
-0.30172474133933);
        helper.addLocation(dir, "Rickmansworth (zone 7)", 51.640323072212,
-0.47367013575456);
        helper.addLocation(dir, "Riddlesdown (zone 6)", 51.332674842588,
-0.099479315537562);
        helper.addLocation(dir, "Roding Valley (zone 4)", 51.616956440142,
0.044040648415103);
        helper.addLocation(dir, "Romford (zone 6)", 51.574641568849,
0.18306970022131);
        helper.addLocation(dir, "Rotherhithe (zone 2)", 51.501594510808,
-0.052951891484305);
        helper.addLocation(dir, "Royal Albert (zone 3)", 51.508493863562,
0.045191552169371);
        helper.addLocation(dir, "Royal Oak (zone 2)", 51.518294375269,
-0.18880926348942);
        helper.addLocation(dir, "Royal Victoria (zone 3)", 51.509055232332,
0.017979819853408);
        helper.addLocation(dir, "Ruislip (zone 6)", 51.57216197222,
-0.42122049909957);
        helper.addLocation(dir, "Ruislip Gardens (zone 5)",
51.559960227907, -0.40927968814014);
        helper.addLocation(dir, "Ruislip Manor (zone 6)", 51.573451624726,
-0.41283492710738);
        helper.addLocation(dir, "Russell Square (zone 1)", 51.523013052867,
-0.12457578611157);
        helper.addLocation(dir, "Sanderstead (zone 6)", 51.34824626461,
-0.093694143249397);
        helper.addLocation(dir, "Selhurst (zone 4)", 51.39218578041,
-0.089884666539009);
        helper.addLocation(dir, "Seven Kings (zone 4)", 51.563993339397,
0.096333999350604);
        helper.addLocation(dir, "Seven Sisters (zone 3)", 51.583362168372,
-0.0724523920649);
        helper.addLocation(dir, "Shadwell (zone 2)", 51.51130016173,
-0.056904799137598);
        helper.addLocation(dir, "Shepherds Bush (zone 2)", 51.50453217729,
-0.21850475368199);
        helper.addLocation(dir, "Shepherds Bush Market (zone 2)",
51.505880735504, -0.22738608723774);
        helper.addLocation(dir, "Shoreditch (zone 2)", 51.522709102713,
-0.070906418527321);
        helper.addLocation(dir, "Shortlands (zone 4)", 51.40560236593,
0.0027819191560382);
        helper.addLocation(dir, "Sidcup (zone 5)", 51.43439844437,
0.10332974285774);
        helper.addLocation(dir, "Silver Street (zone 4)", 51.615242486372,
-0.072575300701906);
        helper.addLocation(dir, "Slade Green (zone 6)", 51.467747631244,
0.19053278174752);
        helper.addLocation(dir, "Sloane Square (zone 1)", 51.492359782932,
-0.1564744555002);
        helper.addLocation(dir, "Smitham (zone 6)", 51.322452969178,
-0.13433270854947);
        helper.addLocation(dir, "Snaresbrook (zone 4)", 51.580891270601,
0.021478357761873);
        helper.addLocation(dir, "South Acton (zone 3)", 51.499685861011,
-0.27020080333496);
        helper.addLocation(dir, "South Bermondsey (zone 2)",
51.487676621549, -0.054740420692279);
        helper.addLocation(dir, "South Croydon (zone 5)", 51.362750208796,
-0.092503001948904);
        helper.addLocation(dir, "South Ealing (zone 3)", 51.501644057917,
-0.30702584019952);
        helper.addLocation(dir, "South Hampstead (zone 2)",
51.541476868984, -0.1783567825076);
        helper.addLocation(dir, "South Harrow (zone 5)", 51.564680211138,
-0.35187954635816);
        helper.addLocation(dir, "South Kensington (zone 1)",
51.494071386411, -0.17390862058942);
        helper.addLocation(dir, "South Kenton (zone 4)", 51.571044486824,
-0.30812855062663);
        helper.addLocation(dir, "South Merton (zone 4)", 51.403240579864,
-0.20553592740103);
        helper.addLocation(dir, "South Quay (zone 2)", 51.500863608239,
-0.018446287979256);
        helper.addLocation(dir, "South Ruislip (zone 5)", 51.55689035096,
-0.39910148824501);
        helper.addLocation(dir, "South Tottenham (zone 3)",
51.580402594532, -0.071841526783666);
        helper.addLocation(dir, "South Wimbledon (zone 40636)",
51.41536073293, -0.19196016848772);
        helper.addLocation(dir, "South Woodford (zone 4)", 51.591552612383,
0.027957511681624);
        helper.addLocation(dir, "Southall (zone 4)", 51.505956957579,
-0.37869678379695);
        helper.addLocation(dir, "Southbury (zone 5)", 51.648433731335,
-0.052968859157203);
        helper.addLocation(dir, "Southfields (zone 3)", 51.444883338258,
-0.20659499856664);
        helper.addLocation(dir, "Southgate (zone 4)", 51.63237586338,
-0.12775560097809);
        helper.addLocation(dir, "Southwark (zone 1)", 51.503853632869,
-0.10578053394541);
        helper.addLocation(dir, "St Helier (zone 4)", 51.389912187517,
-0.19900022218424);
        helper.addLocation(dir, "St James Street (zone 3)",
51.580608667586, -0.032790131848525);
        helper.addLocation(dir, "St Johns (zone 2)", 51.468975297065,
-0.023226267171585);
        helper.addLocation(dir, "St Margarets (zone 4)", 51.455206030249,
-0.32130985776381);
        helper.addLocation(dir, "St Mary Cray (zone 6)", 51.394759394244,
0.10723227089692);
        helper.addLocation(dir, "St Pancras (zone 1)", 51.530554416571,
-0.12549136793246);
        helper.addLocation(dir, "St. James's Park (zone 1)",
51.499609810342, -0.13386435110426);
        helper.addLocation(dir, "St. Johns Wood (zone 2)", 51.534854431713,
-0.17405042505482);
        helper.addLocation(dir, "St. Pauls (zone 1)", 51.51483530739,
-0.097556591574387);
        helper.addLocation(dir, "Stamford Brook (zone 2)", 51.494449997347,
-0.24523190696758);
        helper.addLocation(dir, "Stamford Hill (zone 3)", 51.574447612615,
-0.076653913978365);
        helper.addLocation(dir, "Stanmore (zone 5)", 51.6196734807,
-0.30308485086488);
        helper.addLocation(dir, "Stepney Green (zone 2)", 51.521995838874,
-0.047368111957746);
        helper.addLocation(dir, "Stockwell (zone 2)", 51.472159270341,
-0.12283190859196);
        helper.addLocation(dir, "Stoke Newington (zone 2)",
51.564637618307, -0.072320969849242);
        helper.addLocation(dir, "Stonebridge Park (zone 3)",
51.54398658738, -0.27538602336732);
        helper.addLocation(dir, "Stoneleigh (zone 5)", 51.363364082259,
-0.248695295654);
        helper.addLocation(dir, "Stratford (zone 3)", 51.541692579295,
-0.0037372234417709);
        helper.addLocation(dir, "Stratford International (zone 3)",
51.54480853536, -0.0087640154463654);
        helper.addLocation(dir, "Strawberry Hill (zone 5)",
51.439747873261, -0.33960334587097);
        helper.addLocation(dir, "Streatham (zone 3)", 51.425845878375,
-0.13231111566835);
        helper.addLocation(dir, "Streatham Common (zone 3)",
51.418984686908, -0.13571178617484);
        helper.addLocation(dir, "Streatham Hill (zone 3)", 51.438460380547,
-0.1276670964405);
        helper.addLocation(dir, "Sudbury & Harrow Road (zone 4)",
51.554493821699, -0.31591182033013);
        helper.addLocation(dir, "Sudbury Hill (zone 4)", 51.557339600086,
-0.33637769283987);
        helper.addLocation(dir, "Sudbury Hill Harrow (zone 4)",
51.558342313079, -0.33543227050831);
        helper.addLocation(dir, "Sudbury Town (zone 4)", 51.551397480891,
-0.31632906529511);
        helper.addLocation(dir, "Sundridge Park (zone 4)", 51.413393796204,
0.020379486210958);
        helper.addLocation(dir, "Surbiton (zone 6)", 51.392599569913,
-0.3043701893312);
        helper.addLocation(dir, "Surrey Quays (zone 2)", 51.493266862158,
-0.047515585346921);
        helper.addLocation(dir, "Sutton (zone 5)", 51.359506158142,
-0.19128765090448);
        helper.addLocation(dir, "Sutton Common (zone 4)", 51.375554718505,
-0.19690554710689);
        helper.addLocation(dir, "Swiss Cottage (zone 2)", 51.543034867714,
-0.17561218648329);
        helper.addLocation(dir, "Sydenham (zone 3)", 51.427341258001,
-0.055074289357489);
        helper.addLocation(dir, "Sydenham Hill (zone 3)", 51.432575896828,
-0.080215824663043);
        helper.addLocation(dir, "Syon Lane (zone 4)", 51.481474727333,
-0.32648063620347);
        helper.addLocation(dir, "Teddington (zone 6)", 51.424497537357,
-0.3326909565597);
        helper.addLocation(dir, "Temple (zone 1)", 51.51104062071,
-0.11371134239066);
        helper.addLocation(dir, "Thames Ditton (zone 6)", 51.388616113023,
-0.33827846842909);
        helper.addLocation(dir, "Theydon Bois (zone 6)", 51.672552069981,
0.10290519530392);
        helper.addLocation(dir, "Thornton Heath (zone 4)", 51.398481089859,
-0.10041879260042);
        helper.addLocation(dir, "Tolworth (zone 5)", 51.376843349784,
-0.27960574939507);
        helper.addLocation(dir, "Tooting (zone 3)", 51.419896651766,
-0.16098809293112);
        helper.addLocation(dir, "Tooting Bec (zone 3)", 51.435838083172,
-0.15968610811001);
        helper.addLocation(dir, "Tooting Broadway (zone 3)",
51.42704916499, -0.16867014599257);
        helper.addLocation(dir, "Tottenham Court Road (zone 1)",
51.51621088565, -0.13109602942553);
        helper.addLocation(dir, "Tottenham Hale (zone 3)", 51.587997785049,
-0.060173390466137);
        helper.addLocation(dir, "Totteridge & Whetstone (zone 4)",
51.63024674119, -0.17933981753571);
        helper.addLocation(dir, "Tower Gateway (zone 1)", 51.510392650922,
-0.074395469530797);
        helper.addLocation(dir, "Tower Hill (zone 1)", 51.510394282129,
-0.076686790760475);
        helper.addLocation(dir, "Tufnell Park (zone 2)", 51.556440814333,
-0.13772775294192);
        helper.addLocation(dir, "Tulse Hill (zone 3)", 51.4397974399,
-0.10510812362275);
        helper.addLocation(dir, "Turkey Street (zone 6)", 51.672653666247,
-0.047215472250329);
        helper.addLocation(dir, "Turnham Green (zone 2)", 51.495181971972,
-0.25451016527384);
        helper.addLocation(dir, "Turnpike Lane (zone 3)", 51.590358146027,
-0.1027906082273);
        helper.addLocation(dir, "Twickenham (zone 5)", 51.450250987135,
-0.32884583782433);
        helper.addLocation(dir, "Upminster (zone 6)", 51.558763325208,
0.2514152239117);
        helper.addLocation(dir, "Upminster Bridge (zone 6)",
51.557718771685, 0.23455631120919);
        helper.addLocation(dir, "Upney (zone 4)", 51.538405634701,
0.10154616057314);
        helper.addLocation(dir, "Upper Holloway (zone 2)", 51.563623319983,
-0.12909493917319);
        helper.addLocation(dir, "Upper Warlingham (zone 6)",
51.308772263619, -0.077467317417935);
        helper.addLocation(dir, "Upton Park (zone 3)", 51.536628195871,
0.034556255633226);
        helper.addLocation(dir, "Uxbridge (zone 6)", 51.546454564696,
-0.47708714109832);
        helper.addLocation(dir, "Vauxhall (zone 1,2)", 51.485735816391,
-0.12381555294752);
        helper.addLocation(dir, "Victoria (zone 1)", 51.496423969876,
-0.14390630306143);
        helper.addLocation(dir, "Waddon (zone 5)", 51.367379270921,
-0.11737971383443);
        helper.addLocation(dir, "Wallington (zone 5)", 51.360331562347,
-0.15084947457103);
        helper.addLocation(dir, "Walthamstow Central (zone 3)",
51.583018115291, -0.019926114372123);
        helper.addLocation(dir, "Walthamstow Queens Road (zone 3)",
51.581546193899, -0.0238295131434);
        helper.addLocation(dir, "Wandsworth Common (zone 3)",
51.446365623898, -0.16352259346247);
        helper.addLocation(dir, "Wandsworth Road (zone 2)",
51.470223218762, -0.13902328072857);
        helper.addLocation(dir, "Wandsworth Town (zone 2)",
51.461034098277, -0.18789564563536);
        helper.addLocation(dir, "Wanstead (zone 4)", 51.574902145755,
0.028774900468403);
        helper.addLocation(dir, "Wanstead Park (zone 3)", 51.551778074703,
0.026404363778733);
        helper.addLocation(dir, "Wapping (zone 2)", 51.504340322706,
-0.055846408737992);
        helper.addLocation(dir, "Warren Street (zone 1)", 51.524580005085,
-0.13826391949985);
        helper.addLocation(dir, "Warwick Avenue (zone 2)", 51.523104457076,
-0.18293888140664);
        helper.addLocation(dir, "Waterloo (zone 1)", 51.503146653078,
-0.11324484659974);
        helper.addLocation(dir, "Watford (zone 7)", 51.657605146891,
-0.41725555293253);
        helper.addLocation(dir, "Welling (zone 4)", 51.464777075182,
0.10178943179171);
        helper.addLocation(dir, "Wembley Central (zone 4)",
51.551864816194, -0.29637790641578);
        helper.addLocation(dir, "Wembley Park (zone 4)", 51.563322491915,
-0.27922812839087);
        helper.addLocation(dir, "Wembley Stadium (zone 4)",
51.554654605186, -0.28603202522583);
        helper.addLocation(dir, "West Acton (zone 3)", 51.517770184208,
-0.28064276561988);
        helper.addLocation(dir, "West Brompton (zone 2)", 51.487328938205,
-0.19552441152812);
        helper.addLocation(dir, "West Croydon (zone 5)", 51.378552186111,
-0.1020199266263);
        helper.addLocation(dir, "West Drayton (zone 6)", 51.510071275994,
-0.47216168972777);
        helper.addLocation(dir, "West Dulwich (zone 3)", 51.440911831895,
-0.090658290563767);
        helper.addLocation(dir, "West Ealing (zone 3)", 51.513625243955,
-0.31976854613702);
        helper.addLocation(dir, "West Finchley (zone 4)", 51.609262750488,
-0.1889026706526);
        helper.addLocation(dir, "West Ham (zone 3)", 51.52852551818,
0.0053318072586749);
        helper.addLocation(dir, "West Hampstead (zone 2)", 51.547474356007,
-0.19111216622603);
        helper.addLocation(dir, "West Hampstead Thameslink (zone 2)",
51.548629145744, -0.19252310000093);
        helper.addLocation(dir, "West Harrow (zone 5)", 51.578924280955,
-0.35383226807134);
        helper.addLocation(dir, "West India Quay (zone 2)",
51.506762659668, -0.020568040587805);
        helper.addLocation(dir, "West Kensington (zone 2)",
51.490109387233, -0.20618929345907);
        helper.addLocation(dir, "West Norwood (zone 3)", 51.431241127782,
-0.10317475212492);
        helper.addLocation(dir, "West Ruislip (zone 6)", 51.569587924657,
-0.43784571956141);
        helper.addLocation(dir, "West Silvertown (zone 3)",
51.502884431544, 0.022260451989289);
        helper.addLocation(dir, "West Sutton (zone 5)", 51.366150159758,
-0.20463018612991);
        helper.addLocation(dir, "West Wickham (zone 5)", 51.381284202527,
-0.014561963270977);
        helper.addLocation(dir, "Westbourne Park (zone 2)",
51.520988865484, -0.20086810419124);
        helper.addLocation(dir, "Westcombe Park (zone 3)", 51.484508893293,
0.017760099794534);
        helper.addLocation(dir, "Westferry (zone 2)", 51.509638150617,
-0.026308729670621);
        helper.addLocation(dir, "Westminster (zone 1)", 51.501401606172,
-0.12498767440679);
        helper.addLocation(dir, "White City (zone 2)", 51.512232464701,
-0.22461752326457);
        helper.addLocation(dir, "White Hart Lane (zone 3)",
51.605034779059, -0.07085588920127);
        helper.addLocation(dir, "Whitechapel (zone 2)", 51.519587792346,
-0.059406074587337);
        helper.addLocation(dir, "Whitton (zone 5)", 51.449588234079,
-0.35766767257282);
        helper.addLocation(dir, "Whyteleafe (zone 6)", 51.309929327757,
-0.081120820529126);
        helper.addLocation(dir, "Whyteleafe South (zone 6)",
51.30348981231, -0.076698171894698);
        helper.addLocation(dir, "Willesden Green (zone 2,3)",
51.549373313232, -0.22239318421442);
        helper.addLocation(dir, "Willesden Junction (zone 3)",
51.532233992929, -0.2438947288224);
        helper.addLocation(dir, "Wimbledon (zone 3)", 51.421107869794,
-0.20664845638008);
        helper.addLocation(dir, "Wimbledon Chase (zone 3)",
51.409530957999, -0.21407539384331);
        helper.addLocation(dir, "Wimbledon Park (zone 3)", 51.434580976538,
-0.19917189150183);
        helper.addLocation(dir, "Winchmore Hill (zone 4)", 51.633886871044,
-0.10090248655044);
        helper.addLocation(dir, "Wood Green (zone 3)", 51.597453741251,
-0.10951215426353);
        helper.addLocation(dir, "Wood Street (zone 4)", 51.586669943719,
-0.0019394662016431);
        helper.addLocation(dir, "Woodford (zone 4)", 51.607201839663,
0.034070640659794);
        helper.addLocation(dir, "Woodgrange Park (zone 3,4)",
51.549052529247, 0.044586916011772);
        helper.addLocation(dir, "Woodmansterne (zone 6)", 51.319018597795,
-0.154247780889);
        helper.addLocation(dir, "Woodside Park (zone 4)", 51.617868422141,
-0.185411063095);
        helper.addLocation(dir, "Woolwich Arsenal (zone 4)",
51.489907107526, 0.069208307647642);
        helper.addLocation(dir, "Woolwich Dockyard (zone 3)",
51.491107787563, 0.054626749936269);
        helper.addLocation(dir, "Worcester Park (zone 4)", 51.381104516868,
-0.24556092484593);
    }
}



On 1 January 2012 18:00, David Smiley (@MITRE.org) <DS...@mitre.org>wrote:

> Hi Lance.
>
> LSP has the concept of a "SpatialStrategy" which encompasses all the
> algorithms and what-not to index and query, filter, and sort shapes.  The
> TwoDoublesStrategy aims to basically work like Solr's LatLonType, however
> it
> isn't completely implemented as you found out -- it doesn't do circle query
> shapes.  It shouldn't be hard to rectify that; I might work on it next.
>  The
> SpatialStrategy that has gotten the most attention by far in LSP is
> RecursivePrefixTreeStrategy, my pride and joy.  It supports a variable
> number of points per document, and it supports indexing all shapes; not
> just
> points.  I don't think you care about those two features, but it does do
> sorting and circle query shapes.  The "score" that comes back from the
> query
> is the distance from the query's center, so sort by the query to get what
> you want.  This strategy doesn't store the points in memory as efficiently
> as TwoDoublesStrategy does; that's something I need to improve, but it
> works.
>
> ~ David Smiley
>
> -----
>  Author:
> http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3625177.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Spatial Search

Posted by "David Smiley (@MITRE.org)" <DS...@mitre.org>.
Hi Lance.

LSP has the concept of a "SpatialStrategy" which encompasses all the
algorithms and what-not to index and query, filter, and sort shapes.  The
TwoDoublesStrategy aims to basically work like Solr's LatLonType, however it
isn't completely implemented as you found out -- it doesn't do circle query
shapes.  It shouldn't be hard to rectify that; I might work on it next.  The
SpatialStrategy that has gotten the most attention by far in LSP is
RecursivePrefixTreeStrategy, my pride and joy.  It supports a variable
number of points per document, and it supports indexing all shapes; not just
points.  I don't think you care about those two features, but it does do
sorting and circle query shapes.  The "score" that comes back from the query
is the distance from the query's center, so sort by the query to get what
you want.  This strategy doesn't store the points in memory as efficiently
as TwoDoublesStrategy does; that's something I need to improve, but it
works.

~ David Smiley

-----
 Author: http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
--
View this message in context: http://lucene.472066.n3.nabble.com/Spatial-Search-tp3623494p3625177.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Sun, Jan 1, 2012 at 6:18 AM, Lance Java <la...@googlemail.com> wrote:
> But I'm a bit worried about this solution since Yonik has pointed out that
> the tier based approach is broken. Yonik, any more info on why this is
> broken? Perhaps a bounding box that works is better than a circle that
> doesn't ;)

Haven't used it myself, but it seemed to be the opinion of others who did.

https://issues.apache.org/jira/browse/LUCENE-2599
http://www.lucidimagination.com/search/document/c32e81783642df47/spatial_rethinking_cartesian_tiers_implementation

-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Spatial Search

Posted by Lance Java <la...@googlemail.com>.
Hi, I'm trying to keep this a lucene only project rather than bring in solr
which, as I understand, needs to run in a separate web container. I'd like
to use a single webapp for my project as I'm unsure of the implications of
hosting such a project on the cloud.

I downloaded lucene-spatial-playground and had a poke through the code and
found that TwoDoublesStrategyTestCase runs the following query:

   [San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123
37.817108)

This seemed close to what I wanted except that it uses a bounding box
instead of a circle. Taking inspiration from
BaseSpatialContextTestCase.checkBasicShapeIO() I tried the following

   [San Francisco] G5391959 @ IsWithin(*Circle*( -122.524918 37.674973
distance=7.89))

But unfortunately I got the following exception:

   InvalidShapeException: A rectangle is the only supported at this time,
not class org.apache.lucene.spatial.base.shape.simple.CircleImpl

So it seems that isWithin a circle is not currently supported. If anyone
has any information/documentation on the lucene-spatial-playground it would
be helpful.

In the mean time I have taken inspiration from
http://www.java-community.de/archives/156-Spatial-search-with-Lucene.htmlto
come up with a working solution.

Results:
20 tube stations are 1 miles from liverpool st
47 tube stations are 2 miles from liverpool st
92 tube stations are 3 miles from liverpool st
138 tube stations are 4 miles from liverpool st

But I'm a bit worried about this solution since Yonik has pointed out that
the tier based approach is broken. Yonik, any more info on why this is
broken? Perhaps a bounding box that works is better than a circle that
doesn't ;)


Cheers,
Lance.


On 31 December 2011 18:07, Yonik Seeley <yo...@lucidimagination.com> wrote:

> On Sat, Dec 31, 2011 at 11:52 AM, Lance Java <la...@googlemail.com>
> wrote:
> > Hi, I am new to Lucene and I am trying to use spatial search.
>
> The old tier-based stuff in Lucene is broken and considered deprecated.
>
> For Lucene, this may currently be your best hope:
> http://code.google.com/p/lucene-spatial-playground/
>
> Solr has also had built-in spatial for a little while too:
> http://wiki.apache.org/solr/SpatialSearch
>
>
> -Yonik
> http://www.lucidimagination.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Spatial Search

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Sat, Dec 31, 2011 at 11:52 AM, Lance Java <la...@googlemail.com> wrote:
> Hi, I am new to Lucene and I am trying to use spatial search.

The old tier-based stuff in Lucene is broken and considered deprecated.

For Lucene, this may currently be your best hope:
http://code.google.com/p/lucene-spatial-playground/

Solr has also had built-in spatial for a little while too:
http://wiki.apache.org/solr/SpatialSearch


-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org