Beispiel #1
0
 /**
  * Returns the VPFFile for a particular column. It will only find the first match, but that should
  * be okay because duplicate columns will cause even bigger problems elsewhere.
  *
  * @param column the column to search for
  * @return the VPFFile that owns this column
  */
 private VPFFile getVPFFile(VPFColumn column) {
   String columnName = column.getName();
   VPFFile result = null;
   VPFFile temp;
   Iterator<VPFFile> iter = featureType.getFeatureClass().getFileList().iterator();
   while (iter.hasNext()) {
     temp = (VPFFile) iter.next();
     if ((temp != null) && (temp.getColumn(columnName) != null)) {
       result = temp;
       break;
     }
   }
   return result;
 }
Beispiel #2
0
  /**
   * Get the values from all of the columns based on their presence (or absense) in the rows
   *
   * <p>Potential cases: simple column join column non-matching join null value geometry
   *
   * @param file the file
   * @param row the row
   */
  private void retrieveObject(VPFFile file, SimpleFeature row) throws IOException {
    VPFFile secondFile = null;
    VPFColumn column = null;
    Map rows = generateFileRowMap(file, row);
    List<AttributeDescriptor> attributes = featureType.getFeatureClass().getAttributeDescriptors();
    Object[] values = new Object[featureType.getAttributeCount()];
    Object value = null;
    String featureId = null;
    // Pass 1 - identify the feature identifier
    for (int inx = 0; inx < attributes.size(); inx++) {
      // I am thinking it is probably safer to look this up
      // by column name than by position, but if it breaks,
      // it is easy enough to change
      if (attributes.get(inx).getLocalName().equals("id")) {
        value = row.getAttribute(inx);
        if (value != null) {
          featureId = value.toString();
        }
        break;
      }
    }
    try {
      currentFeature = SimpleFeatureBuilder.build(featureType, values, featureId);
    } catch (IllegalAttributeException exc) {
      // This shouldn't happen since everything should be nillable
      exc.printStackTrace();
    }

    // Pass 2 - get the attributes, including the geometry
    for (int inx = 0; inx < attributes.size(); inx++) {
      try {
        if (attributes
            .get(inx)
            .getLocalName()
            .equals(AnnotationFeatureType.ANNOTATION_ATTRIBUTE_NAME)) {
          try {
            // TODO: are we sure this is the intended action? Hard-coding an attribute to "nam"?
            currentFeature.setAttribute(inx, "nam");
          } catch (IllegalAttributeException exc) {
            exc.printStackTrace();
          }
          continue;
        }
        column = (VPFColumn) attributes.get(inx);
        value = null;
        secondFile = getVPFFile(column);
        SimpleFeature tempRow = (SimpleFeature) rows.get(secondFile);
        if (tempRow != null) {
          value = tempRow.getAttribute(column.getName());
          if (column.isAttemptLookup()) {
            try {
              // Attempt to perform a lookup and conversion
              String featureClassName = getVPFFile(column).getFileName();
              String intVdtFileName =
                  featureType
                      .getFeatureClass()
                      .getDirectoryName()
                      .concat(File.separator)
                      .concat("int.vdt");
              VPFFile intVdtFile = VPFFileFactory.getInstance().getFile(intVdtFileName);
              Iterator intVdtIter = intVdtFile.readAllRows().iterator();
              while (intVdtIter.hasNext()) {
                SimpleFeature intVdtRow = (SimpleFeature) intVdtIter.next();
                if (intVdtRow.getAttribute("table").toString().trim().equals(featureClassName)
                    && (Short.parseShort(intVdtRow.getAttribute("value").toString())
                            == Short.parseShort(value.toString())
                        && (intVdtRow
                            .getAttribute("attribute")
                            .toString()
                            .trim()
                            .equals(column.getName())))) {
                  value = intVdtRow.getAttribute("description").toString().trim();
                  break;
                }
              }
              // If there is a problem, forget about mapping and continue
            } catch (IOException exc) {
            } catch (RuntimeException exc) {
            }
          }
        }
        try {
          currentFeature.setAttribute(inx, value);
        } catch (ArrayIndexOutOfBoundsException exc) {
          // TODO Auto-generated catch block
          exc.printStackTrace();
        } catch (IllegalAttributeException exc) {
          // TODO Auto-generated catch block
          exc.printStackTrace();
        }
      } catch (ClassCastException exc2) {
        try {
          // This is the area geometry case
          featureType
              .getFeatureClass()
              .getGeometryFactory()
              .createGeometry(featureType, currentFeature);
        } catch (IllegalAttributeException exc) {
          // TODO Auto-generated catch block
          exc.printStackTrace();
        } catch (SQLException exc) {
          // TODO Auto-generated catch block
          exc.printStackTrace();
        }
      }
    }
  }