Esempio n. 1
0
  public List<OGRFeature> listByExtentTypeCountry(
      Double x1,
      Double y1,
      String countryCode,
      String orderByCol,
      String orderByDirection,
      String cursorString) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(OGRFeature.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();

    appendNonNullParam("x1", filterString, paramString, "Double", x1, paramMap, LTE_OP);
    appendNonNullParam(
        "featureType",
        filterString,
        paramString,
        "String",
        FeatureType.SUB_COUNTRY_OTHER,
        paramMap,
        EQ_OP);
    appendNonNullParam(
        "countryCode", filterString, paramString, "String", countryCode, paramMap, EQ_OP);

    query.setFilter(filterString.toString());
    query.declareParameters(paramString.toString());

    if (orderByCol != null && orderByDirection != null)
      query.setOrdering(orderByCol + " " + orderByDirection);

    prepareCursor(cursorString, query);
    @SuppressWarnings("unchecked")
    List<OGRFeature> resultsGTE = (List<OGRFeature>) query.executeWithMap(paramMap);
    List<OGRFeature> results = new ArrayList<OGRFeature>();
    for (OGRFeature item : resultsGTE) {
      Double[] boundingBox = item.getBoundingBox();
      if (boundingBox[0] < x1
          && boundingBox[1] > y1
          && boundingBox[2] > x1
          && boundingBox[3] < y1) {
        results.add(item);
      }
    }

    return results;
  }
Esempio n. 2
0
  public OGRFeature save(OGRFeature item) {
    // If type == country then must update can't have 2 shapes for 1 country
    if (item.getFeatureType().equals(FeatureType.COUNTRY)) {
      OGRFeature existingItem = findByCountryAndType(item.getCountryCode(), FeatureType.COUNTRY);
      if (existingItem != null) {
        existingItem.setGeometry(item.getGeometry());
        existingItem.setBoundingBox(item.getBoundingBox());
        super.save(existingItem);
        item = existingItem;
      } else {
        super.save(item);
      }
      // Save to country table as well so that we have populated it
      CountryDao countryDao = new CountryDao();
      Country country = countryDao.findByCode(item.getCountryCode());
      if (country == null) {
        country = new Country();
        country.setName(item.getName());
        country.setDisplayName(item.getName());
        country.setCentroidLat(item.getCentroidLat());
        country.setCentroidLon(item.getCentroidLon());
        country.setIsoAlpha2Code(item.getCountryCode());
        countryDao.save(country);
      } else if (country.getName() == null || country.getDisplayName() == null) {
        country.setName(item.getName());
        country.setDisplayName(item.getName());
        countryDao.save(country);
      }
      return item;
    } else {
      ArrayList<String> subList = new ArrayList<String>();
      if (item.getSub1() != null) {
        subList.add(item.getSub1());
      }
      if (item.getSub2() != null) {
        subList.add(item.getSub2());
      }
      if (item.getSub3() != null) {
        subList.add(item.getSub3());
      }
      if (item.getSub4() != null) {
        subList.add(item.getSub4());
      }
      if (item.getSub5() != null) {
        subList.add(item.getSub5());
      }
      if (item.getSub6() != null) {
        subList.add(item.getSub6());
      }

      OGRFeature existingItem =
          findByCountryTypeAndSub(
              item.getCountryCode(), item.getName(), FeatureType.SUB_COUNTRY_OTHER, subList);
      if (existingItem != null) {
        boolean isSame = true;
        if (item.getSub1() != null
            && existingItem.getSub1() != null
            && !existingItem.getSub1().equals(item.getSub1())) {
          isSame = false;
        }
        if ((item.getSub2() != null
                && existingItem.getSub2() != null
                && !existingItem.getSub2().equals(item.getSub2()))
            || (item.getSub2() == null && existingItem.getSub2() != null)) {
          isSame = false;
        }
        if (item.getSub3() != null
            && existingItem.getSub3() != null
            && !existingItem.getSub3().equals(item.getSub3())) {
          isSame = false;
        }
        if (item.getSub4() != null
            && existingItem.getSub4() != null
            && !existingItem.getSub4().equals(item.getSub4())) {
          isSame = false;
        }
        if (item.getSub5() != null
            && existingItem.getSub5() != null
            && !existingItem.getSub5().equals(item.getSub5())) {
          isSame = false;
        }
        if (item.getSub6() != null
            && existingItem.getSub6() != null
            && !existingItem.getSub6().equals(item.getSub6())) {
          isSame = false;
        }
        if (isSame) {
          existingItem.setGeometry(item.getGeometry());
          existingItem.setBoundingBox(item.getBoundingBox());
          existingItem.setCentroidLat(item.getCentroidLat());
          existingItem.setCentroidLon(item.getCentroidLon());
          super.save(existingItem);
          return existingItem;
        }
      }
      super.save(item);
      return item;
    }
  }