1 | import java.nio.file.Files;
|
---|
2 | import java.nio.file.Paths;
|
---|
3 |
|
---|
4 | import org.odmg.Database;
|
---|
5 | import org.odmg.OQLQuery;
|
---|
6 | import org.odmg.Transaction;
|
---|
7 |
|
---|
8 | import rasj.RasGMArray;
|
---|
9 | import rasj.RasImplementation;
|
---|
10 | import rasj.RasMInterval;
|
---|
11 |
|
---|
12 | public class CreateCollection{
|
---|
13 |
|
---|
14 | public static void main(String [] args){
|
---|
15 |
|
---|
16 | RasImplementation rasImpl = new RasImplementation("http://localhost:7001");
|
---|
17 | Transaction transaction = null;
|
---|
18 |
|
---|
19 | try{
|
---|
20 |
|
---|
21 | rasImpl.setUserIdentification("rasadmin", "rasadmin");
|
---|
22 | Database rasDb = rasImpl.newDatabase();
|
---|
23 |
|
---|
24 | rasDb.open("RASBASE", Database.OPEN_READ_WRITE);
|
---|
25 |
|
---|
26 | transaction = rasImpl.newTransaction();
|
---|
27 | transaction.begin();
|
---|
28 |
|
---|
29 | OQLQuery myQu = rasImpl.newOQLQuery();
|
---|
30 |
|
---|
31 | myQu.create("create collection my_collection GreySet");
|
---|
32 | myQu.execute();
|
---|
33 |
|
---|
34 | RasGMArray mdd = createMDDFromFile("/tmp/polygon.tiff");
|
---|
35 | mdd.setObjectTypeName("GreyImage");
|
---|
36 |
|
---|
37 | myQu.create("insert into my_collection values inv_tiff( $1 )");
|
---|
38 | myQu.bind(mdd);
|
---|
39 | myQu.execute();
|
---|
40 |
|
---|
41 | }
|
---|
42 | catch(Exception ex){
|
---|
43 |
|
---|
44 | ex.printStackTrace();
|
---|
45 |
|
---|
46 | }
|
---|
47 | finally{
|
---|
48 | if(transaction != null){
|
---|
49 | transaction.commit();
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static RasGMArray createMDDFromFile(String fileName) throws Exception{
|
---|
56 |
|
---|
57 | RasGMArray mdd = new RasGMArray(new RasMInterval("[1:422,1:229]"), 1);
|
---|
58 | byte [] array = Files.readAllBytes(Paths.get(fileName));
|
---|
59 | mdd.setArray(array);
|
---|
60 |
|
---|
61 | return mdd;
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|