Package org.neo4j.gis.spatial.osm

Examples of org.neo4j.gis.spatial.osm.OSMLayer


    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
View Full Code Here


    shutdownDatabase();
  }

  public void testAnalysis2(String osm, int years, int days) throws IOException {
    SpatialDatabaseService spatial = new SpatialDatabaseService(graphDb());
    OSMLayer layer = (OSMLayer) spatial.getLayer(osm);
    OSMDataset dataset = (OSMDataset) layer.getDataset();
    Map<String, User> userIndex = new HashMap<String, User>();
    long latestTimestamp = 0L;
    long firstTimestamp = Long.MAX_VALUE;

    for (Node cNode : dataset.getAllChangesetNodes()) {
      long timestamp = (Long) cNode.getProperty("timestamp", 0L);
      Node userNode = dataset.getUser(cNode);
      String name = (String) userNode.getProperty("name");

      User user = userIndex.get(name);
      if (user == null) {
        user = new User(userNode.getId(), name);
        userIndex.put(name, user);
      }
      user.addChangeset(cNode, timestamp);
      if (latestTimestamp < timestamp)
        latestTimestamp = timestamp;
      if (firstTimestamp > timestamp)
        firstTimestamp = timestamp;
    }
    SortedSet<User> topTen = getTopTen(userIndex);
   
    Date latest = new Date(latestTimestamp);
    Calendar time = Calendar.getInstance();
    time.setTime(latest);
    int slidesPerYear = 360/days;
    int slideCount = slidesPerYear * years;
    long msPerSlide = days * 24 * 3600000;
    int timeWindow = 15;
    StringBuffer userQuery = new StringBuffer();
    int user_rank = 1;
    for (User user : topTen) {
      if (userQuery.length() > 0)
        userQuery.append(" or ");
      userQuery.append("user = '" + user.name + "'");
      user_rank++;
    }
    LinkedHashMap<DynamicLayerConfig,Long> slides = new LinkedHashMap<DynamicLayerConfig,Long>();
    for (int i = -timeWindow; i < slideCount; i++) {
      long timestamp = latestTimestamp - i * msPerSlide;
      long minTime = timestamp;
      long maxTime = timestamp + 15 * msPerSlide;
      time.setTimeInMillis(timestamp);
      Date date = new Date(timestamp);
      System.out.println("Preparing slides for " + date);
      String name = osm + "-" + date;
      DynamicLayerConfig config = layer.addLayerConfig(name, Constants.GTYPE_GEOMETRY, "timestamp > " + minTime + " and timestamp < "
          + maxTime + " and (" + userQuery + ")");
      System.out.println("Added dynamic layer '"+config.getName()+"' with CQL: "+config.getQuery());
      slides.put(config, timestamp);
    }
    DynamicLayerConfig config = layer.addLayerConfig(osm + "-top-ten", Constants.GTYPE_GEOMETRY, userQuery.toString());
    System.out.println("Added dynamic layer '"+config.getName()+"' with CQL: "+config.getQuery());
    slides.clear();
    slides.put(config, 0L);

    StyledImageExporter imageExporter = new StyledImageExporter(graphDb());
View Full Code Here

        // Define dynamic layers
        ArrayList<Layer> layers = new ArrayList<Layer>();
        try (Transaction tx = graphDb().beginTx()) {
            SpatialDatabaseService spatialService = new SpatialDatabaseService(graphDb());
            OSMLayer osmLayer = (OSMLayer) spatialService.getLayer(osmFile);
            LinearRing ring = osmLayer.getGeometryFactory().createLinearRing(
                    new Coordinate[] { new Coordinate(bbox.getMinX(), bbox.getMinY()), new Coordinate(bbox.getMinX(), bbox.getMaxY()),
                            new Coordinate(bbox.getMaxX(), bbox.getMaxY()), new Coordinate(bbox.getMaxX(), bbox.getMinY()),
                            new Coordinate(bbox.getMinX(), bbox.getMinY()) });
            Polygon polygon = osmLayer.getGeometryFactory().createPolygon(ring, null);
            layers.add(osmLayer.addLayerConfig("CQL1-highway", GTYPE_LINESTRING, "highway is not null and geometryType(the_geom) = 'LineString'"));
            layers.add(osmLayer.addLayerConfig("CQL2-residential", GTYPE_LINESTRING, "highway = 'residential' and geometryType(the_geom) = 'LineString'"));
            layers.add(osmLayer.addLayerConfig("CQL3-natural", GTYPE_POLYGON, "natural is not null and geometryType(the_geom) = 'Polygon'"));
            layers.add(osmLayer.addLayerConfig("CQL4-water", GTYPE_POLYGON, "natural = 'water' and geometryType(the_geom) = 'Polygon'"));
            layers.add(osmLayer.addLayerConfig("CQL5-bbox", GTYPE_GEOMETRY, "BBOX(the_geom, " + toCoordinateText(bbox) + ")"));
            layers.add(osmLayer.addLayerConfig("CQL6-bbox-polygon", GTYPE_GEOMETRY, "within(the_geom, POLYGON(("
                    + toCoordinateText(polygon.getCoordinates()) + ")))"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "primary"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "secondary"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "tertiary"));
            layers.add(osmLayer.addSimpleDynamicLayer(GTYPE_LINESTRING, "highway=*"));
            layers.add(osmLayer.addSimpleDynamicLayer(GTYPE_LINESTRING, "highway=footway, bicycle=yes"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway=*, bicycle=yes"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "residential"));
            layers.add(osmLayer.addCQLDynamicLayerOnAttribute("highway", "residential", GTYPE_LINESTRING));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "footway"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "cycleway"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "track"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "path"));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", "unclassified"));
            layers.add(osmLayer.addSimpleDynamicLayer("amenity", "parking", GTYPE_POLYGON));
            layers.add(osmLayer.addSimpleDynamicLayer("railway", null));
            layers.add(osmLayer.addSimpleDynamicLayer("highway", null));
            layers.add(osmLayer.addSimpleDynamicLayer("waterway", null));
            layers.add(osmLayer.addSimpleDynamicLayer("building", null, GTYPE_POLYGON));
            layers.add(osmLayer.addCQLDynamicLayerOnAttribute("building", null, GTYPE_POLYGON));
            layers.add(osmLayer.addSimpleDynamicLayer("natural", null, GTYPE_GEOMETRY));
            layers.add(osmLayer.addSimpleDynamicLayer("natural", "water", GTYPE_POLYGON));
            layers.add(osmLayer.addSimpleDynamicLayer("natural", "wood", GTYPE_POLYGON));
            layers.add(osmLayer.addSimpleDynamicLayer("natural", "coastline"));
            layers.add(osmLayer.addSimpleDynamicLayer("natural", "beach"));
            layers.add(osmLayer.addSimpleDynamicLayer(GTYPE_POLYGON));
            layers.add(osmLayer.addSimpleDynamicLayer(GTYPE_POINT));
            layers.add(osmLayer.addCQLDynamicLayerOnGeometryType(GTYPE_POLYGON));
            layers.add(osmLayer.addCQLDynamicLayerOnGeometryType(GTYPE_POINT));
            assertEquals(layers.size() + 1, osmLayer.getLayerNames().size());
            tx.success();
        }
    // Now export the layers to files
    // First prepare the SHP and PNG exporters
    ShapefileExporter shpExporter = new ShapefileExporter(graphDb());
View Full Code Here

    printDatabaseStats();

    // Define dynamic layers
    List<Layer> layers = new ArrayList<Layer>();
    SpatialDatabaseService spatialService = new SpatialDatabaseService(graphDb());
    OSMLayer osmLayer = (OSMLayer) spatialService.getLayer(osm);
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "primary"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "secondary"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "tertiary"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "residential"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "footway"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "cycleway"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "track"));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", "path"));
    layers.add(osmLayer.addSimpleDynamicLayer("railway", null));
    layers.add(osmLayer.addSimpleDynamicLayer("highway", null));

    // Now test snapping to a layer
    GeometryFactory factory = osmLayer.getGeometryFactory();
    EditableLayerImpl results = (EditableLayerImpl) spatialService.getOrCreateEditableLayer("testSnapping_results");
    String[] fieldsNames = new String[] { "snap-id", "description", "distance" };
    results.setExtraPropertyNames(fieldsNames);
    Point point = factory.createPoint(new Coordinate(12.9777, 56.0555));
    results.add(point, fieldsNames, new Object[] { 0L, "Point to snap", 0L });
    for (String layerName : new String[] { "railway", "highway-residential" }) {
      Layer layer = osmLayer.getLayer(layerName);
      assertNotNull("Missing layer: " + layerName, layer);
      System.out.println("Closest features in " + layerName + " to point " + point + ":");
      List<PointResult> edgeResults = SpatialTopologyUtils.findClosestEdges(point, layer);
      for (PointResult result : edgeResults) {
        System.out.println("\t" + result);
        results.add(result.getKey(), fieldsNames, new Object[] { result.getValue().getGeomNode().getId(),
            "Snapped point to layer " + layerName + ": " + result.getValue().getGeometry().toString(),
            (long) (1000000 * result.getDistance()) });
      }
      if (edgeResults.size() > 0) {
        PointResult closest = edgeResults.get(0);
        Point closestPoint = closest.getKey();

        SpatialDatabaseRecord wayRecord = closest.getValue();
        OSMDataset.Way way = ((OSMDataset) osmLayer.getDataset()).getWayFrom(wayRecord.getGeomNode());
        OSMDataset.WayPoint wayPoint = way.getPointAt(closestPoint.getCoordinate());
      }
    }

  }
View Full Code Here

TOP

Related Classes of org.neo4j.gis.spatial.osm.OSMLayer

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.