@Test public void testRoundTripConversion() throws FileNotFoundException, IOException, FactoryException { SimpleFeatureType original = buildDummyFeatureType("dummy"); BasicDBObject dbo = FeatureTypeDBObject.convert(original); String json = dbo.toJson(); dbo = BasicDBObject.parse(json); SimpleFeatureType result = FeatureTypeDBObject.convert(dbo); compareFeatureTypes(original, result, false); }
public static BasicDBObject convert(SimpleFeatureType ft) { BasicDBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); } GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; } DBObject crsDBO = encodeCRSToGeoJSON(crs); if (crsDBO != null) { gdDBO.put(KEY_crs, crsDBO); } ftDBO.put(KEY_geometryDescriptor, gdDBO); BasicDBList adDBL = new BasicDBList(); for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); } adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); } Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData()); if (!adUserData.isEmpty()) { adDBO.put(KEY_userData, new BasicDBObject(adUserData)); } adDBL.add(adDBO); } ftDBO.put(KEY_attributeDescriptors, adDBL); return ftDBO; }
FeatureTypeDBObject { public static BasicDBObject convert(SimpleFeatureType ft) { BasicDBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); } GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; } DBObject crsDBO = encodeCRSToGeoJSON(crs); if (crsDBO != null) { gdDBO.put(KEY_crs, crsDBO); } ftDBO.put(KEY_geometryDescriptor, gdDBO); BasicDBList adDBL = new BasicDBList(); for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); } adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); } Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData()); if (!adUserData.isEmpty()) { adDBO.put(KEY_userData, new BasicDBObject(adUserData)); } adDBL.add(adDBO); } ftDBO.put(KEY_attributeDescriptors, adDBL); return ftDBO; } }
FeatureTypeDBObject { public static BasicDBObject convert(SimpleFeatureType ft) { BasicDBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); } GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; } DBObject crsDBO = encodeCRSToGeoJSON(crs); if (crsDBO != null) { gdDBO.put(KEY_crs, crsDBO); } ftDBO.put(KEY_geometryDescriptor, gdDBO); BasicDBList adDBL = new BasicDBList(); for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); } adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); } Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData()); if (!adUserData.isEmpty()) { adDBO.put(KEY_userData, new BasicDBObject(adUserData)); } adDBL.add(adDBO); } ftDBO.put(KEY_attributeDescriptors, adDBL); return ftDBO; }  }
FeatureTypeDBObject { public static BasicDBObject convert(SimpleFeatureType ft) { BasicDBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); } GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; } DBObject crsDBO = encodeCRSToGeoJSON(crs); if (crsDBO != null) { gdDBO.put(KEY_crs, crsDBO); } ftDBO.put(KEY_geometryDescriptor, gdDBO); BasicDBList adDBL = new BasicDBList(); for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); } adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); } Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData()); if (!adUserData.isEmpty()) { adDBO.put(KEY_userData, new BasicDBObject(adUserData)); } adDBL.add(adDBO); } ftDBO.put(KEY_attributeDescriptors, adDBL); return ftDBO; }  static BasicDBObject convert(SimpleFeatureType ft); static SimpleFeatureType convert(DBObject ftDBO); static SimpleFeatureType convert(DBObject ftDBO, Name name); }
FeatureTypeDBObject { public static BasicDBObject convert(SimpleFeatureType ft) { BasicDBObject ftDBO = new BasicDBObject(KEY_typeName, ft.getTypeName()); Map<String, String> ftUserData = typeCheck(ft.getUserData()); if (!ftUserData.isEmpty()) { ftDBO.put(KEY_userData, new BasicDBObject(ftUserData)); } GeometryDescriptor gd = ft.getGeometryDescriptor(); String gdLocalName = gd.getLocalName(); DBObject gdDBO = new BasicDBObject(KEY_localName, gdLocalName); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs == null) { crs = DefaultGeographicCRS.WGS84; } DBObject crsDBO = encodeCRSToGeoJSON(crs); if (crsDBO != null) { gdDBO.put(KEY_crs, crsDBO); } ftDBO.put(KEY_geometryDescriptor, gdDBO); BasicDBList adDBL = new BasicDBList(); for (AttributeDescriptor ad : ft.getAttributeDescriptors()) { String adLocalName = ad.getLocalName(); DBObject adDBO = new BasicDBObject(KEY_localName, adLocalName); if (!adLocalName.equals(gdLocalName)) { Object dv = ad.getDefaultValue(); if (dv != null) { adDBO.put(KEY_defaultValue, dv); } adDBO.put(KEY_minOccurs, ad.getMinOccurs()); adDBO.put(KEY_maxOccurs, ad.getMaxOccurs()); } Class<?> binding = ad instanceof GeometryDescriptor ? Geometry.class : ad.getType().getBinding(); adDBO.put(KEY_type, new BasicDBObject(KEY_binding, binding.getName())); Map<String, String> adUserData = typeCheck(ad.getUserData()); if (!adUserData.isEmpty()) { adDBO.put(KEY_userData, new BasicDBObject(adUserData)); } adDBL.add(adDBO); } ftDBO.put(KEY_attributeDescriptors, adDBL); return ftDBO; }  static BasicDBObject convert(SimpleFeatureType ft); static SimpleFeatureType convert(DBObject ftDBO); static SimpleFeatureType convert(DBObject ftDBO, Name name);  }