Package models

Examples of models.PostcodeUnit


        if (geocodeForm.hasErrors()) {
            return badRequest(index.render(form(DistanceCalc.class), geocodeForm, new ArrayList<PostcodeUnit>()));
        } else {
            Geocode geocode = geocodeForm.get();

            PostcodeUnit unit = PostcodeUnit.find.field("postcode").equal(CharMatcher.WHITESPACE.removeFrom(geocode.postcode).toUpperCase()).get();
            return ok(toJson(unit.location));
        }
    }
View Full Code Here


    public static Result latLng(String postcode) {
        if (Strings.isNullOrEmpty(postcode)) return badRequest("empty postcode");
        postcode = CharMatcher.WHITESPACE.removeFrom(postcode).toUpperCase();
        if (postcode.length() < 5 || postcode.length() > 7) return badRequest("illegal postcode format");

        PostcodeUnit unit = PostcodeUnit.find.field("postcode").equal(postcode).get();
        if (unit == null) {
            return notFound();
        } else {
            return ok(toJson(unit.location));
        }
View Full Code Here

        if (geocodeForm.hasErrors()) {
            return badRequest(index.render(form(DistanceCalc.class), geocodeForm, new ArrayList<PostcodeUnit>()));
        } else {
            Geocode geocode = geocodeForm.get();

            PostcodeUnit unit = PostcodeUnit.find.field("postcode").equal(CharMatcher.WHITESPACE.removeFrom(geocode.postcode).toUpperCase()).get();
            return ok(toJson(unit.cartesianLocation));
        }
    }
View Full Code Here

    public static Result eastingsNorthings(String postcode) {
        if (Strings.isNullOrEmpty(postcode)) return badRequest("empty postcode");
        postcode = CharMatcher.WHITESPACE.removeFrom(postcode).toUpperCase();
        if (postcode.length() < 5 || postcode.length() > 7) return badRequest("illegal postcode format");

        PostcodeUnit unit = PostcodeUnit.find.field("postcode").equal(postcode).get();
        if (unit == null) {
            return notFound();
        } else {
            return ok(toJson(unit.cartesianLocation));
        }
View Full Code Here

        if (distanceCalcForm.hasErrors()) {
            return badRequest(index.render(distanceCalcForm, form(Geocode.class), new ArrayList<PostcodeUnit>()));
        } else {
            DistanceCalc calc = distanceCalcForm.get();

            PostcodeUnit postcode = PostcodeUnit.find.field("postcode").equal(CharMatcher.WHITESPACE.removeFrom(calc.postcode).toUpperCase()).get();
            List<PostcodeUnit> near = findNearMiles(postcode.location.latitude, postcode.location.longitude, calc.distance, 100);

            StringBuilder message = new StringBuilder();
            message.append("Found ")
                    .append(near.size())
View Full Code Here

    @Override
    public void onReceive(Object message) {
        if (message instanceof CodePointOpenCsvEntry) {
            CodePointOpenCsvEntry entry = (CodePointOpenCsvEntry) message;

            PostcodeUnit unit = new PostcodeUnit(CharMatcher.WHITESPACE.removeFrom(entry.getPostcode()));
            unit.pqi = entry.getPositionalQualityIndicator();

            try {
                int eastings = Integer.parseInt(entry.getEastings());
                int northings = Integer.parseInt(entry.getNorthings());

                unit.cartesianLocation = new CartesianLocation(eastings, northings);

                final TimerContext latLongCtx = latLongTransform.time();
                try {
                    DirectPosition eastNorth = new GeneralDirectPosition(eastings, northings);
                    DirectPosition latLng = osgbToWgs84Transform.transform(eastNorth, eastNorth);

                    unit.location = new Location(round(latLng.getOrdinate(1), 8), round(latLng.getOrdinate(0), 8));
                } finally {
                    latLongCtx.stop();
                }
            } catch (NumberFormatException e) {
                throw new RuntimeException("NumberFormatException parsing easting/northings '" + entry.getEastings() + ", " + entry.getNorthings() + "'.");
            } catch (TransformException e) {
                throw Throwables.propagate(e);
            }

            final TimerContext saveCtx = savePostcodeUnit.time();
            try {
                unit.save();

                postcodesProcessed.inc();
            } catch (MongoException.DuplicateKey e) {
                // ignore
            } finally {
View Full Code Here

TOP

Related Classes of models.PostcodeUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.