Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.GraphDatabaseService


   *            formated query string for this dynamic layer
   */
  public DynamicLayerConfig(DynamicLayer parent, String name, int geometryType, String query) {
    this.parent = parent;
   
    GraphDatabaseService database = parent.getSpatialDatabase().getDatabase();
    Transaction tx = database.beginTx();
    try {
      Node node = database.createNode();
      node.setProperty(PROP_LAYER, name);
      node.setProperty(PROP_TYPE, geometryType);
      node.setProperty(PROP_QUERY, query);
      parent.getLayerNode().createRelationshipTo(node, SpatialRelationshipTypes.LAYER_CONFIG);
      tx.success();
View Full Code Here


    deleteDatabase(true);

    System.out.println("\n=== Test import map.osm, create DynamicLayer and export shapefile ===");
    importMapOSM();

    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(databasePath);
    try {
      // START SNIPPET: exportShapefileFromOSM
            SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
            try (Transaction tx = database.beginTx()) {
          OSMLayer layer = (OSMLayer) spatialService.getLayer("map.osm");
          DynamicLayerConfig wayLayer = layer.addSimpleDynamicLayer(Constants.GTYPE_LINESTRING);
          ShapefileExporter shpExporter = new ShapefileExporter(database);
          shpExporter.exportLayer(wayLayer.getName());
                tx.success();
            }
      // END SNIPPET: exportShapefileFromOSM
    } finally {
      database.shutdown();
    }
  }
View Full Code Here

    deleteDatabase(true);

    System.out.println("\n=== Test import map.osm, create DynamicLayer and export shapefile ===");
    importMapOSM();

    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(databasePath);
    try {
      // START SNIPPET: exportShapefileFromQuery
      SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
      Layer layer = spatialService.getLayer("map.osm");
      LayerIndexReader spatialIndex = layer.getIndex();
      System.out.println("Have " + spatialIndex.count() + " geometries in " + spatialIndex.getBoundingBox());

      Envelope bbox = new Envelope(12.94, 12.96, 56.04, 56.06);
            try (Transaction tx = database.beginTx()) {
                List<SpatialDatabaseRecord> results = GeoPipeline
                    .startIntersectWindowSearch(layer, bbox)
                    .toSpatialDatabaseRecordList();

                spatialService.createResultsLayer("results", results);
                ShapefileExporter shpExporter = new ShapefileExporter(database);
                shpExporter.exportLayer("results");
                tx.success();
      // END SNIPPET: exportShapefileFromQuery

          doGeometryTestsOnResults(bbox, results);
            }
    } finally {
      database.shutdown();
    }
  }
View Full Code Here

    public static final String MESSAGE = "I want to see this";

    @Test
    public void testSuppressedException() throws Exception {
        try {
        GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
        try (Transaction tx = db.beginTx()) {
            Node n = db.createNode();
            try (Transaction tx2 = db.beginTx()) {
                n.setProperty("foo","bar");
                if (true) throw new Exception(MESSAGE);
                tx2.success();
            }
            tx.success();
View Full Code Here

    }

    @Test
    public void testSuppressedExceptionTopLevel() throws Exception {
        try {
            GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
            try (Transaction tx = db.beginTx()) {
                Node n = db.createNode();
                n.setProperty("foo", "bar");
                if (true) throw new Exception(MESSAGE);
                tx.success();
            }
        } catch (Exception e) {
View Full Code Here

    } else {
      layerName = args[2];
      commitInterval = Integer.parseInt(args[3]);
    }
   
    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(neoPath);
    try {
          ShapefileImporter importer = new ShapefileImporter(database, new NullListener(), commitInterval);
          importer.importFile(shpPath, layerName);
      } finally {
      database.shutdown();
    }
  }
View Full Code Here

    for (Map.Entry<Node, PropertyMapper> entry : loadMappers().entrySet()) {
      if (!toSave.remove(entry.getValue())) {
        toDelete.add(entry.getKey());
      }
    }
    GraphDatabaseService db = layer.getLayerNode().getGraphDatabase();
    Transaction tx = db.beginTx();
    try {
      for (Node node : toDelete) {
        for (Relationship rel : node.getRelationships()) {
          rel.delete();
        }
        node.delete();
      }
      for (PropertyMapper mapper : toSave) {
        Node node = db.createNode();
        mapper.save(node);
        layer.getLayerNode().createRelationshipTo(node, SpatialRelationshipTypes.PROPERTY_MAPPING);
      }
      tx.success();
    } finally {
View Full Code Here

   
  }

  @Test
  public void testIndexingExistingPointNodes() {
    GraphDatabaseService db = graphDb();
    SpatialDatabaseService sdb = new SpatialDatabaseService(db);
    SimplePointLayer layer = sdb.createSimplePointLayer("my-points", "x", "y");

    Coordinate[] coords = makeCoordinateDataFromTextFile("NEO4J-SPATIAL.txt", testOrigin);
    try (Transaction tx = db.beginTx()) {
      for (Coordinate coordinate : coords) {
        Node n = db.createNode();
        n.setProperty("x", coordinate.x);
        n.setProperty("y", coordinate.y);
        layer.add(n);
      }
      tx.success();
View Full Code Here

    assertEquals(coords.length, layer.getIndex().count());
  }
 
  @Test
  public void testIndexingExistingPointNodesWithMultipleLocations() {
    GraphDatabaseService db = graphDb();
    SpatialDatabaseService sdb = new SpatialDatabaseService(db);
    double x_offset = 0.15, y_offset = 0.15;
    SimplePointLayer layerA = sdb.createSimplePointLayer("my-points-A", "xa", "ya", "bbox_a");
    SimplePointLayer layerB = sdb.createSimplePointLayer("my-points-B", "xb", "yb", "bbox_b");

    Coordinate[] coords = makeCoordinateDataFromTextFile("NEO4J-SPATIAL.txt", testOrigin);
    try (Transaction tx = db.beginTx()) {
      for (Coordinate coordinate : coords) {
        Node n = db.createNode();
        n.setProperty("xa", coordinate.x);
        n.setProperty("ya", coordinate.y);
        n.setProperty("xb", coordinate.x + x_offset);
        n.setProperty("yb", coordinate.y + y_offset);

        layerA.add(n);
        layerB.add(n);

        tx.success();
      }
    }
    saveLayerAsImage(layerA, 700, 70);
    saveLayerAsImage(layerB, 700, 70);
    Envelope bboxA = layerA.getIndex().getBoundingBox();
    Envelope bboxB = layerB.getIndex().getBoundingBox();
    double[] centreA = bboxA.centre();
    double[] centreB = bboxB.centre();

    List<SpatialDatabaseRecord> resultsA;
    List<SpatialDatabaseRecord> resultsB;
    try (Transaction tx = db.beginTx()) {
      resultsA = GeoPipeline.startNearestNeighborLatLonSearch(layerA,
          new Coordinate(centreA[0] + 0.1, centreA[1]), 10.0).toSpatialDatabaseRecordList();
      resultsB = GeoPipeline.startNearestNeighborLatLonSearch(layerB,
          new Coordinate(centreB[0] + 0.1, centreB[1]), 10.0).toSpatialDatabaseRecordList();
      tx.success();
View Full Code Here

      throw new IOException("The parameters map isn't correct!!");
    }
   
      File neodir = (File) DIRECTORY.lookUp(params);

    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(neodir.getAbsolutePath());
    Neo4jSpatialDataStore dataStore = new Neo4jSpatialDataStore(db);

    return dataStore;
  }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.GraphDatabaseService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.