本文整理了Java中org.locationtech.jts.geom.Geometry.getUserData()
方法的一些代码示例,展示了Geometry.getUserData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getUserData()
方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getUserData
[英]Gets the user data object for this geometry, if any.
[中]获取此几何体的用户数据对象(如果有)。
代码示例来源:origin: geoserver/geoserver
CoordinateReferenceSystem crs = (CoordinateReferenceSystem) geometry.getUserData();
代码示例来源:origin: geotools/geotools
/** @return The coordinate reference system of the feature, or null if not set. */
public CoordinateReferenceSystem getCRS(Object geom) {
if (crs != null) {
return crs;
} else if (geom != null && geom instanceof Geometry) {
Object userData = ((Geometry) geom).getUserData();
if (userData != null && userData instanceof CoordinateReferenceSystem) {
return (CoordinateReferenceSystem) userData;
}
}
return null;
}
代码示例来源:origin: geotools/geotools
public Object getUserData() {
return geometry.getUserData();
}
代码示例来源:origin: geotools/geotools
@SuppressWarnings("rawtypes")
String getMetadata(Geometry g, String metadata) {
if (g.getUserData() instanceof Map) {
Map userData = (Map) g.getUserData();
return (String) userData.get(metadata);
}
return null;
}
代码示例来源:origin: geotools/geotools
/**
* Determines the crs of the geometry by checking {@link Geometry#getUserData()}.
*
* <p>This method returns <code>null</code> when no crs can be found.
*/
public static CoordinateReferenceSystem getCRS(Geometry g) {
if (g.getUserData() == null) {
return null;
}
if (g.getUserData() instanceof CoordinateReferenceSystem) {
return (CoordinateReferenceSystem) g.getUserData();
}
if (g.getUserData() instanceof Map) {
Map userData = (Map) g.getUserData();
return (CoordinateReferenceSystem) userData.get(CoordinateReferenceSystem.class);
}
return null;
}
代码示例来源: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
public Object getProperty(Object object, QName name) throws Exception {
if ("srsName".equals(name.getLocalPart())) {
Geometry geometry = (Geometry) object;
if (geometry.getUserData() instanceof CoordinateReferenceSystem) {
return GML2EncodingUtils.crs((CoordinateReferenceSystem) geometry.getUserData());
}
}
return null;
}
}
代码示例来源:origin: geotools/geotools
private void initCRS(Geometry g) {
// see if we have a native CRS in the mix
if (crs == null && g.getUserData() instanceof CoordinateReferenceSystem) {
crs = (CoordinateReferenceSystem) g.getUserData();
}
if (srid == -1 && g.getSRID() > 0) {
srid = g.getSRID();
}
}
}
代码示例来源:origin: geotools/geotools
/** Get axisLabels for the geometry if set in app-schema mapping configuration. */
public static String getAxisLabels(Geometry g) {
Object userData = g.getUserData();
if (userData != null && userData instanceof Map) {
Object attributes = ((Map) userData).get(Attributes.class);
if (attributes != null && attributes instanceof Map) {
Name attribute = new NameImpl("axisLabels");
Object axisLabels = ((Map) attributes).get(attribute);
if (axisLabels != null) {
return axisLabels.toString();
}
}
}
return null;
}
代码示例来源:origin: geotools/geotools
/** Get uomLabels for the geometry if set in app-schema mapping configuration. */
public static String getUomLabels(Geometry g) {
Object userData = g.getUserData();
if (userData != null && userData instanceof Map) {
Object attributes = ((Map) userData).get(Attributes.class);
if (attributes != null && attributes instanceof Map) {
Name attribute = new NameImpl("uomLabels");
Object uomLabels = ((Map) attributes).get(attribute);
if (uomLabels != null) {
return uomLabels.toString();
}
}
}
return null;
}
代码示例来源:origin: geotools/geotools
@Override
public Envelope decodeGeometryEnvelope(ResultSet rs, int column, Connection cx)
throws SQLException, IOException {
String s = rs.getString(column);
Geometry g = decodeGeometry(s, null);
if (g == null) {
return null;
}
return new ReferencedEnvelope(
g.getEnvelopeInternal(), (CoordinateReferenceSystem) g.getUserData());
}
代码示例来源:origin: geotools/geotools
@Override
public Object visit(Literal expression, Object extraData) {
Object value = expression.getValue();
if (value instanceof Geometry) {
Geometry g = (Geometry) value;
if (g.getUserData() instanceof CoordinateReferenceSystem) {
return g.getUserData();
} else if (g.getSRID() > 0) {
try {
return CRS.decode("EPSG:" + g.getSRID());
} catch (Exception e) {
return null;
}
}
}
return null;
}
代码示例来源:origin: geotools/geotools
private CoordinateReferenceSystem evaluateCRS(SimpleFeature originalFeature) {
SimpleFeatureType originalSchema = originalFeature.getFeatureType();
CoordinateReferenceSystem computedCRS = evaluateCRS(originalSchema);
if (computedCRS == null) {
// all right, let's try the sample feature then
Geometry g = expression.evaluate(originalFeature, Geometry.class);
if (g != null && g.getUserData() instanceof CoordinateReferenceSystem) {
computedCRS = (CoordinateReferenceSystem) g.getUserData();
} else {
try {
computedCRS = CRS.decode("EPSG:" + g.getSRID());
} catch (Exception e) {
return null;
}
}
}
return computedCRS;
}
代码示例来源: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
@Test
public void setCRSCode() throws Exception {
Function f = ff.function("setCRS", ff.literal(g), ff.literal("EPSG:4326"));
Geometry sg = (Geometry) f.evaluate(null);
assertEquals(CRS.decode("EPSG:4326"), sg.getUserData());
}
代码示例来源:origin: geotools/geotools
@Test
public void testPreserveOriginalSRS() throws NoSuchAuthorityCodeException, FactoryException {
String srs = "AUTO:42004,9001,0,33";
CoordinateReferenceSystem crs = CRS.decode(srs);
BBOX bbox = ff.bbox(ff.property(""), 0, 1000, 2000, 3000, srs);
Geometry geom = bbox.getExpression2().evaluate(null, Geometry.class);
assertEquals(crs, geom.getUserData());
assertEquals(srs, bbox.getSRS());
}
}
代码示例来源:origin: geotools/geotools
@Test
public void force3DCRS2DEnvelope() throws Exception {
CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
BBOX bbox = ff.bbox("the_geom", -180, -90, 180, 90, null);
DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
BBOX filtered = (BBOX) bbox.accept(visitor, null);
Literal box = (Literal) filtered.getExpression2();
Geometry g = (Geometry) box.evaluate(null);
assertEquals(hcrs, g.getUserData());
}
代码示例来源:origin: geotools/geotools
@Test
public void setCRSObject() {
Function f = ff.function("setCRS", ff.literal(g), ff.literal(DefaultGeographicCRS.WGS84));
Geometry sg = (Geometry) f.evaluate(null);
assertEquals(DefaultGeographicCRS.WGS84, sg.getUserData());
}
代码示例来源:origin: geotools/geotools
@Test
public void force3DCRS3DEnvelope() throws Exception {
CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
BBOX bbox =
ff.bbox(
ff.property("the_geom"),
new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null));
DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
BBOX filtered = (BBOX) bbox.accept(visitor, null);
Literal box = (Literal) filtered.getExpression2();
Geometry g = (Geometry) box.evaluate(null);
assertEquals(crs, g.getUserData());
}
}
代码示例来源:origin: geotools/geotools
@Test
public void setCRSWkt() {
Function f =
ff.function(
"setCRS", ff.literal(g), ff.literal(DefaultGeographicCRS.WGS84.toWKT()));
Geometry sg = (Geometry) f.evaluate(null);
assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, sg.getUserData()));
}
}
内容来源于网络,如有侵权,请联系作者删除!