org.geotools.feature.Feature.setAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(409)

本文整理了Java中org.geotools.feature.Feature.setAttribute()方法的一些代码示例,展示了Feature.setAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Feature.setAttribute()方法的具体详情如下:
包路径:org.geotools.feature.Feature
类名称:Feature
方法名:setAttribute

Feature.setAttribute介绍

[英]Sets an attribute by the given zero-based index. This index is based on the values within the Feature as opposed to the AttributeType declaration. To get the values for the 5th attributeType, use the schema to determine the xPath and class the setAttribute(xPath,val) method.
[中]通过给定的从零开始的索引设置属性。此索引基于功能中的值,而不是AttributeType声明。要获取第5个attributeType的值,请使用模式确定xPath并对setAttribute(xPath,val)方法进行分类。

代码示例

代码示例来源:origin: org.geotools/gt2-xml-xsd

public void setValue(Object value) {
  if ( index == -1 )
    return; //fids arent settable
  
  try {
    feature.setAttribute( index, value );
  } 
  catch( Exception e ) {
    throw new RuntimeException( e );
  }
}

代码示例来源:origin: org.geotools/gt2-xml-core

public void setValue(Object value) {
  if (index == -1) {
    return; //fids arent settable
  }
  try {
    feature.setAttribute(index, value);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.geotools/gt2-xml-core

public void setProperty(Object object, String property, Object value) {
  Feature feature = (Feature) object;
  try {
    feature.setAttribute(property(property), value);
  } catch (IllegalAttributeException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.geotools/gt2-xml-xsd

public void setProperty(Object object, String property, Object value) {
  Feature feature = (Feature) object;
  try {
    feature.setAttribute( property( property ), value );
  } 
  catch (IllegalAttributeException e) {
    throw new RuntimeException( e );
  }
}

代码示例来源:origin: org.geotools/gt2-main

public void set(Object object, String xpath, Object value, Class target)
      throws IllegalAttributeException {
    xpath = stripPrefix(xpath);
    
    if ( object instanceof Feature ) {
      ((Feature) object).setAttribute( xpath, value );
    }
    
    if ( object instanceof FeatureType ) {
      throw new IllegalAttributeException("feature type is immutable");    
    }
    
  }
}

代码示例来源:origin: org.geotools/gt2-main

f.setAttribute(childName,value);

代码示例来源:origin: org.geotools/gt2-postgis-versioned

public String createID(Connection conn, Feature feature, Statement statement)
    throws IOException {
  if (feature.getAttribute(colNames[1]) == null) {
    try {
      String id = autoIncrementMapper.createID(conn, feature, statement);
      feature.setAttribute(colNames[1], new Long(id));
    } catch (Exception e) {
      throw new DataSourceException("Could not generate key for the "
          + "unset primary key column " + colNames[1], e);
    }
  }
  return super.createID(conn, feature, statement);
}

代码示例来源:origin: org.geotools/gt2-postgis-versioned

writer = wrapped.getFeatureWriterAppend(VersionedPostgisDataStore.TBL_CHANGESETS, t);
f = writer.next();
f.setAttribute("author", author);
f.setAttribute("message", message);
f.setAttribute("date", new Date());

代码示例来源:origin: org.geotools/gt2-postgis-versioned

public String createID(Connection conn, Feature feature, Statement statement)
    throws IOException {
  if (colNames.length == 2 && feature.getAttribute(colNames[1]) == null) {
    try {
      feature.setAttribute(colNames[1], (new UID()).toString());
    } catch (IllegalAttributeException e) {
      throw new DataSourceException("Could not generate key for the "
          + "unset primary key column " + colNames[0], e);
    }
  }
  return super.createID(conn, feature, statement);
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-gis

currentFeature_.setAttribute(gmlInput_.columnName(index), l);
currentFeature_.setAttribute(gmlInput_.columnName(index),

代码示例来源:origin: org.geotools/gt2-postgis-versioned

private void writeOldFeature(boolean expire) throws IOException, DataSourceException {
  try {
    if(expire)
      oldFeature.setAttribute("expired", new Long(state.getRevision()));
    updateWriter.write();
  } catch (IllegalAttributeException e) {
    throw new DataSourceException("Error writing expiration tag on old feature. "
        + "Should not happen, there's a bug at work.", e);
  } catch (FeatureLockException fle) {
    // we have to mangle the id here too
    String unversionedFid = mapper.getUnversionedFid(fle.getFeatureID());
    FeatureLockException mangled = new FeatureLockException(fle.getMessage(),
        unversionedFid, fle.getCause());
    throw mangled;
  }
}

代码示例来源:origin: org.geotools/gt2-main

newFeature.setAttribute( a, values[a] );

代码示例来源:origin: org.geotools/gt2-main

public void testGetFeaturesWriterModify()
  throws IOException, IllegalAttributeException {
  FeatureWriter writer = data.getFeatureWriter("ROAD",
      Transaction.AUTO_COMMIT);
  Feature feature;
  while (writer.hasNext()) {
    feature = writer.next();
    if (feature.getID().equals(roadFeatures[0].getID())) {
      feature.setAttribute("NAME", "changed");
      writer.write();
    }
  }
  feature = null;
  FeatureReader reader = data.getFeatureReader(new DefaultQuery("ROAD",
        rd1Filter), Transaction.AUTO_COMMIT);
  if (reader.hasNext()) {
    feature = reader.next();
  }
  //        feature = (Feature) data.features("ROAD").get("road.rd1");
  assertEquals("changed", feature.getAttribute("NAME"));
}

代码示例来源:origin: org.geotools/gt2-jdbc

protected void modifyFeatures( AttributeType[] type, Object[] value, FeatureWriter writer ) throws DataSourceException, IOException{
  Feature feature;        
  try {
    while (writer.hasNext()) {
      feature = writer.next();
      for (int i = 0; i < type.length; i++) {
        try {
          feature.setAttribute(type[i].getName(), value[i]);
        } catch (IllegalAttributeException e) {
          throw new DataSourceException(
            "Could not update feature " + feature.getID()
            + " with " + type[i].getName() + "=" + value[i], e);
        }
      }
      writer.write();
    }
  } finally {
    writer.close();
  }        
}
/**

代码示例来源:origin: org.geotools/gt2-main

/**
 * Applies transform to all geometry attribute.
 * 
 * @param feature Feature to be transformed
 * @param schema Schema for target transformation - transform( schema, crs )
 * @param transform MathTransform used to transform coordinates - reproject( crs, crs )
 * @return transformed Feature of type schema
 * @throws TransformException
 * @throws MismatchedDimensionException
 * @throws IllegalAttributeException
 */
public static Feature transform( Feature feature, FeatureType schema, MathTransform transform )
    throws MismatchedDimensionException, TransformException, IllegalAttributeException {
  feature = schema.create(feature.getAttributes(null), feature.getID());
  GeometryAttributeType geomType = schema.getDefaultGeometry();
  Geometry geom = (Geometry) feature.getAttribute(geomType.getName());
  geom = JTS.transform(geom, transform);
  try {
    feature.setAttribute(geomType.getName(), geom);
  } catch (IllegalAttributeException shouldNotHappen) {
    // we are expecting the transform to return the same geometry type
  }
  return feature;
}

代码示例来源:origin: org.geotools/gt2-postgis-versioned

Object newValue = liveFeature.getAttribute(at.getName());
  Object oldValue = oldFeature.getAttribute(at.getName());
  newFeature.setAttribute(at.getName(), newValue);
  if (!DataUtilities.attributesEqual(newValue, oldValue)) {
    dirty = true;
  oldFeature.setAttribute(at.getName(), liveFeature.getAttribute(at.getName()));
  newFeature.setAttribute(at.getName(), liveFeature.getAttribute(at.getName()));
newFeature.setAttribute("expired", NON_EXPIRED);
newFeature.setAttribute("revision", new Long(state.getRevision()));
  newFeature.setAttribute("created", oldFeature.getAttribute("created"));
} else {
  newFeature.setAttribute("created", new Long(state.getRevision()));
if (oldFeature != null) {
  id = mapper.createVersionedFid(liveFeature.getID(), state.getRevision()); 
  newFeature.setAttribute("created", oldFeature.getAttribute("created"));
} else if (!mapper.hasAutoIncrementColumns()) {
  id = mapper.createID(state.getConnection(), newFeature, null);
  newFeature.setAttribute("created", new Long(state.getRevision()));
    newFeature.setAttribute(mapper.getColumnName(i), pkatts[i]);

代码示例来源:origin: org.geotools/gt2-postgis-versioned

Feature restored = fw.next();
for (int i = 0; i < original.getFeatureType().getAttributeCount(); i++) {
  restored.setAttribute(i, original.getAttribute(i));
restored.setAttribute("revision", new Long(revision));
restored.setAttribute("expired", new Long(Long.MAX_VALUE));
fw.write();
Feature original = fr.next();
for (int i = 0; i < original.getFeatureType().getAttributeCount(); i++) {
  current.setAttribute(i, original.getAttribute(i));

代码示例来源:origin: org.geotools/gt2-main

public void testGetFeatureReaderMutability()
  throws IOException, IllegalAttributeException {
  Query query = new DefaultQuery(roadType.getTypeName());
  FeatureReader reader = data.getFeatureReader(query,
      Transaction.AUTO_COMMIT);
  Feature feature;
  while (reader.hasNext()) {
    feature = (Feature) reader.next();
    feature.setAttribute("NAME", null);
  }
  reader.close();
  reader = data.getFeatureReader(query, Transaction.AUTO_COMMIT);
  while (reader.hasNext()) {
    feature = (Feature) reader.next();
    assertNotNull(feature.getAttribute("NAME"));
  }
  reader.close();
  try {
    reader.next();
    fail(
      "next should fail with an IOException or NoSuchElementException");
  } catch (IOException expected) {
  } catch (NoSuchElementException expected) {
  }
}

代码示例来源:origin: org.geotools/gt2-main

feature.setAttribute(type[i].getName(), value[i]);
} catch (IllegalAttributeException e) {
  throw new DataSourceException(

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-gis

feature.setDefaultGeometry(_zone.getGeometry(i));
for (int j = 1; j < nbAttribute; j++) {
 feature.setAttribute(j, _zone.getModel(attIdx.get(atts[j])).getObjectValueAt(i));

相关文章