public void testImportKMLIndirect() throws Exception { File dir = unpack("kml/sample.zip"); String wsName = getCatalog().getDefaultWorkspace().getName(); DataStoreInfo h2DataStore = createH2DataStore(wsName, "kmltest"); SpatialFile importData = new SpatialFile(new File(dir, "sample.kml")); ImportContext context = importer.createContext(importData, h2DataStore); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); assertEquals("Invalid srs", "EPSG:4326", resource.getSRS()); ReferencedEnvelope emptyBounds = new ReferencedEnvelope(); emptyBounds.setToNull(); assertTrue("Unexpected bounding box", emptyBounds.equals(resource.getNativeBoundingBox())); // transform chain to limit characters // otherwise we get a sql exception thrown TransformChain transformChain = task.getTransform(); transformChain.add(new DescriptionLimitingTransform()); importer.run(context); Exception error = task.getError(); if (error != null) { error.printStackTrace(); fail(error.getMessage()); } assertFalse("Bounding box not updated", emptyBounds.equals(resource.getNativeBoundingBox())); FeatureTypeInfo fti = (FeatureTypeInfo) resource; assertEquals("Invalid type name", "sample", fti.getName()); FeatureSource<? extends FeatureType, ? extends Feature> featureSource = fti.getFeatureSource(null, null); assertEquals("Unexpected feature count", 20, featureSource.getCount(Query.ALL)); }
public void testImportCSV() throws Exception { File dir = unpack("csv/locations.zip"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "locations.csv"))); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_CRS, task.getState()); LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); resource.setSRS("EPSG:4326"); assertTrue("Item not ready", importer.prep(task)); assertEquals(ImportTask.State.READY, task.getState()); context.updated(); assertEquals(ImportContext.State.PENDING, context.getState()); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo fti = (FeatureTypeInfo) resource; SimpleFeatureType featureType = (SimpleFeatureType) fti.getFeatureType(); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); assertNull("Expecting no geometry", geometryDescriptor); assertEquals(4, featureType.getAttributeCount()); }
public void testImportIntoDatabaseWithEncoding() throws Exception { Catalog cat = getCatalog(); DataStoreInfo ds = createH2DataStore(cat.getDefaultWorkspace().getName(), "ming"); File dir = tmpDir(); unpack("shape/ming_time.zip", dir); ImportContext context = importer.createContext(new Directory(dir), ds); assertEquals(1, context.getTasks().size()); context.getTasks().get(0).getData().setCharsetEncoding("UTF-8"); importer.run(context); FeatureTypeInfo info = (FeatureTypeInfo) context.getTasks().get(0).getLayer().getResource(); FeatureSource<? extends FeatureType, ? extends Feature> fs = info.getFeatureSource(null, null); FeatureCollection<? extends FeatureType, ? extends Feature> features = fs.getFeatures(); FeatureIterator<? extends Feature> it = features.features(); assertTrue(it.hasNext()); SimpleFeature next = (SimpleFeature) it.next(); // let's test some attributes to see if they were digested properly String type_ch = (String) next.getAttribute("type_ch"); assertEquals("卫", type_ch); String name_ch = (String) next.getAttribute("name_ch"); assertEquals("杭州前卫", name_ch); it.close(); }
public void testImportShapefiles() throws Exception { File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); unpack("shape/bugsites_esri_prj.tar.gz", dir); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(2, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("archsites", task.getLayer().getResource().getName()); task = context.getTasks().get(1); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("bugsites", task.getLayer().getResource().getName()); importer.run(context); Catalog cat = getCatalog(); assertNotNull(cat.getLayerByName("archsites")); assertNotNull(cat.getLayerByName("bugsites")); assertEquals(ImportTask.State.COMPLETE, context.getTasks().get(0).getState()); assertEquals(ImportTask.State.COMPLETE, context.getTasks().get(1).getState()); runChecks("archsites"); runChecks("bugsites"); }
public void testImportDirectoryWithRasterDirect() throws Exception { File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); unpack("shape/bugsites_esri_prj.tar.gz", dir); unpack("geotiff/EmissiveCampania.tif.bz2", dir); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(3, context.getTasks().size()); assertTrue(context.getData() instanceof Directory); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("archsites", task.getLayer().getResource().getName()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("Shapefile", task.getData().getFormat().getName()); task = context.getTasks().get(1); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("bugsites", task.getLayer().getResource().getName()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("Shapefile", task.getData().getFormat().getName()); task = context.getTasks().get(2); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("EmissiveCampania", task.getLayer().getResource().getName()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("GeoTIFF", task.getData().getFormat().getName()); }
public void testCreateContextFromArchive() throws Exception { File file = file("shape/archsites_epsg_prj.zip"); Archive arch = new Archive(file); ImportContext context = importer.createContext(arch); assertEquals(1, context.getTasks().size()); assertEquals(1, context.getTasks().get(0).getItems().size()); }
public void testImportUnknownFile() throws Exception { File dir = unpack("gml/states_wfs11.xml.gz"); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_FORMAT, task.getState()); assertNull(task.getData().getFormat()); }
public void testCreateContextDirectoryHomo() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); unpack("shape/bugsites_esri_prj.tar.gz", dir); Directory d = new Directory(dir); ImportContext context = importer.createContext(d); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(d, task.getData()); }
public void testCreateContextSingleFile() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); ImportContext context = importer.createContext(file); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(file, task.getData()); }
public void testImportDirectoryWithRasterIndirect() throws Exception { DataStoreInfo ds = createH2DataStore(getCatalog().getDefaultWorkspace().getName(), "shapes"); File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); unpack("shape/bugsites_esri_prj.tar.gz", dir); unpack("geotiff/EmissiveCampania.tif.bz2", dir); ImportContext context = importer.createContext(new Directory(dir), ds); assertEquals(3, context.getTasks().size()); assertTrue(context.getData() instanceof Directory); ImportTask task = Iterables.find( context.getTasks(), new Predicate<ImportTask>() { @Override public boolean apply(ImportTask input) { return "archsites".equals(input.getLayer().getResource().getName()); } }); assertEquals(ImportTask.State.READY, task.getState()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("Shapefile", task.getData().getFormat().getName()); task = Iterables.find( context.getTasks(), new Predicate<ImportTask>() { @Override public boolean apply(ImportTask input) { return "bugsites".equals(input.getLayer().getResource().getName()); } }); assertEquals(ImportTask.State.READY, task.getState()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("Shapefile", task.getData().getFormat().getName()); task = Iterables.find( context.getTasks(), new Predicate<ImportTask>() { @Override public boolean apply(ImportTask input) { return "EmissiveCampania".equals(input.getLayer().getResource().getName()); } }); assertEquals(ImportTask.State.BAD_FORMAT, task.getState()); assertTrue(task.getData() instanceof SpatialFile); assertEquals("GeoTIFF", task.getData().getFormat().getName()); }
public void testImportCSVIndirect() throws Exception { File dir = unpack("csv/locations.zip"); String wsName = getCatalog().getDefaultWorkspace().getName(); DataStoreInfo h2DataStore = createH2DataStore(wsName, "csvindirecttest"); SpatialFile importData = new SpatialFile(new File(dir, "locations.csv")); ImportContext context = importer.createContext(importData, h2DataStore); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); TransformChain transformChain = task.getTransform(); transformChain.add(new AttributesToPointGeometryTransform("LAT", "LON")); assertEquals(ImportTask.State.NO_CRS, task.getState()); LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); resource.setSRS("EPSG:4326"); assertTrue("Item not ready", importer.prep(task)); assertEquals(ImportTask.State.READY, task.getState()); context.updated(); assertEquals(ImportContext.State.PENDING, context.getState()); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo fti = (FeatureTypeInfo) resource; SimpleFeatureType featureType = (SimpleFeatureType) fti.getFeatureType(); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); assertNotNull("Expecting geometry", geometryDescriptor); assertEquals("Invalid geometry name", "location", geometryDescriptor.getLocalName()); assertEquals(3, featureType.getAttributeCount()); FeatureSource<? extends FeatureType, ? extends Feature> featureSource = fti.getFeatureSource(null, null); FeatureCollection<? extends FeatureType, ? extends Feature> features = featureSource.getFeatures(); assertEquals(9, features.size()); FeatureIterator<? extends Feature> featureIterator = features.features(); assertTrue("Expected features", featureIterator.hasNext()); SimpleFeature feature = (SimpleFeature) featureIterator.next(); assertNotNull(feature); assertEquals("Invalid city attribute", "Trento", feature.getAttribute("CITY")); assertEquals("Invalid number attribute", 140, feature.getAttribute("NUMBER")); Object geomAttribute = feature.getAttribute("location"); assertNotNull("Expected geometry", geomAttribute); Point point = (Point) geomAttribute; Coordinate coordinate = point.getCoordinate(); assertEquals("Invalid x coordinate", 11.12, coordinate.x, 0.1); assertEquals("Invalid y coordinate", 46.07, coordinate.y, 0.1); featureIterator.close(); }
public void testCreateContextDirectoryHetero() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); unpack("geotiff/EmissiveCampania.tif.bz2", dir); Directory d = new Directory(dir); ImportContext context = importer.createContext(d); assertEquals(2, context.getTasks().size()); // cannot ensure order of tasks due to hashing HashSet files = new HashSet(); files.add(context.getTasks().get(0).getData()); files.add(context.getTasks().get(1).getData()); assertTrue(files.containsAll(d.getFiles())); }
public void testCreateContextIgnoreHidden() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); FileUtils.touch(new File(dir, ".DS_Store")); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(1, context.getTasks().size()); }
public void testIntegerToDateTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/archsites_epsg_prj.zip"); SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); assertEquals(1, context.getTasks().size()); context.setTargetStore(store); ImportTask task = context.getTasks().get(0); // this is a silly test - CAT_ID ranges from 1-25 and is not supposed to be a date // java date handling doesn't like dates in year 1 task.getTransform().add(new IntegerFieldToDateTransform("CAT_ID")); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "archsites"); assertNotNull(ft); SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType(); assertEquals(Timestamp.class, schema.getDescriptor("CAT_ID").getType().getBinding()); FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features(); int year = 2; Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); try { // make sure we have something assertTrue(it.hasNext()); // the first date will be bogus due to java date limitation it.next(); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); // class will be timestamp cal.setTime((Date) f.getAttribute("CAT_ID")); assertEquals(year++, cal.get(Calendar.YEAR)); } } finally { it.close(); } }
public void testImportShapefilesWithExtraFiles() throws Exception { File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); // make some 'extra' files new File(dir, "archsites.sbn").createNewFile(); new File(dir, "archsites.sbx").createNewFile(); new File(dir, "archsites.shp.xml").createNewFile(); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("archsites", task.getLayer().getResource().getName()); }
public void testReprojectTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/archsites_epsg_prj.zip"); SpatialFile file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); LayerInfo l1 = context.getTasks().get(0).getLayer(); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:26713"), l1.getResource().getNativeCRS())); assertEquals("EPSG:26713", l1.getResource().getSRS()); dir = unpack("shape/archsites_epsg_prj.zip"); file = new SpatialFile(new File(dir, "archsites.shp")); file.prepare(); context = importer.createContext(file, store); ImportTask item = context.getTasks().get(0); item.getTransform().add(new ReprojectTransform(CRS.decode("EPSG:4326"))); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); LayerInfo l2 = context.getTasks().get(0).getLayer(); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), l2.getResource().getNativeCRS())); assertEquals("EPSG:4326", l2.getResource().getSRS()); assertFalse( l1.getResource().getNativeBoundingBox().equals(l2.getResource().getNativeBoundingBox())); assertTrue( CRS.equalsIgnoreMetadata( l2.getResource().getNativeCRS(), l2.getResource().getNativeBoundingBox().getCoordinateReferenceSystem())); LayerInfo l = cat.getLayer(l2.getId()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), l2.getResource().getNativeCRS())); assertEquals("EPSG:4326", l2.getResource().getSRS()); }
public void testImportShapefile() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "archsites.shp"))); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("archsites", task.getLayer().getResource().getName()); importer.run(context); Catalog cat = getCatalog(); assertNotNull(cat.getLayerByName("archsites")); assertEquals(ImportTask.State.COMPLETE, task.getState()); runChecks("archsites"); }
public void testImportNoCrsLatLonBoundingBox() throws Exception { File dir = unpack("shape/archsites_no_crs.zip"); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_CRS, task.getState()); assertNull(task.getLayer().getResource().getLatLonBoundingBox()); task.getLayer().getResource().setSRS("EPSG:26713"); importer.changed(task); assertEquals(ImportTask.State.READY, task.getState()); ResourceInfo r = task.getLayer().getResource(); assertNotNull(r.getLatLonBoundingBox()); assertNotNull(r.boundingBox()); assertNotNull(r.boundingBox().getCoordinateReferenceSystem()); }
public void testImportGeoTIFF() throws Exception { File dir = unpack("geotiff/EmissiveCampania.tif.bz2"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "EmissiveCampania.tif"))); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("EmissiveCampania", task.getLayer().getResource().getName()); importer.run(context); Catalog cat = getCatalog(); assertNotNull(cat.getLayerByName("EmissiveCampania")); assertEquals(ImportTask.State.COMPLETE, task.getState()); runChecks("EmissiveCampania"); }
public void testImportDatabaseIntoDatabase() throws Exception { File dir = unpack("h2/cookbook.zip"); DataStoreInfo ds = createH2DataStore("gs", "cookbook"); Map params = new HashMap(); params.put(H2DataStoreFactory.DBTYPE.key, "h2"); params.put(H2DataStoreFactory.DATABASE.key, new File(dir, "cookbook").getAbsolutePath()); ImportContext context = importer.createContext(new Database(params), ds); assertEquals(3, context.getTasks().size()); }
public void testImportIntoDatabase() throws Exception { Catalog cat = getCatalog(); DataStoreInfo ds = createH2DataStore(cat.getDefaultWorkspace().getName(), "spearfish"); File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); unpack("shape/bugsites_esri_prj.tar.gz", dir); ImportContext context = importer.createContext(new Directory(dir), ds); assertEquals(2, context.getTasks().size()); ImportTask task1 = context.getTasks().get(0); ImportTask task2 = context.getTasks().get(1); assertEquals(ImportTask.State.READY, task1.getState()); assertEquals(ImportTask.State.READY, task2.getState()); // assertEquals(ImportTask.State.READY, context.getTasks().get(1).getState()); // cannot ensure ordering of items HashSet resources = new HashSet(); resources.add(task1.getLayer().getResource().getName()); resources.add(task2.getLayer().getResource().getName()); assertTrue(resources.contains("bugsites")); assertTrue(resources.contains("archsites")); importer.run(context); assertEquals(ImportTask.State.COMPLETE, task1.getState()); assertEquals(ImportTask.State.COMPLETE, task2.getState()); assertNotNull(cat.getLayerByName("archsites")); assertNotNull(cat.getLayerByName("bugsites")); assertNotNull(cat.getFeatureTypeByDataStore(ds, "archsites")); assertNotNull(cat.getFeatureTypeByDataStore(ds, "bugsites")); runChecks("archsites"); runChecks("bugsites"); }
public void testImportDatabase() throws Exception { File dir = unpack("h2/cookbook.zip"); Map params = new HashMap(); params.put(H2DataStoreFactory.DBTYPE.key, "h2"); params.put(H2DataStoreFactory.DATABASE.key, new File(dir, "cookbook").getAbsolutePath()); ImportContext context = importer.createContext(new Database(params)); assertEquals(3, context.getTasks().size()); assertEquals(ImportTask.State.READY, context.getTasks().get(0).getState()); assertEquals(ImportTask.State.READY, context.getTasks().get(1).getState()); assertEquals(ImportTask.State.READY, context.getTasks().get(2).getState()); Catalog cat = getCatalog(); assertNull(cat.getDataStoreByName(cat.getDefaultWorkspace(), "cookbook")); assertNull(cat.getLayerByName("point")); assertNull(cat.getLayerByName("line")); assertNull(cat.getLayerByName("polygon")); importer.run(context); assertEquals(ImportTask.State.COMPLETE, context.getTasks().get(0).getState()); assertEquals(ImportTask.State.COMPLETE, context.getTasks().get(1).getState()); assertEquals(ImportTask.State.COMPLETE, context.getTasks().get(2).getState()); assertNotNull(cat.getDataStoreByName(cat.getDefaultWorkspace(), "cookbook")); DataStoreInfo ds = cat.getDataStoreByName(cat.getDefaultWorkspace(), "cookbook"); assertNotNull(cat.getFeatureTypeByDataStore(ds, "point")); assertNotNull(cat.getFeatureTypeByDataStore(ds, "line")); assertNotNull(cat.getFeatureTypeByDataStore(ds, "polygon")); assertNotNull(cat.getLayerByName("point")); assertNotNull(cat.getLayerByName("line")); assertNotNull(cat.getLayerByName("polygon")); runChecks("point"); runChecks("line"); runChecks("polygon"); }
public void testDateFormatTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/ivan.zip"); SpatialFile file = new SpatialFile(new File(dir, "ivan.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); assertEquals(1, context.getTasks().size()); context.setTargetStore(store); ImportTask task = context.getTasks().get(0); task.getTransform().add(new DateFormatTransform("timestamp", "yyyy-MM-dd HH:mm:ss.S")); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "ivan"); assertNotNull(ft); SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType(); assertTrue( Date.class.isAssignableFrom(schema.getDescriptor("timestamp").getType().getBinding())); FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features(); try { assertTrue(it.hasNext()); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); assertTrue(f.getAttribute("timestamp") instanceof Date); } } finally { it.close(); } }
public void testNumberFormatTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/restricted.zip"); SpatialFile file = new SpatialFile(new File(dir, "restricted.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); assertEquals(1, context.getTasks().size()); context.setTargetStore(store); ImportTask task = context.getTasks().get(0); task.getTransform().add(new NumberFormatTransform("cat", Integer.class)); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "restricted"); assertNotNull(ft); SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType(); assertEquals(Integer.class, schema.getDescriptor("cat").getType().getBinding()); FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features(); try { assertTrue(it.hasNext()); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); assertTrue(f.getAttribute("cat") instanceof Integer); } } finally { it.close(); } }
public void testImportIntoDatabaseUpdateModes() throws Exception { testImportIntoDatabase(); DataStoreInfo ds = getCatalog().getDataStoreByName("spearfish"); assertNotNull(ds); File dir = tmpDir(); unpack("shape/archsites_epsg_prj.zip", dir); unpack("shape/bugsites_esri_prj.tar.gz", dir); FeatureSource<? extends FeatureType, ? extends Feature> fs = getCatalog().getFeatureTypeByName("archsites").getFeatureSource(null, null); int archsitesCount = fs.getCount(Query.ALL); fs = getCatalog().getFeatureTypeByName("bugsites").getFeatureSource(null, null); int bugsitesCount = fs.getCount(Query.ALL); ImportContext context = importer.createContext(new Directory(dir), ds); context.getTasks().get(0).setUpdateMode(UpdateMode.REPLACE); context.getTasks().get(1).setUpdateMode(UpdateMode.APPEND); importer.run(context); fs = getCatalog().getFeatureTypeByName("archsites").getFeatureSource(null, null); int archsitesCount2 = fs.getCount(Query.ALL); fs = getCatalog().getFeatureTypeByName("bugsites").getFeatureSource(null, null); int bugsitesCount2 = fs.getCount(Query.ALL); // tasks might not be in same order if (context.getTasks().get(0).getLayer().getName().equals("archsites")) { assertEquals(archsitesCount, archsitesCount2); assertEquals(bugsitesCount * 2, bugsitesCount2); } else { assertEquals(archsitesCount * 2, archsitesCount2); assertEquals(bugsitesCount, bugsitesCount2); } }
public void testGeoJSONImport() throws Exception { DataStoreInfo h2 = createH2DataStore(getCatalog().getDefaultWorkspace().getName(), "jsontest"); File dir = unpack("geojson/point.json.zip"); ImportContext imp = importer.createContext(new SpatialFile(new File(dir, "point.json")), h2); assertEquals(1, imp.getTasks().size()); assertEquals(ImportTask.State.READY, imp.task(0).getState()); importer.run(imp); assertEquals(ImportContext.State.COMPLETE, imp.getState()); runChecks("point"); }
public void testImportNameClash() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "archsites.shp"))); importer.run(context); Catalog cat = getCatalog(); assertNotNull(cat.getLayerByName("archsites")); runChecks("archsites"); context = importer.createContext(new SpatialFile(new File(dir, "archsites.shp"))); importer.run(context); assertEquals("archsites0", context.getTasks().get(0).getLayer().getName()); runChecks("archsites0"); }
public void testGeoJSONImportDirectory() throws Exception { DataStoreInfo h2 = createH2DataStore(getCatalog().getDefaultWorkspace().getName(), "jsontest"); File dir = unpack("geojson/point.json.zip"); unpack("geojson/line.json.zip", dir); unpack("geojson/polygon.json.zip", dir); ImportContext imp = importer.createContext(new Directory(dir), h2); assertEquals(3, imp.getTasks().size()); assertEquals(ImportContext.State.PENDING, imp.getState()); assertEquals(ImportTask.State.READY, imp.task(0).getState()); assertEquals(ImportTask.State.READY, imp.task(1).getState()); assertEquals(ImportTask.State.READY, imp.task(2).getState()); importer.run(imp); assertEquals(ImportContext.State.COMPLETE, imp.getState()); runChecks("point"); runChecks("line"); runChecks("polygon"); }