org.locationtech.jts.geom.Geometry.setUserData()方法的使用及代码示例

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

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

Geometry.setUserData介绍

[英]A simple scheme for applications to add their own custom data to a Geometry. An example use might be to add an object representing a Coordinate Reference System.

Note that user data objects are not present in geometries created by construction methods.
[中]应用程序向几何图形添加自己的自定义数据的简单方案。例如,可以添加表示坐标参照系的对象。
请注意,由构造方法创建的几何图形中不存在用户数据对象。

代码示例

代码示例来源:origin: geotools/geotools

public void setUserData(Object userData) {
  geometry.setUserData(userData);
}

代码示例来源:origin: geotools/geotools

/**
 *
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated modifiable
 */
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  // set the crs
  if (value instanceof Geometry) {
    CoordinateReferenceSystem crs = GML3ParsingUtils.crs(node);
    if (crs != null) {
      Geometry geometry = (Geometry) value;
      geometry.setUserData(crs);
    }
  }
  return value;
}

代码示例来源:origin: geotools/geotools

/**
 *
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated modifiable
 */
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  // set the crs
  if (value instanceof Geometry) {
    CoordinateReferenceSystem crs = GML3ParsingUtils.crs(node);
    if (crs != null) {
      Geometry geometry = (Geometry) value;
      geometry.setUserData(crs);
    }
  }
  return value;
}

代码示例来源:origin: geotools/geotools

public Geometry gml(Node root) {
  // look for the SRS name, if available
  Node srsNameNode = root.getAttributes().getNamedItem("srsName");
  CoordinateReferenceSystem crs = null;
  if (srsNameNode != null) {
    String srs = srsNameNode.getTextContent();
    try {
      crs = CRS.decode(srs);
    } catch (Exception e) {
      LOGGER.warning("Failed to parse the specified SRS " + srs);
    }
  }
  // parse the geometry
  Geometry g = _gml(root);
  // force the crs if necessary
  if (crs != null) {
    g.setUserData(crs);
  }
  return g;
}

代码示例来源:origin: geotools/geotools

@SuppressWarnings({"unchecked", "rawtypes"})
void setMetadata(Geometry g, String metadata, String value) {
  if (g.getUserData() == null) {
    g.setUserData(new HashMap());
  }
  if (g.getUserData() instanceof Map) {
    ((Map) g.getUserData()).put(metadata, value);
  }
}

代码示例来源:origin: geotools/geotools

g.setUserData(srsName);

代码示例来源:origin: geotools/geotools

g.setUserData(srsName);

代码示例来源:origin: geotools/geotools

/**
 *
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated modifiable
 */
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  if (value instanceof Geometry) {
    Geometry geometry = (Geometry) value;
    // &lt;attribute name="srsName" type="anyURI" use="optional"/&gt;
    if (node.hasAttribute("srsName")) {
      URI srs = (URI) node.getAttributeValue("srsName");
      CoordinateReferenceSystem crs = CRS.decode(srs.toString());
      if (crs != null) {
        geometry.setUserData(crs);
      } else {
        logger.warning("Could not create Coordinate Reference System for " + srs);
      }
    }
    // TODO: process the ID attribute
  }
  return value;
}

代码示例来源:origin: geotools/geotools

Geometry decodeGeometry(String s, GeometryFactory factory) throws IOException {
  if (s == null) {
    return null;
  }
  if (factory == null) {
    factory = new GeometryFactory();
  }
  String[] split = s.split(":");
  String srid = split[0];
  Geometry g = null;
  try {
    g = new WKTReader(factory).read(split[1]);
  } catch (ParseException e) {
    throw (IOException) new IOException().initCause(e);
  }
  if (srid != null && POSITIVE_NUMBER.matcher(srid).matches()) {
    CoordinateReferenceSystem crs;
    try {
      crs = CRS.decode("EPSG:" + srid);
    } catch (Exception e) {
      throw (IOException) new IOException().initCause(e);
    }
    g.setUserData(crs);
  }
  return g;
}

代码示例来源:origin: geotools/geotools

/** Helper method for setting the gml:id of a geometry as user data. */
protected void setGmlProperties(Geometry g, String gid, String name, String description) {
  // set up the user data
  Map userData = null;
  if (g.getUserData() != null) {
    if (g.getUserData() instanceof Map) {
      userData = (Map) g.getUserData();
    } else {
      userData = new HashMap();
      userData.put(g.getUserData().getClass(), g.getUserData());
    }
  } else {
    userData = new HashMap();
  }
  if (gid != null) {
    userData.put("gml:id", gid);
  }
  if (name != null) {
    userData.put("gml:name", name);
  }
  if (description != null) {
    userData.put("gml:description", description);
  }
  g.setUserData(userData);
}

代码示例来源:origin: geotools/geotools

protected void copyUserProperties(Geometry sourceGeometry, Geometry destGeometry) {
    // NC-added, copy userdata
    if (destGeometry != null) {
      Map<Object, Object> newUserData = new HashMap<Object, Object>();

      // copy if anything is already in destination data
      if (destGeometry.getUserData() instanceof Map) {
        newUserData.putAll((Map) destGeometry.getUserData());
      } else if (destGeometry.getUserData() instanceof CoordinateReferenceSystem) {
        newUserData.put(CoordinateReferenceSystem.class, destGeometry.getUserData());
      }
      // overwrite with source
      if (sourceGeometry.getUserData() instanceof Map) {
        newUserData.putAll((Map) sourceGeometry.getUserData());
      } else if (sourceGeometry.getUserData() instanceof CoordinateReferenceSystem) {
        newUserData.put(CoordinateReferenceSystem.class, sourceGeometry.getUserData());
      }

      destGeometry.setUserData(newUserData);
    }
  }
}

代码示例来源:origin: geotools/geotools

/** Helper method to reproject a geometry. */
protected Geometry reproject(Object value, CoordinateReferenceSystem propertyCrs) {
  if (value == null) {
    return null;
  }
  if (!(value instanceof Geometry))
    throw new IllegalArgumentException(
        "Binary geometry filter, but second expression "
            + "is not a geometry literal? (it's a "
            + value.getClass()
            + ")");
  Geometry geom = (Geometry) value;
  // does it make sense to proceed?
  if (geom.getUserData() == null
      || !(geom.getUserData() instanceof CoordinateReferenceSystem)) return geom;
  try {
    // reproject
    CoordinateReferenceSystem geomCRS = (CoordinateReferenceSystem) geom.getUserData();
    Geometry transformed =
        JTS.transform(geom, CRS.findMathTransform(geomCRS, propertyCrs, true));
    transformed.setUserData(propertyCrs);
    return transformed;
  } catch (Exception e) {
    throw new RuntimeException("Could not reproject geometry " + value, e);
  }
}

代码示例来源:origin: geotools/geotools

public Literal buildReferencedGeometryLiteral() throws CQLException {
  BuildResultStack resultStack = getResultStack();
  Literal literal = resultStack.popLiteral();
  int srid = resultStack.popIntegerValue();
  try {
    CoordinateReferenceSystem crs = CRS.decode("EPSG:" + srid);
    Geometry geometry = (Geometry) literal.getValue();
    geometry.setUserData(crs);
  } catch (FactoryException e) {
    throw new CQLException(
        "Failed to build CRS for SRID: " + srid, null, e, getStatement());
  }
  return literal;
}

代码示例来源:origin: geotools/geotools

geom.setUserData(newUserData);
target.setValue(geom);

代码示例来源:origin: geotools/geotools

geom.setUserData(crs);

代码示例来源:origin: geotools/geotools

((Geometry) value).setUserData(crs);

代码示例来源:origin: geotools/geotools

public Object visit(Literal expression, Object extraData) {
    if (!(expression.getValue() instanceof Geometry)) return super.visit(expression, extraData);

    // check if reprojection is needed
    Geometry geom = (Geometry) expression.getValue();
    if (geom.getUserData() != null && geom.getUserData() instanceof CoordinateReferenceSystem)
      return super.visit(expression, extraData);

    // clone the geometry and assign the new crs
    Geometry clone = geom.getFactory().createGeometry(geom);
    clone.setUserData(defaultCrs);

    // clone
    return ff.literal(clone);
  }
}

代码示例来源:origin: geotools/geotools

public void testLinearRingToCurve() throws Exception {
    Geometry ls = new WKTReader().read("LINEARRING(0 0, 10 10, 10 0, 0 0)");
    Map<String, String> userData = Collections.singletonMap("test", "value");
    ls.setUserData(userData);
    Converter converter = getConverter(ls, CurvedGeometry.class);
    CurvedGeometry curve = converter.convert(ls, CurvedGeometry.class);
    assertTrue(curve instanceof CompoundRing);
    CompoundRing cr = (CompoundRing) curve;
    assertEquals(1, cr.getComponents().size());
    assertEquals(ls, cr.getComponents().get(0));
    assertEquals(userData, cr.getUserData());
  }
}

代码示例来源:origin: geotools/geotools

@Test
  public void testCRSNested() throws Exception {
    WKTReader reader = new WKTReader();

    GeometryCollector collector = new GeometryCollector();
    collector.setFactory(null);
    final Geometry p0 = reader.read("MULTIPOINT(0 0, 1 1)");
    p0.setUserData(DefaultGeographicCRS.WGS84);
    collector.add(p0);
    final Geometry p1 = reader.read("MULTIPOINT(2 2, 3 3)");
    collector.add(p1);
    p1.setUserData(DefaultGeographicCRS.WGS84);

    GeometryCollection result = collector.collect();
    assertEquals(4, result.getNumGeometries());
    assertSame(DefaultGeographicCRS.WGS84, result.getUserData());
    assertEquals(reader.read("POINT(0 0)"), result.getGeometryN(0));
  }
}

代码示例来源:origin: geotools/geotools

@Test
public void testCRSSimple() throws Exception {
  WKTReader reader = new WKTReader();
  GeometryCollector collector = new GeometryCollector();
  collector.setFactory(null);
  final Geometry p0 = reader.read("POINT(0 0)");
  p0.setUserData(DefaultGeographicCRS.WGS84);
  collector.add(p0);
  final Geometry p1 = reader.read("POINT(1 1)");
  collector.add(p1);
  p1.setUserData(DefaultGeographicCRS.WGS84);
  GeometryCollection result = collector.collect();
  assertEquals(2, result.getNumGeometries());
  assertSame(DefaultGeographicCRS.WGS84, result.getUserData());
  assertSame(p0, result.getGeometryN(0));
  assertSame(p1, result.getGeometryN(1));
}

相关文章