Package org.geomajas.plugin.geocoder.api

Examples of org.geomajas.plugin.geocoder.api.GetLocationResult


  public CoordinateReferenceSystem getCrs() {
    return crs;
  }

  public GetLocationResult[] getLocation(List<String> location, int maxAlternatives, Locale ignore) {
    GetLocationResult result = null;
    for (StaticRegexGeocoderLocationInfo test : geocoderInfo.getLocations()) {
      result = getLocation(test, location);
      if (null != result) {
        break;
      }
View Full Code Here


      }
    }
    if (index < location.size() && !skipMoreDetailed) {
      return null; // remaining unmatched bits
    }
    GetLocationResult result = new GetLocationResult();
    if (null != test.getBbox()) {
      result.setEnvelope(dtoConverterService.toInternal(test.getBbox()));
    } else {
      result.setCoordinate(new Coordinate(test.getX(), test.getY()));
    }
    result.setCanonicalStrings(test.getCanonical());
    result.setUserData(test.getUserData());
    return result;
  }
View Full Code Here

        throw new Exception(root.getChildText("ErrorMessage"));
      }

      for (Object obj : root.getChildren("Result")) {
        Element toponymElement = (Element) obj;
        GetLocationResult location = getLocationFromElement(toponymElement);
        searchResult.add(location);
      }
    }
    return searchResult;
  }
View Full Code Here

    conn.setRequestProperty("User-Agent", USER_AGENT);
    return conn.getInputStream();
  }

  private GetLocationResult getLocationFromElement(Element locationElement) {
    GetLocationResult location = new GetLocationResult();

    List<String> canonical = new ArrayList<String>();
    canonicalAdd(canonical, locationElement, "line4");
    canonicalAdd(canonical, locationElement, "line3");
    canonicalAdd(canonical, locationElement, "line2");
    canonicalAdd(canonical, locationElement, "line1");
    if (0 == canonical.size()) {
      canonicalAdd(canonical, locationElement, "level5");
      canonicalAdd(canonical, locationElement, "level4");
      canonicalAdd(canonical, locationElement, "level3");
      canonicalAdd(canonical, locationElement, "level2");
      canonicalAdd(canonical, locationElement, "level1");
      canonicalAdd(canonical, locationElement, "level0");
    }
    location.setCanonicalStrings(canonical);

    Element area = locationElement.getChild("boundingbox");
    if (null != area) {
      double north = Double.parseDouble(area.getChildText("north"));
      double south = Double.parseDouble(area.getChildText("south"));
      double east = Double.parseDouble(area.getChildText("east"));
      double west = Double.parseDouble(area.getChildText("west"));
      if (Math.abs(north - south) > DELTA || Math.abs(east - west) > DELTA) {
        // return point when bbox is a point
        Bbox bbox = new Bbox(west, south, east - west, north - south);
        location.setEnvelope(dtoConverterService.toInternal(bbox));
      }
    }

    location.setCoordinate(new Coordinate(Double.parseDouble(locationElement.getChildText("longitude")),
        Double.parseDouble(locationElement.getChildText("latitude"))));

    return location;
  }
View Full Code Here

      resCount = toponyms.size();

      result = new GetLocationResult[resCount];
      for (int i = 0; i < resCount; i++) {
        Toponym toponym = toponyms.get(i);
        GetLocationResult one = new GetLocationResult();
        List<String> prefResult = new ArrayList<String>();
        prefResult.add(toponym.getCountryCode());
        prefResult.add(toponym.getName());
        one.setCanonicalStrings(prefResult);
        Coordinate coordinate = new Coordinate();
        coordinate.x = toponym.getLongitude();
        coordinate.y = toponym.getLatitude();
        one.setCoordinate(coordinate);
        result[i] = one;
      }
      return result;
    } catch (Exception ex) {
      log.error("Search failed", ex);
View Full Code Here

  /** {@inheritDoc} */
  public GetLocationResult[] getLocation(List<String> location, int maxAlternatives, Locale locale) {
    if (null == locale) {
      locale = Locale.US;
    }
    GetLocationResult result = new GetLocationResult();
    if (location.size() > 0) {
      String[] parts = location.get(0).split("\\s+");
      if (parts.length >= 2) {
        NumberFormat format = NumberFormat.getInstance(locale);
        try {
          Double x = format.parse(parts[0]).doubleValue();
          Double y = format.parse(parts[1]).doubleValue();

          result.setCoordinate(new Coordinate(x, y));
          List<String> canonical = new ArrayList<String>();
          canonical.add(parts[0] + " " + parts[1]);
          result.setCanonicalStrings(canonical);
          return new GetLocationResult[] { result };
        } catch (ParseException pe) {
          log.debug("Could not parse " + location.get(0) + ", " + pe.getMessage());
        }

View Full Code Here

  private static final double DELTA = 1e-20;

  @Test
  public void testCombine() throws Exception {
    Envelope e1 = new Envelope(10, 40, 10, 30);
    GetLocationResult glr1 = new GetLocationResult();
    glr1.setEnvelope(e1);
    Envelope e2 = new Envelope(20, 35, 25, 50);
    GetLocationResult glr2 = new GetLocationResult();
    glr2.setEnvelope(e2);
    List<GetLocationResult> list = new ArrayList<GetLocationResult>();
    list.add(glr1);
    list.add(glr2);

    CombineResultService cis = new CombineIntersectionService();
View Full Code Here

  }

  @Test
  public void testGetOneLocationShort() throws Exception {
    List<String> list = new ArrayList<String>();
    GetLocationResult result;

    list.clear();
    list.add("bla"); // needs to be "Booischot"
    result = service.getLocation(booischotShort, list);
    Assert.assertNull(result);
View Full Code Here

  }

  @Test
  public void testGetOneLocationNormal() throws Exception {
    List<String> list = new ArrayList<String>();
    GetLocationResult result;

    // one alternative with all details
    list.clear();
    list.add("belgium");
    list.add("antwerp");
View Full Code Here

  }

  @Test
  public void testGetOneLocationStrict() throws Exception {
    List<String> list = new ArrayList<String>();
    GetLocationResult result;

    // all details
    list.clear();
    list.add("België");
    list.add("Antwerpen");
View Full Code Here

TOP

Related Classes of org.geomajas.plugin.geocoder.api.GetLocationResult

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.