@Override public void dispose(FeatureReader reader, ImportTask task) throws IOException { reader.close(); if (task.getMetadata().containsKey(DataStore.class)) { DataStore dataStore = (DataStore) task.getMetadata().get(DataStore.class); dataStore.dispose(); task.getMetadata().remove(DataStore.class); } }
private DataStore getDataStore(ImportData data, ImportTask task) throws IOException { DataStore dataStore = (DataStore) task.getMetadata().get(DataStore.class); if (dataStore == null) { dataStore = createDataStore(data); // store in order to later dispose // TODO: come up with a better scheme for caching the datastore task.getMetadata().put(DataStore.class, dataStore); } return dataStore; }
@Override public void dispose(FeatureReader reader, ImportTask task) throws IOException { reader.close(); if (task.getMetadata().containsKey(DataStore.class)) { DataStore dataStore = (DataStore) task.getMetadata().get(DataStore.class); dataStore.dispose(); task.getMetadata().remove(DataStore.class); } }
private DataStore getDataStore(ImportData data, ImportTask task) throws IOException { DataStore dataStore = (DataStore) task.getMetadata().get(DataStore.class); if (dataStore == null) { dataStore = createDataStore(data); //store in order to later dispose //TODO: come up with a better scheme for caching the datastore task.getMetadata().put(DataStore.class, dataStore); } return dataStore; }
@Override public FeatureReader read(ImportData data, ImportTask task) throws IOException { File file = getFileFromData(data); // we need to get the feature type, to use for the particular parse through the file // since we put it on the metadata from the list method, we first check if that's still // available SimpleFeatureType ft = (SimpleFeatureType) task.getMetadata().get(FeatureType.class); GMLVersion version = (GMLVersion) task.getMetadata().get(GML_VERSION_KEY); if (version == null) { version = GMLVersion.GML3; } if (ft == null) { FeatureTypeInfo fti = (FeatureTypeInfo) task.getLayer().getResource(); ft = buildFeatureTypeFromInfo(fti); } return new GMLReader(new FileInputStream(file), version.getConfiguration(), ft); }
@Override public FeatureReader read(ImportData data, ImportTask item) throws IOException { final FeatureType featureType = (FeatureType) item.getMetadata().get(FeatureType.class); final FeatureIterator it = new FeatureJSON().streamFeatureCollection(file(data, item)); return new FeatureReader() { @Override public FeatureType getFeatureType() { return featureType; } @Override public boolean hasNext() throws IOException { return it.hasNext(); } @Override public Feature next() throws IOException, IllegalArgumentException, NoSuchElementException { return it.next(); } @Override public void close() throws IOException { it.close(); } }; }
@Override public FeatureReader read(ImportData data, ImportTask item) throws IOException { final SimpleFeatureType featureType = (SimpleFeatureType) item.getMetadata().get(FeatureType.class); FeatureJSON json = new FeatureJSON(); json.setFeatureType(featureType); final FeatureIterator it = json.streamFeatureCollection(file(data, item)); return new FeatureReader() { @Override public FeatureType getFeatureType() { return featureType; } @Override public boolean hasNext() throws IOException { return it.hasNext(); } @Override public Feature next() throws IOException, IllegalArgumentException, NoSuchElementException { return it.next(); } @Override public void close() throws IOException { it.close(); } }; }
@SuppressWarnings("rawtypes") @Override public FeatureReader read(ImportData data, ImportTask task) throws IOException { File file = getFileFromData(data); // we need to get the feature type, to use for the particular parse through the file // since we put it on the metadata from the list method, we first check if that's still // available SimpleFeatureType ft = (SimpleFeatureType) task.getMetadata().get(FeatureType.class); if (ft == null) { // if the type is not available, we can generate one from the resource // we aren't able to ask for the feature type from the resource directly, // because we don't have a backing store FeatureTypeInfo fti = (FeatureTypeInfo) task.getLayer().getResource(); ft = buildFeatureTypeFromInfo(fti); MetadataMap metadata = fti.getMetadata(); if (metadata.containsKey("importschemanames")) { Map<Object, Object> userData = ft.getUserData(); userData.put("schemanames", metadata.get("importschemanames")); } } return read(ft, file); }
task.setLayer(layer); task.getMetadata().put(FeatureType.class, featureType);
task.setLayer(layer); task.getMetadata().put(FeatureType.class, featureType);
@SuppressWarnings("rawtypes") @Override public FeatureReader read(ImportData data, ImportTask task) throws IOException { File file = getFileFromData(data); // we need to get the feature type, to use for the particular parse through the file // since we put it on the metadata from the list method, we first check if that's still available SimpleFeatureType ft = (SimpleFeatureType) task.getMetadata().get(FeatureType.class); if (ft == null) { // if the type is not available, we can generate one from the resource // we aren't able to ask for the feature type from the resource directly, // because we don't have a backing store FeatureTypeInfo fti = (FeatureTypeInfo) task.getLayer().getResource(); SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName(fti.getName()); List<AttributeTypeInfo> attributes = fti.getAttributes(); for (AttributeTypeInfo attr : attributes) { ftb.add(attr.getName(), attr.getBinding()); } ft = ftb.buildFeatureType(); MetadataMap metadata = fti.getMetadata(); if (metadata.containsKey("importschemanames")) { Map<Object, Object> userData = ft.getUserData(); userData.put("schemanames", metadata.get("importschemanames")); } } return read(ft, file); }
task.getMetadata().put(FeatureType.class, featureType); task.getMetadata().put(GML_VERSION_KEY, featureType.getUserData().get(GML_VERSION_KEY));
@Test public void testJaggedGeoJSON() throws Exception { File json = file("geojson/jagged.json"); ImportContext ctx = importer.createContext(new SpatialFile(json)); assertEquals(1, ctx.getTasks().size()); SimpleFeatureType info = (SimpleFeatureType) ctx.getTasks().get(0).getMetadata().get(FeatureType.class); assertEquals(4, info.getAttributeCount()); int cnt = 0; for (int i = 0; i < info.getAttributeCount(); i++) { if (info.getDescriptor(i).getLocalName().equals("geometry")) { cnt++; } } assertEquals(1, cnt); }
task.getMetadata().put(FeatureType.class, featureType); result.add(task);
task.getMetadata().put(FeatureType.class, featureType); result.add(task);
task.getMetadata().put(FeatureType.class, schema);
task.getMetadata().put(FeatureType.class, schema);
(FeatureType) task.getMetadata().get(FeatureType.class); if (featureType != null) { style = styleGen.createStyle((FeatureTypeInfo) r, featureType);
(FeatureType) task.getMetadata().get(FeatureType.class); if (featureType != null) { style =
(SimpleFeatureType) task.getMetadata().get(FeatureType.class); task.setOriginalLayerName(featureType.getTypeName()); String nativeName = task.getLayer().getResource().getNativeName();