@Test public void testCreateFromCollection() throws Exception { List<AttributeDescriptor> l = new ArrayList<AttributeDescriptor>(); l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.INTEGER), "osm_id")); l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.DATE), "lastchange")); l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.STRING), "type")); l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.STRING), "name")); l.add(new AttributeDescriptorImpl(new PrimitiveAttributeTypeImpl(PrimitiveType.INTEGER), "population")); when(layer.getAttributeDescriptors()).thenReturn(l); JsonFeatureFactory factory = new JsonFeatureFactory(); FeatureCollection c = factory .createCollection( JsonTestUtil .parse("{\"type\":\"FeatureCollection\"," + "\"features\":[{\"type\":\"Feature\",\"id\":\"place.1\"," + "\"geometry\":{\"type\":\"Point\",\"coordinates\":[4.4436244,50.4120332]}," + "\"geometry_name\":\"geom\",\"properties\":" + "{\"osm_id\":9002746,\"lastchange\":\"2008-10-03T10:29:40.046-04:00\"," + "\"type\":\"city\",\"name\":\"Charleroi\",\"population\":203000}}," + "{\"type\":\"Feature\",\"id\":\"place.2\",\"geometry\":" + "{\"type\":\"Point\",\"coordinates\":[4.3487134,50.883392]}," + "\"geometry_name\":\"geom\",\"properties\":{\"osm_id\":17428149," + "\"lastchange\":\"2008-10-03T10:29:40.046-04:00\",\"type\":\"village\",\"name\":\"Laken - Laeken\"," + "\"population\":null}}],\"crs\":{\"type\":\"EPSG\"," + "\"properties\":{\"code\":\"4326\"}}}"), layer); Assert.assertEquals(2, c.getFeatures().size()); Feature f1 = c.getFeatures().get(0); Assert.assertEquals(9002746, f1.getAttributeValue("osm_id")); Assert.assertEquals(new Date(1223044180046L), (Date) f1.getAttributeValue("lastchange")); Assert.assertEquals("city", f1.getAttributeValue("type")); Assert.assertEquals("Charleroi", f1.getAttributeValue("name")); Assert.assertEquals(203000, f1.getAttributeValue("population")); Assert.assertEquals("POINT (4.4436244 50.4120332)", WktService.toWkt(f1.getGeometry())); Feature f2 = c.getFeatures().get(1); Assert.assertEquals(17428149, f2.getAttributeValue("osm_id")); Assert.assertEquals(new Date(1223044180046L), (Date) f2.getAttributeValue("lastchange")); Assert.assertEquals("village", f2.getAttributeValue("type")); Assert.assertEquals("Laken - Laeken", f2.getAttributeValue("name")); Assert.assertNull(f2.getAttributeValue("population")); Assert.assertEquals("POINT (4.3487134 50.883392)", WktService.toWkt(f2.getGeometry())); }
public FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer) { FeatureCollection dto = new FeatureCollection(layer); String type = JsonService.getStringValue(jsonObject, "type"); if ("FeatureCollection".equals(type)) { JSONArray features = JsonService.getChildArray(jsonObject, "features"); for (int i = 0; i < features.size(); i++) { dto.getFeatures().add(createFeature((JSONObject) features.get(i), layer)); } } else if ("Feature".equals(type)) { dto.getFeatures().add(createFeature(jsonObject, layer)); } return dto; }
JsonFeatureFactory { public FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer) { FeatureCollection dto = new FeatureCollection(layer); String type = JsonService.getStringValue(jsonObject, "type"); if ("FeatureCollection".equals(type)) { JSONArray features = JsonService.getChildArray(jsonObject, "features"); for (int i = 0; i < features.size(); i++) { dto.getFeatures().add(createFeature((JSONObject) features.get(i), layer)); } } else if ("Feature".equals(type)) { dto.getFeatures().add(createFeature(jsonObject, layer)); } return dto; } }
JsonFeatureFactory { public FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer) { FeatureCollection dto = new FeatureCollection(layer); String type = JsonService.getStringValue(jsonObject, "type"); if ("FeatureCollection".equals(type)) { JSONArray features = JsonService.getChildArray(jsonObject, "features"); for (int i = 0; i < features.size(); i++) { dto.getFeatures().add(createFeature((JSONObject) features.get(i), layer)); } } else if ("Feature".equals(type)) { dto.getFeatures().add(createFeature(jsonObject, layer)); } return dto; }  }
JsonFeatureFactory { public FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer) { FeatureCollection dto = new FeatureCollection(layer); String type = JsonService.getStringValue(jsonObject, "type"); if ("FeatureCollection".equals(type)) { JSONArray features = JsonService.getChildArray(jsonObject, "features"); for (int i = 0; i < features.size(); i++) { dto.getFeatures().add(createFeature((JSONObject) features.get(i), layer)); } } else if ("Feature".equals(type)) { dto.getFeatures().add(createFeature(jsonObject, layer)); } return dto; }  FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer); }
JsonFeatureFactory { public FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer) { FeatureCollection dto = new FeatureCollection(layer); String type = JsonService.getStringValue(jsonObject, "type"); if ("FeatureCollection".equals(type)) { JSONArray features = JsonService.getChildArray(jsonObject, "features"); for (int i = 0; i < features.size(); i++) { dto.getFeatures().add(createFeature((JSONObject) features.get(i), layer)); } } else if ("Feature".equals(type)) { dto.getFeatures().add(createFeature(jsonObject, layer)); } return dto; }  FeatureCollection createCollection(JSONObject jsonObject, FeaturesSupported layer);  }