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

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

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

Geometry.getUserData介绍

[英]Gets the user data object for this geometry, if any.
[中]获取此几何体的用户数据对象(如果有)。

代码示例

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

  1. CoordinateReferenceSystem crs = (CoordinateReferenceSystem) geometry.getUserData();

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

  1. /** @return The coordinate reference system of the feature, or null if not set. */
  2. public CoordinateReferenceSystem getCRS(Object geom) {
  3. if (crs != null) {
  4. return crs;
  5. } else if (geom != null && geom instanceof Geometry) {
  6. Object userData = ((Geometry) geom).getUserData();
  7. if (userData != null && userData instanceof CoordinateReferenceSystem) {
  8. return (CoordinateReferenceSystem) userData;
  9. }
  10. }
  11. return null;
  12. }

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

  1. public Object getUserData() {
  2. return geometry.getUserData();
  3. }

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

  1. @SuppressWarnings("rawtypes")
  2. String getMetadata(Geometry g, String metadata) {
  3. if (g.getUserData() instanceof Map) {
  4. Map userData = (Map) g.getUserData();
  5. return (String) userData.get(metadata);
  6. }
  7. return null;
  8. }

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

  1. /**
  2. * Determines the crs of the geometry by checking {@link Geometry#getUserData()}.
  3. *
  4. * <p>This method returns <code>null</code> when no crs can be found.
  5. */
  6. public static CoordinateReferenceSystem getCRS(Geometry g) {
  7. if (g.getUserData() == null) {
  8. return null;
  9. }
  10. if (g.getUserData() instanceof CoordinateReferenceSystem) {
  11. return (CoordinateReferenceSystem) g.getUserData();
  12. }
  13. if (g.getUserData() instanceof Map) {
  14. Map userData = (Map) g.getUserData();
  15. return (CoordinateReferenceSystem) userData.get(CoordinateReferenceSystem.class);
  16. }
  17. return null;
  18. }

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

  1. @SuppressWarnings({"unchecked", "rawtypes"})
  2. void setMetadata(Geometry g, String metadata, String value) {
  3. if (g.getUserData() == null) {
  4. g.setUserData(new HashMap());
  5. }
  6. if (g.getUserData() instanceof Map) {
  7. ((Map) g.getUserData()).put(metadata, value);
  8. }
  9. }

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

  1. public Object getProperty(Object object, QName name) throws Exception {
  2. if ("srsName".equals(name.getLocalPart())) {
  3. Geometry geometry = (Geometry) object;
  4. if (geometry.getUserData() instanceof CoordinateReferenceSystem) {
  5. return GML2EncodingUtils.crs((CoordinateReferenceSystem) geometry.getUserData());
  6. }
  7. }
  8. return null;
  9. }
  10. }

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

  1. private void initCRS(Geometry g) {
  2. // see if we have a native CRS in the mix
  3. if (crs == null && g.getUserData() instanceof CoordinateReferenceSystem) {
  4. crs = (CoordinateReferenceSystem) g.getUserData();
  5. }
  6. if (srid == -1 && g.getSRID() > 0) {
  7. srid = g.getSRID();
  8. }
  9. }
  10. }

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

  1. /** Get axisLabels for the geometry if set in app-schema mapping configuration. */
  2. public static String getAxisLabels(Geometry g) {
  3. Object userData = g.getUserData();
  4. if (userData != null && userData instanceof Map) {
  5. Object attributes = ((Map) userData).get(Attributes.class);
  6. if (attributes != null && attributes instanceof Map) {
  7. Name attribute = new NameImpl("axisLabels");
  8. Object axisLabels = ((Map) attributes).get(attribute);
  9. if (axisLabels != null) {
  10. return axisLabels.toString();
  11. }
  12. }
  13. }
  14. return null;
  15. }

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

  1. /** Get uomLabels for the geometry if set in app-schema mapping configuration. */
  2. public static String getUomLabels(Geometry g) {
  3. Object userData = g.getUserData();
  4. if (userData != null && userData instanceof Map) {
  5. Object attributes = ((Map) userData).get(Attributes.class);
  6. if (attributes != null && attributes instanceof Map) {
  7. Name attribute = new NameImpl("uomLabels");
  8. Object uomLabels = ((Map) attributes).get(attribute);
  9. if (uomLabels != null) {
  10. return uomLabels.toString();
  11. }
  12. }
  13. }
  14. return null;
  15. }

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

  1. @Override
  2. public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx)
  3. throws SQLException, IOException {
  4. String s = rs.getString(column);
  5. Geometry g = decodeGeometry(s, null);
  6. if (g == null) {
  7. return null;
  8. }
  9. return new ReferencedEnvelope(
  10. g.getEnvelopeInternal(), (CoordinateReferenceSystem) g.getUserData());
  11. }

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

  1. @Override
  2. public Object visit(Literal expression, Object extraData) {
  3. Object value = expression.getValue();
  4. if (value instanceof Geometry) {
  5. Geometry g = (Geometry) value;
  6. if (g.getUserData() instanceof CoordinateReferenceSystem) {
  7. return g.getUserData();
  8. } else if (g.getSRID() > 0) {
  9. try {
  10. return CRS.decode("EPSG:" + g.getSRID());
  11. } catch (Exception e) {
  12. return null;
  13. }
  14. }
  15. }
  16. return null;
  17. }

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

  1. private CoordinateReferenceSystem evaluateCRS(SimpleFeature originalFeature) {
  2. SimpleFeatureType originalSchema = originalFeature.getFeatureType();
  3. CoordinateReferenceSystem computedCRS = evaluateCRS(originalSchema);
  4. if (computedCRS == null) {
  5. // all right, let's try the sample feature then
  6. Geometry g = expression.evaluate(originalFeature, Geometry.class);
  7. if (g != null && g.getUserData() instanceof CoordinateReferenceSystem) {
  8. computedCRS = (CoordinateReferenceSystem) g.getUserData();
  9. } else {
  10. try {
  11. computedCRS = CRS.decode("EPSG:" + g.getSRID());
  12. } catch (Exception e) {
  13. return null;
  14. }
  15. }
  16. }
  17. return computedCRS;
  18. }

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

  1. public Object visit(Literal expression, Object extraData) {
  2. if (!(expression.getValue() instanceof Geometry)) return super.visit(expression, extraData);
  3. // check if reprojection is needed
  4. Geometry geom = (Geometry) expression.getValue();
  5. if (geom.getUserData() != null && geom.getUserData() instanceof CoordinateReferenceSystem)
  6. return super.visit(expression, extraData);
  7. // clone the geometry and assign the new crs
  8. Geometry clone = geom.getFactory().createGeometry(geom);
  9. clone.setUserData(defaultCrs);
  10. // clone
  11. return ff.literal(clone);
  12. }
  13. }

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

  1. @Test
  2. public void setCRSCode() throws Exception {
  3. Function f = ff.function("setCRS", ff.literal(g), ff.literal("EPSG:4326"));
  4. Geometry sg = (Geometry) f.evaluate(null);
  5. assertEquals(CRS.decode("EPSG:4326"), sg.getUserData());
  6. }

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

  1. @Test
  2. public void testPreserveOriginalSRS() throws NoSuchAuthorityCodeException, FactoryException {
  3. String srs = "AUTO:42004,9001,0,33";
  4. CoordinateReferenceSystem crs = CRS.decode(srs);
  5. BBOX bbox = ff.bbox(ff.property(""), 0, 1000, 2000, 3000, srs);
  6. Geometry geom = bbox.getExpression2().evaluate(null, Geometry.class);
  7. assertEquals(crs, geom.getUserData());
  8. assertEquals(srs, bbox.getSRS());
  9. }
  10. }

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

  1. @Test
  2. public void force3DCRS2DEnvelope() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
  4. CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
  5. BBOX bbox = ff.bbox("the_geom", -180, -90, 180, 90, null);
  6. DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
  7. BBOX filtered = (BBOX) bbox.accept(visitor, null);
  8. Literal box = (Literal) filtered.getExpression2();
  9. Geometry g = (Geometry) box.evaluate(null);
  10. assertEquals(hcrs, g.getUserData());
  11. }

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

  1. @Test
  2. public void setCRSObject() {
  3. Function f = ff.function("setCRS", ff.literal(g), ff.literal(DefaultGeographicCRS.WGS84));
  4. Geometry sg = (Geometry) f.evaluate(null);
  5. assertEquals(DefaultGeographicCRS.WGS84, sg.getUserData());
  6. }

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

  1. @Test
  2. public void force3DCRS3DEnvelope() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
  4. CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
  5. BBOX bbox =
  6. ff.bbox(
  7. ff.property("the_geom"),
  8. new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null));
  9. DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
  10. BBOX filtered = (BBOX) bbox.accept(visitor, null);
  11. Literal box = (Literal) filtered.getExpression2();
  12. Geometry g = (Geometry) box.evaluate(null);
  13. assertEquals(crs, g.getUserData());
  14. }
  15. }

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

  1. @Test
  2. public void setCRSWkt() {
  3. Function f =
  4. ff.function(
  5. "setCRS", ff.literal(g), ff.literal(DefaultGeographicCRS.WGS84.toWKT()));
  6. Geometry sg = (Geometry) f.evaluate(null);
  7. assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, sg.getUserData()));
  8. }
  9. }

相关文章