writer.endNode(); writer.startNode("type"); writer.setValue(Geometries.getForBinding(vt.getGeometryType(geom)).getName()); writer.endNode(); writer.startNode("srid");
if (reader.getNodeName().equals("name")) geomName = reader.getValue(); else if (reader.getNodeName().equals("type")) { Geometries geomType = Geometries.getForName(reader.getValue()); type = geomType == null ? Geometry.class : geomType.getBinding(); } else if (reader.getNodeName().equals("srid")) { srid = Converters.convert(reader.getValue(), Integer.class);
@Override public String getGeometryTypeName(Integer type) { return Geometries.getForSQLType(type).getName(); }
/** * Get the {@code Geometries} for the specified name. * * @param name The name of the geometry, eg: "POINT" * @return The constant for the name. */ public static Geometries getForName(String name) { for (Geometries gt : Geometries.values()) { if (gt.getName().equalsIgnoreCase(name)) { return gt; } } return null; }
/** * Get the {@code Geometries} for the given object. * * @param geom a JTS Geometry object * @return the {@code Geometries} for the argument's class, or {@code null} if the argument is * {@code null} */ public static Geometries get(Geometry geom) { if (geom != null) { return getForBinding(geom.getClass()); } return null; }
/** Tests getName and getSimpleName */ @Test public void testGetName() { // System.out.println(" getName and getSimpleName"); for (Geometries type : Geometries.values()) { String className = type.getBinding().getSimpleName(); assertTrue(type.getName().equalsIgnoreCase(className)); if (className.startsWith("Multi")) { assertTrue(type.getSimpleName().equalsIgnoreCase(className.substring(5))); } else { assertTrue(type.getSimpleName().equalsIgnoreCase(className)); } } }
throw new IllegalArgumentException("Invalid geometry type: " + geomType.getName());
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // add geometry mappings for (Geometries g : Geometries.values()) { mappings.put(g.getBinding(), g.getSQLType()); } // override some internal defaults mappings.put(Long.class, Types.INTEGER); mappings.put(Double.class, Types.REAL); mappings.put(Boolean.class, Types.INTEGER); }
@Test public void testGetForSQLType() { // System.out.println(" getSQLType and getForSQLType"); for (Geometries type : Geometries.values()) { int sqlType = type.getSQLType(); assertEquals(type, Geometries.getForSQLType(sqlType)); } } }
FeatureEntry createFeatureEntry(ResultSet rs) throws SQLException, IOException { FeatureEntry e = new FeatureEntry(); initEntry(e, rs); e.setGeometryColumn(rs.getString("column_name")); e.setGeometryType(Geometries.getForName(rs.getString("geometry_type_name"))); e.setZ(rs.getBoolean("z")); e.setM(rs.getBoolean("m")); return e; }
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); mappings.put( Geometries.POINT.getBinding(), Geometries.POINT.getSQLType() ); mappings.put( Geometries.LINESTRING.getBinding(), Geometries.LINESTRING.getSQLType() ); mappings.put( Geometries.POLYGON.getBinding(), Geometries.POLYGON.getSQLType() ); mappings.put( Geometries.MULTIPOINT.getBinding(), Geometries.MULTIPOINT.getSQLType() ); mappings.put( Geometries.MULTILINESTRING.getBinding(), Geometries.MULTILINESTRING.getSQLType() ); mappings.put( Geometries.MULTIPOLYGON.getBinding(), Geometries.MULTIPOLYGON.getSQLType() ); mappings.put( Geometries.GEOMETRY.getBinding(), Geometries.GEOMETRY.getSQLType() ); mappings.put( Geometries.GEOMETRYCOLLECTION.getBinding(), Geometries.GEOMETRYCOLLECTION.getSQLType() ); //override some internal defaults mappings.put(Long.class, Types.INTEGER); mappings.put(Double.class, Types.REAL); }
private static Geometry smooth( final Geometry geom, final double fit, final GeometryFactory factory, GeometrySmoother smoother) { switch (Geometries.get(geom)) { case POINT: case MULTIPOINT: // For points, just return the input geometry return geom; case LINESTRING: // This handles open and closed lines (LinearRings) return smoothLineString(factory, smoother, geom, fit); case MULTILINESTRING: return smoothMultiLineString(factory, smoother, geom, fit); case POLYGON: return smoother.smooth((Polygon) geom, fit); case MULTIPOLYGON: return smoothMultiPolygon(factory, smoother, geom, fit); case GEOMETRYCOLLECTION: return smoothGeometryCollection(factory, smoother, geom, fit); default: throw new UnsupportedOperationException( "No smoothing method available for " + geom.getGeometryType()); } }
@Test public void testGetBinding() { // System.out.println(" getBinding"); assertEquals(Point.class, Geometries.POINT.getBinding()); assertEquals(MultiPoint.class, Geometries.MULTIPOINT.getBinding()); assertEquals(LineString.class, Geometries.LINESTRING.getBinding()); assertEquals(MultiLineString.class, Geometries.MULTILINESTRING.getBinding()); assertEquals(Polygon.class, Geometries.POLYGON.getBinding()); assertEquals(MultiPolygon.class, Geometries.MULTIPOLYGON.getBinding()); assertEquals(Geometry.class, Geometries.GEOMETRY.getBinding()); assertEquals(GeometryCollection.class, Geometries.GEOMETRYCOLLECTION.getBinding()); }
/** * Get the {@code Geometries} with the given integer SQL type code. * * @param sqlType the code to look up. * @return the matching type or {@code null} if no match was found */ public static Geometries getForSQLType(int sqlType) { for (Geometries gt : Geometries.values()) { if (gt.sqlType == sqlType) { return gt; } } return null; } }
static Geometries findGeometryType(SimpleFeatureType schema) { GeometryDescriptor gd = findGeometryDescriptor(schema); return gd != null ? Geometries.getForBinding((Class<? extends Geometry>) gd.getType().getBinding()) : null; }
@Override public String getGeometryTypeName(Integer type) { return Geometries.getForSQLType(type).getName(); }
.set( e.getGeometryType() != null ? e.getGeometryType().getName() : null) .set(e.getSrid())
@Override public void registerClassToSqlMappings(Map<Class<?>, Integer> mappings) { super.registerClassToSqlMappings(mappings); // add geometry mappings for (Geometries g : Geometries.values()) { mappings.put(g.getBinding(), g.getSQLType()); } // override some internal defaults mappings.put(Long.class, Types.INTEGER); mappings.put(Double.class, Types.REAL); mappings.put(Boolean.class, Types.INTEGER); }
public Geometry toGeometry(DBObject obj) { if (obj == null) { return null; } String type = (String) obj.get("type"); Geometries g = Geometries.getForName(type); if (g == null) { throw new IllegalArgumentException("Unable to create geometry of type: " + type); } BasicDBList list = (BasicDBList) obj.get("coordinates"); switch (g) { case POINT: return toPoint(list); case LINESTRING: return toLineString(list); case POLYGON: return toPolygon(list); case MULTIPOINT: return toMultiPoint(list); case MULTILINESTRING: return toMultiLineString(list); case MULTIPOLYGON: return toMultiPolygon(list); case GEOMETRYCOLLECTION: return toGeometryCollection((BasicDBList) obj.get("geometries")); default: throw new IllegalArgumentException("Unknown geometry type: " + type); } }