Beispiel #1
0
 @Test
 public void testMetadataEditionListenerTest() throws Exception {
   dsf.getSourceManager().remove("big");
   dsf.getSourceManager()
       .register("big", new FileSourceCreation(super.getAnyNonSpatialResource(), null));
   testMetadataEditionListenerTest("big", TypeFactory.createType(Type.STRING, "STRING"));
 }
Beispiel #2
0
 @Test
 public void testAddField() throws Exception {
   sm.register(
       "landcover",
       getTempCopyOf(new File(TestResourceHandler.TESTRESOURCES, "landcover2000.shp")));
   testAddField("landcover", TypeFactory.createType(Type.STRING, "String"));
 }
 @Test
 public void testObjectDriverType() throws Exception {
   MemoryDataSetDriver driver =
       new MemoryDataSetDriver(
           new String[] {"pk", "geom"},
           new Type[] {TypeFactory.createType(Type.INT), TypeFactory.createType(Type.GEOMETRY)});
   sm.register("spatial", driver);
   Source src = sm.getSource("spatial");
   assertEquals((src.getType() & SourceManager.MEMORY), SourceManager.MEMORY);
   assertEquals((src.getType() & SourceManager.VECTORIAL), SourceManager.VECTORIAL);
   driver =
       new MemoryDataSetDriver(new String[] {"pk"}, new Type[] {TypeFactory.createType(Type.INT)});
   sm.register("alpha", driver);
   src = sm.getSource("alpha");
   assertEquals((src.getType() & SourceManager.MEMORY), SourceManager.MEMORY);
   assertEquals((src.getType() & SourceManager.VECTORIAL), 0);
 }
Beispiel #4
0
 protected Value evaluate(Function function, Value... args) throws FunctionException {
   Type[] types = new Type[args.length];
   for (int i = 0; i < types.length; i++) {
     types[i] = TypeFactory.createType(args[i].getType());
   }
   FunctionValidator.failIfTypesDoNotMatchSignature(types, function.getFunctionSignatures());
   return evaluateFunction(function, args);
 }
Beispiel #5
0
  public void setUp() throws Exception {
    byte[] rasterData = new byte[4];
    RasterMetadata rasterMetadata = new RasterMetadata(0, 0, 1, 1, 2, 2);
    GeoRaster gr = GeoRasterFactory.createGeoRaster(rasterData, rasterMetadata);

    dsf = new DataSourceFactory();
    dsf.setTempDir("src/test/resources/backup");
    DefaultMetadata metadata =
        new DefaultMetadata(
            new Type[] {TypeFactory.createType(Type.RASTER)}, new String[] {"raster"});
    ObjectMemoryDriver omd = new ObjectMemoryDriver(metadata);
    omd.addValues(new Value[] {ValueFactory.createValue(gr)});
    dsf.getSourceManager().register("raster", omd);
  }
  @Test
  public void testCreationFileAlreadyExists() throws Exception {
    DefaultMetadata metadata = new DefaultMetadata();
    metadata.addField("mystr", TypeFactory.createType(Type.STRING));
    File file = File.createTempFile("temp", ".gdms", currentWorkspace);
    file.delete();
    FileSourceCreation sc = new FileSourceCreation(file, metadata);

    dsf.createDataSource(sc);
    try {
      dsf.createDataSource(sc);
      fail();
    } catch (DriverException e) {
    }
  }
Beispiel #7
0
 @Test
 public void testEditionWithFieldAdded() throws Exception {
   sm.register("toto", getTempCopyOf(super.getAnyNonSpatialResource()));
   DataSource d = dsf.getDataSource("toto", DataSourceFactory.EDITABLE);
   d.open();
   d.addField("extra", TypeFactory.createType(Type.STRING));
   int fi = d.getFieldIndexByName("extra");
   new UndoRedoTest().testAlphanumericEditionUndoRedo(d);
   Value newValue = ValueFactory.createValue("hi");
   d.setFieldValue(0, fi, newValue);
   d.undo();
   d.redo();
   d.commit();
   d.close();
   d.open();
   assertTrue(equals(d.getFieldValue(0, d.getFieldIndexByName("extra")), newValue));
   d.close();
 }
Beispiel #8
0
  @Test
  public void testFieldInsertionEditionWhileEdition() throws Exception {
    sm.register("toto", getTempCopyOf(super.getAnyNonSpatialResource()));
    DataSource d = dsf.getDataSource("toto");
    d.open();
    String nouveau = "nouveau";
    Value newValue = ValueFactory.createValue(nouveau);
    Value testValue = d.getFieldValue(2, 1);
    int lastField = d.getMetadata().getFieldCount();
    d.deleteRow(0);
    d.setFieldValue(0, 1, d.getFieldValue(1, 1));
    d.addField(nouveau, TypeFactory.createType(Type.STRING));
    d.setFieldValue(0, lastField, newValue);
    assertTrue(equals(d.getFieldValue(0, lastField), newValue));
    d.commit();
    d.close();

    d.open();
    assertEquals(d.getMetadata().getFieldName(lastField).toLowerCase(), nouveau);
    assertTrue(equals(d.getFieldValue(0, lastField), newValue));
    assertTrue(equals(d.getFieldValue(0, 1), testValue));
    d.close();
  }
Beispiel #9
0
  @Before
  public void setUp() throws Exception {
    super.setUpTestsWithoutEdition();
    wktReader = new WKTReader();
    JTSMultiPolygon2D = wktReader.read("MULTIPOLYGON (((0 0, 1 1, 0 1, 0 0)))");
    JTSMultiLineString2D = wktReader.read("MULTILINESTRING ((0 0, 1 1, 0 1, 0 0))");
    JTSMultiPoint2D = wktReader.read("MULTIPOINT (0 0, 1 1, 0 1, 0 0)");
    JTSPolygon2D =
        wktReader.read(
            "POLYGON ((181 124, 87 162, 76 256, 166 315, 286 325, 373 255, 387 213, 377 159, 351 121, 298 101, 234 56, 181 124), (165 244, 227 219, 234 300, 168 288, 165 244), (244 130, 305 135, 324 186, 306 210, 272 206, 206 174, 244 130))");

    JTSLineString2D = wktReader.read("LINESTRING (1 1, 2 1, 2 2, 1 2, 1 1)");
    JTSLineString3D = wktReader.read("LINESTRING (1 1 1, 2 1 2, 2 2 3, 1 2 4, 1 1 5)");
    JTSPoint3D = wktReader.read("POINT(0 10 20)");
    JTSPoint2D = wktReader.read("POINT(0 10)");

    JTSPolygonWith2Holes =
        wktReader.read(
            "POLYGON ((85 55, 85 306, 366 306, 366 55, 85 55), (153 205, 212 173, 241 190, 251 253, 235 278, 147 254, 153 205), (262 88, 321 97, 324 153, 303 177, 240 138, 262 88))");

    GeometryFactory gf = new GeometryFactory();
    JTSGeometryCollection =
        gf.createGeometryCollection(
            new Geometry[] {JTSMultiPolygon2D, JTSMultiLineString2D, JTSPolygon2D});
    JTS3DCollection =
        gf.createGeometryCollection(new Geometry[] {JTSMultiPolygon2D, JTSLineString3D});

    // first datasource
    final MemoryDataSetDriver driver1 =
        new MemoryDataSetDriver(
            new String[] {"pk", "geom"},
            new Type[] {
              TypeFactory.createType(Type.INT, new PrimaryKeyConstraint()),
              TypeFactory.createType(Type.GEOMETRY)
            });

    // insert all filled rows...
    driver1.addValues(
        new Value[] {ValueFactory.createValue(1), ValueFactory.createValue(JTSMultiPolygon2D)});
    driver1.addValues(
        new Value[] {ValueFactory.createValue(2), ValueFactory.createValue(JTSMultiLineString2D)});
    driver1.addValues(
        new Value[] {ValueFactory.createValue(3), ValueFactory.createValue(JTSLineString2D)});
    driver1.addValues(
        new Value[] {ValueFactory.createValue(4), ValueFactory.createValue(JTSPolygon2D)});
    // and register this new driver...

    dsf.getSourceManager().register("ds1", driver1);

    // second datasource
    final MemoryDataSetDriver driver2 =
        new MemoryDataSetDriver(
            new String[] {"pk", "geom"},
            new Type[] {
              TypeFactory.createType(Type.INT, new PrimaryKeyConstraint()),
              TypeFactory.createType(Type.GEOMETRY)
            });

    driver1.addValues(
        new Value[] {ValueFactory.createValue(1), ValueFactory.createValue(JTSMultiPolygon2D)});
    // and register this new driver...
    dsf.getSourceManager().register("ds2", driver2);
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if ("modify".equals(e.getActionCommand())) {
      try {
        File globals = new File(configPath);

        // Table creation
        GdmsWriter globalsGW = new GdmsWriter(globals);
        String[] fieldNames1 = {
          "bufferSize",
          "amenitiesWeighting",
          "constructibilityWeighting",
          "idealhousingWeighting",
          "gaussDeviation",
          "segregationThreshold",
          "segregationTolerance",
          "householdMemory",
          "movingThreshold",
          "immigrantNumber",
          "numberOfTurns",
          "year",
          "threshold_1",
          "threshold_2",
          "threshold_3",
          "threshold_4"
        };

        org.gdms.data.types.Type integ = TypeFactory.createType(64);
        org.gdms.data.types.Type doubl = TypeFactory.createType(16);
        org.gdms.data.types.Type[] fieldTypes1 = {
          doubl, doubl, doubl, doubl, doubl, doubl, doubl, integ, doubl, integ, integ, integ, doubl,
          doubl, doubl, doubl
        };
        Metadata m1 = new DefaultMetadata(fieldTypes1, fieldNames1);
        globalsGW.writeMetadata(0, m1);

        // Table filling
        Map<String, JSpinner> sp = spp.getSpinners();
        Double hM = (Double) sp.get("householdMemory").getValue();
        Integer hMi = hM.intValue();
        Double iN = (Double) sp.get("immigrantNumber").getValue();
        Integer iNi = iN.intValue();
        Double nOT = (Double) sp.get("numberOfTurns").getValue();
        Integer nOTi = nOT.intValue();
        Double y = (Double) sp.get("year").getValue();
        Integer yi = y.intValue();
        globalsGW.addValues(
            new Value[] {
              ValueFactory.createValue((Double) sp.get("bufferSize").getValue()),
              ValueFactory.createValue((Double) sp.get("amenitiesWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("constructibilityWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("idealhousingWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("gaussDeviation").getValue()),
              ValueFactory.createValue((Double) sp.get("segregationThreshold").getValue()),
              ValueFactory.createValue((Double) sp.get("segregationTolerance").getValue()),
              ValueFactory.createValue(hMi),
              ValueFactory.createValue((Double) sp.get("movingThreshold").getValue()),
              ValueFactory.createValue(iNi),
              ValueFactory.createValue(nOTi),
              ValueFactory.createValue(yi),
              ValueFactory.createValue((Double) sp.get("threshold_1").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_2").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_3").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_4").getValue()),
            });

        // Table closing
        globalsGW.writeRowIndexes();
        globalsGW.writeExtent();
        globalsGW.writeWritenRowCount();
        globalsGW.close();

        try {
          if (spp.getSelections().get("statistical").isSelected()) {
            new LaunchFrame(configPath, "statistical");
          } else if (spp.getSelections().get("schelling").isSelected()) {
            new LaunchFrame(configPath, "schelling");
          }
        } catch (DriverException ex) {
          Services.getErrorManager().error("Driver Exception", ex);
          JOptionPane.showMessageDialog(
              this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
          return;
        } catch (DataSourceCreationException ex) {
          Services.getErrorManager().error("DataSourceCreation Exception", ex);
          JOptionPane.showMessageDialog(
              this,
              "Some DataSource creation error has occurred.",
              "DataSource Creation Error",
              JOptionPane.WARNING_MESSAGE);
          return;
        }
        dispose();
      } catch (IOException ex) {
        Services.getErrorManager().error("I/O Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some I/O error has occurred.", "I/O Error", JOptionPane.WARNING_MESSAGE);
        return;
      } catch (DriverException ex) {
        Services.getErrorManager().error("Driver Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
        return;
      }

    } else {
      try {
        new LaunchFrame(configPath, oldChoice);
      } catch (DriverException ex) {
        Services.getErrorManager().error("Driver Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
        return;
      } catch (DataSourceCreationException ex) {
        Services.getErrorManager().error("DataSourceCreation Exception", ex);
        JOptionPane.showMessageDialog(
            this,
            "Some DataSource creation error has occurred.",
            "DataSource Creation Error",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      dispose();
    }
  }
Beispiel #11
0
 @Override
 public Type getType(Type[] types) {
   return TypeFactory.createType(Type.DOUBLE);
 }
Beispiel #12
0
 public SumDriver(double n) {
   super(
       new DefaultMetadata(
           new Type[] {TypeFactory.createType(Type.DOUBLE)}, new String[] {"sum"}));
   sum = n;
 }