Hi,

i try with java, the code below should work:

public class Space {
    
    private static String remote = "remote:localhost/";

    public static void main(String[] args) {

        String nomeDb = "GeoByJava10";
        String currentPath = remote + nomeDb;

        OServerAdmin serverAdmin;
        OrientGraph g; 
        
        try {
            serverAdmin = new OServerAdmin(currentPath).connect("root", 
"root");
            
            if (serverAdmin.existsDatabase()) {
                System.out.println("Db already exist");
    
            } else {
                serverAdmin.createDatabase(nomeDb, "graph", "plocal");
                System.out.println("Db created");

            }    
            
            g = new OrientGraph(currentPath);
                    
            OrientVertexType type = g.createVertexType("Spazio");
            type.createProperty("name", OType.STRING);
            type.createProperty("latitude", OType.DOUBLE);
            type.createProperty("longitude", OType.DOUBLE);
               
            String sql = "CREATE INDEX Spazio.l_lon ON 
Spazio(latitude,longitude) SPATIAL ENGINE LUCENE";
            OCommandSQL createIndex = new OCommandSQL(sql);
            Object done = g.command(createIndex).execute(new Object[0]);
              
            OrientVertex v1=g.addVertex("class:Spazio");
            v1.setProperties("name","A");
            v1.setProperties("latitude",32.783333);
            v1.setProperties("longitude",-79.916667);
            
            OrientVertex v2=g.addVertex("class:Spazio");
            v2.setProperties("name","B");
            v2.setProperties("latitude",34.134333);
            v2.setProperties("longitude",45.223145);
                    
            g.commit();
            
            Iterable<Vertex> risultato = g.command(new 
OSQLSynchQuery<Vertex>("select from Spazio where 
[latitude,longitude,$spatial] NEAR [32.783333,-79.916667,{\"maxDistance\": 
1000}]")).execute();         
            
            for (Vertex v : risultato){
                System.out.println("Result: " + v.getProperty("name"));
                System.out.println("Result: " + v.getProperty("latitude"));
                System.out.println("Result: " + v.getProperty("longitude"));
            }
                
                    
            g.shutdown();
            
            serverAdmin.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
            
    }

}

regards,
Savio L.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to