Package org.neo4j.gis.spatial

Examples of org.neo4j.gis.spatial.SpatialDatabaseRecord


        Trkseg track = gpx.getTrk(0).getTrkseg(0);

        // Start a new transaction
        Transaction tx = graphDb.beginTx();
        // Contains the record that was added previously (in order to create a relation between the new and the previous node)
        SpatialDatabaseRecord fromrecord = null;

        // Iterate all points
        for (int i = 0; i < track.getTrkptCount(); i++) {

            // Create a new coordinate for this point
            Coordinate to = new Coordinate(track.getTrkpt(i).getLon().doubleValue(),track.getTrkpt(i).getLat().doubleValue());

            // Check whether we can find a node from which is located within a distance of 20 meters
            List<GeoPipeFlow> closests = GeoPipeline.startNearestNeighborLatLonSearch(runningLayer, to, 0.02).sort("OrthodromicDistance").getMin("OrthodromicDistance").toList();
            SpatialDatabaseRecord torecord = null;

            // If first time, we add all nodes. Otherwise, we check whether we find a node that is close enough to the current location
            if (!firsttime && (closests.size() == 1)) {
                // Retrieve the node
                System.out.println("Using existing: " + closests.get(0).getProperty("OrthodromicDistance"));
                torecord = closests.get(0).getRecord();
                // Recalculate average speed
                double previousspeed  =  (Double)torecord.getProperty("speed");
                int previousoccurences =  (Integer)torecord.getProperty("occurences");
                double currentspeed = analyzer.getHorizontalSpeed(track.getTrkpt(i).getTime());
                double denormalizespeed = previousspeed * previousoccurences;
                double newspeed = ((denormalizespeed + currentspeed) / (previousoccurences + 1));
                // Update the data accordingly
                torecord.setProperty("speed",newspeed);
                torecord.setProperty("occurences",previousoccurences+1);
            }
            else {
                // New node, add it
                torecord = runningLayer.add(runningLayer.getGeometryFactory().createPoint(to));
                // Set the data accordingly
                torecord.setProperty("speed", analyzer.getHorizontalSpeed(track.getTrkpt(i).getTime()));
                torecord.setProperty("occurences", 1);
            }

            // If a previous node is available (and they are not identical), add a directed relationship between both
            if (fromrecord != null && (!fromrecord.equals(torecord)))  {
                Relationship next = fromrecord.getGeomNode().createRelationshipTo(torecord.getGeomNode(), RelTypes.NEXT);
            }
            // Previous record is put on new record
            fromrecord = torecord;
        }

View Full Code Here


    private boolean queryIndexNode(Envelope indexNodeEnvelope) {
        return filterEnvelope == null || filterEnvelope.intersects(indexNodeEnvelope);
    }

  private boolean queryLeafNode(Node indexNode) {
    SpatialDatabaseRecord dbRecord = new SpatialDatabaseRecord(layer, indexNode);
    SimpleFeature feature = builder.buildFeature(dbRecord);
    return filter.evaluate(feature);
  }
View Full Code Here

        double x = 10.0 + Math.random() * 10.0;
        double y = 10.0 + Math.random() * 10.0;
        String name = "Fake Geometry " + i;
        // System.out.println("Creating point '" + name +
        // "' at location x:" + x + " y:" + y);
        SpatialDatabaseRecord record = layer.add(x, y);
        record.getGeomNode().setProperty("name", name);
      }
      tx.success();
      tx.close();
      System.out.println("Finished writing " + records + " point records to database");
    } catch (Exception e) {
View Full Code Here

   *
   */
  public SimpleFeature next() throws IOException, IllegalArgumentException, NoSuchElementException {
    if (results == null) return null;
   
    SpatialDatabaseRecord record = results.next();
    if (record == null) return null;
   
    builder.reset();
      builder.set(FEATURE_PROP_GEOM, record.getGeometry());
         
      if (extraPropertyNames != null) {
        for (int i = 0; i < extraPropertyNames.length; i++) {
          if (record.hasProperty(extraPropertyNames[i])) {
            builder.set(extraPropertyNames[i], record.getProperty(extraPropertyNames[i]));
            }
        }
      }
         
      return builder.buildFeature(record.getId());           
  }
View Full Code Here

  @Override
  protected Node underlyingObjectToObject(GeoPipeFlow current) {
        this.current = current;

        SpatialDatabaseRecord record = current.getRecord();
        // It looks to be possible to have SpatialDatabaseRecords without any
    // associated 'real' node. If this is the case is it OK to just return
    // null or should we return the geomNode
   
    Object idString = record.getProperty("id");
    Node result = null;
   
    if(idString != null){
      result = spatialDatabase.getDatabase().getNodeById(Long.valueOf(idString.toString()));
    }
View Full Code Here

    return nodeIterator.hasNext();
  }

  @Override
  public SpatialDatabaseRecord next() {
    return new SpatialDatabaseRecord(layer, nodeIterator.next());
  }
View Full Code Here

        return filterEnvelope == null || filterEnvelope.intersects(envelope);
  }

  @Override
  public boolean geometryMatches(Node geomNode) {
    SimpleFeature feature = featureBuilder.buildFeature(new SpatialDatabaseRecord(this.layer, geomNode));
    return filter.evaluate(feature);
  }
View Full Code Here

        // check if node already exists in layer
        Node matchingNode = findExistingNode( geometry );

        if (matchingNode == null)
        {
          SpatialDatabaseRecord newNode = layer.add(
                decodeGeometry, new String[] { "id" },
                new Object[] { geometry.getId() } );

    // index geomNode with node of geometry
    idLookup.add(newNode.getGeomNode(), "id", geometry.getId());
  }
        else
        {
          // update existing geoNode
          layer.update(matchingNode.getId(), decodeGeometry);     
View Full Code Here

TOP

Related Classes of org.neo4j.gis.spatial.SpatialDatabaseRecord

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.