Package org.geonames

Examples of org.geonames.Toponym


      searchObj.setMaxRows(1);
      searchObj.setQ(searchString);
      logger.debug("search criteria: " + searchObj);
      ToponymSearchResult result = WebService.search(searchObj);
      if (result != null && result.getTotalResultsCount() > 0) {
        Toponym topo = result.getToponyms().get(0);
        geo = new Geo(topo.getLatitude(), topo.getLongitude());
      }
    } catch (Exception e) {
      logger.debug("search geo failed: original geoString=" + geoString
          + ", actual searchString=" + searchString, e);
    }
View Full Code Here


      removeDuplicates(toponyms);
      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) {
View Full Code Here

    }
  }

  private void removeDuplicates(List<Toponym> toponyms) {
    for (int pos = 0; pos < toponyms.size(); pos++) {
      Toponym left = toponyms.get(pos);
      for (int sec = toponyms.size() - 1; sec > pos; sec--) {
        Toponym right = toponyms.get(sec);
        if (ObjectUtils.nullSafeEquals(left.getName(), right.getName())
            && ObjectUtils.nullSafeEquals(left.getCountryCode(), right.getCountryCode())
            && Math.abs(left.getLongitude() - right.getLongitude()) < DELTA
            && Math.abs(left.getLatitude() - right.getLatitude()) < DELTA) {
          toponyms.remove(sec);
        }
      }
    }
  }
View Full Code Here

        throw new Exception(message.getAttributeValue("message"));
      }

      for (Object obj : root.getChildren("geoname")) {
        Element toponymElement = (Element) obj;
        Toponym toponym = getToponymFromElement(toponymElement);
        searchResult.add(toponym);
      }
    }
    return searchResult;
  }
View Full Code Here

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

  private Toponym getToponymFromElement(Element toponymElement) {
    Toponym toponym = new Toponym();

    toponym.setName(toponymElement.getChildText("name"));
    toponym.setAlternateNames(toponymElement.getChildText("alternateNames"));
    toponym.setLatitude(Double.parseDouble(toponymElement.getChildText("lat")));
    toponym.setLongitude(Double.parseDouble(toponymElement.getChildText("lng")));

    toponym.setCountryCode(toponymElement.getChildText("countryCode"));
    toponym.setCountryName(toponymElement.getChildText("countryName"));

    toponym.setFeatureClass(FeatureClass.fromValue(toponymElement.getChildText("fcl")));
    toponym.setFeatureCode(toponymElement.getChildText("fcode"));

    toponym.setFeatureClassName(toponymElement.getChildText("fclName"));
    toponym.setFeatureCodeName(toponymElement.getChildText("fCodeName"));

    return toponym;
  }
View Full Code Here

TOP

Related Classes of org.geonames.Toponym

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.