Java Code Examples for org.mapdb.Fun#Tuple2

The following examples show how to use org.mapdb.Fun#Tuple2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VehicleStates.java    From traffic-engine with GNU General Public License v3.0 6 votes vote down vote up
public void placeVehicleInTile(Fun.Tuple2<Integer, Integer> tile, Long vehicleId) {
	synchronized (vehicleCache) {
		if(!tileVehicleMap.containsKey(tile)) {
			tileVehicleMap.put(tile, new ConcurrentHashMap<>());
		}

		if(!tileCount.containsKey(tile)){
			tileCount.put(tile, new AtomicInteger());
		}

		if(tileVehicleMap.get(tile).containsKey(vehicleId)) {
			tileCount.get(tile).decrementAndGet();
			tileVehicleMap.get(tile).remove(vehicleId);
		}

		tileCount.get(tile).incrementAndGet();
		tileVehicleMap.get(tile).put(vehicleId, true);
	}
}
 
Example 2
Source File: OSMDataStore.java    From traffic-engine with GNU General Public License v3.0 6 votes vote down vote up
public void loadPbfFile(Fun.Tuple2<Integer, Integer> tile, Envelope env, File pbfFile) {

		log.log(Level.INFO, "loading osm from: " + pbfFile.getAbsolutePath());

		// load pbf osm source and merge into traffic engine
		OSM osm = new OSM(null);
		osm.readFromFile(pbfFile.getAbsolutePath().toString());
		try {
			// add OSM an truncate geometries
			OSMArea osmArea = addOsm(tile, env, osm, false);
		}
		catch (Exception e) {
			e.printStackTrace();
			log.log(Level.SEVERE, "Unable to load osm: " + pbfFile.getAbsolutePath());
		}
		finally {
			osm.close();
		}
	}
 
Example 3
Source File: VehicleStates.java    From traffic-engine with GNU General Public License v3.0 5 votes vote down vote up
public List<GPSPoint> getVehicleTilePoints(Fun.Tuple2<Integer, Integer> tile) {
	List<GPSPoint> points = new ArrayList<>();

	if(tileVehicleMap.containsKey(tile)) {
		for (Long vehicleId : tileVehicleMap.get(tile).keySet()) {
			points.add(vehicleCache.get(vehicleId).lastPoint);
		}
	}

	return points;
}
 
Example 4
Source File: VehicleStates.java    From traffic-engine with GNU General Public License v3.0 5 votes vote down vote up
public static Map<Fun.Tuple2<Integer, Integer>, AtomicInteger> sortByValue(Map<Fun.Tuple2<Integer, Integer>, AtomicInteger> map)
{
	Map<Fun.Tuple2<Integer, Integer>, AtomicInteger> result = new LinkedHashMap<>();
	Stream<Map.Entry<Fun.Tuple2<Integer, Integer>, AtomicInteger>> st = map.entrySet().stream();

	Comparator<Map.Entry<Fun.Tuple2<Integer, Integer>, AtomicInteger>> comparator =  Comparator.comparing(e -> e.getValue().get());

	st.sorted(comparator.reversed())
			.forEach(e -> result.put(e.getKey(), e.getValue()));

	return result;
}
 
Example 5
Source File: OSMDataStore.java    From traffic-engine with GNU General Public License v3.0 5 votes vote down vote up
public OSMArea checkOsm(double lat, double lon) {

		Fun.Tuple2<Integer, Integer> tile = getOsmId(lat, lon);

		if(!osmAreas.containsKey(tile)){
			synchronized (this){
				loadingOSM = true;
				loadOSMTile(tile);
				loadingOSM = false;
			}
		}
		return osmAreas.get(tile);
	}
 
Example 6
Source File: VehicleStates.java    From traffic-engine with GNU General Public License v3.0 4 votes vote down vote up
public Integer getVehicleTileCount(Fun.Tuple2<Integer, Integer> tile) {
	if(tileCount.containsKey(tile))
		return tileCount.get(tile).get();
	else
		return 0;
}
 
Example 7
Source File: OSMDataStore.java    From traffic-engine with GNU General Public License v3.0 3 votes vote down vote up
public static Fun.Tuple2<Integer, Integer> getOsmId(double lat, double lon) {

		int x = SpatialDataStore.getTileX(lon, Z_INDEX);
		int y = SpatialDataStore.getTileY(lat, Z_INDEX);

		return new Fun.Tuple2<Integer, Integer>(x, y);
	}
 
Example 8
Source File: GPSPoint.java    From traffic-engine with GNU General Public License v3.0 2 votes vote down vote up
public Fun.Tuple2<Integer, Integer> getTile() {

		return SpatialDataStore.getTile(lat, lon);
	}
 
Example 9
Source File: Jumper.java    From traffic-engine with GNU General Public License v3.0 2 votes vote down vote up
public Fun.Tuple2<Long, Long> getStartEndTuple() {
    return new Fun.Tuple2<>(startNodeId, endNodeId);

}
 
Example 10
Source File: Jumper.java    From traffic-engine with GNU General Public License v3.0 2 votes vote down vote up
public Fun.Tuple2<Long, Long> getEndStartTuple() {
    return new Fun.Tuple2<>(endNodeId, startNodeId);

}
 
Example 11
Source File: OSMDataStore.java    From traffic-engine with GNU General Public License v3.0 2 votes vote down vote up
private OSMArea addOsm(Fun.Tuple2<Integer, Integer> tile, Envelope env, OSM osm, Boolean keepCompleteGeometries) {


		String placeName = null;
		Long placePop = null;

		for( Entry<Long, Node> entry : osm.nodes.entrySet() ) {

			Long id = entry.getKey();
			Node node = entry.getValue();
			if (id ==259009337) {
				try {
					long pop = Long.parseLong(node.getTag("population"));
					if (placePop == null || placePop < pop) {
						placePop = pop;
						placeName = node.getTag("name");
					}
				} catch (Exception e) {

				}
			}
		}



		List<StreetSegment> segments = getStreetSegments(osm);


		List<SpatialDataItem> segmentItems = new ArrayList<>();
		List<SpatialDataItem> triplineItems = new ArrayList<>();

		for(StreetSegment segment : segments) {

			if(streetSegments.contains(segment.getSegmentId()))
				continue;

			if(segment.length > MIN_SEGMENT_LEN) {

				LengthIndexedLine lengthIndexedLine = new LengthIndexedLine(segment.getGeometry());

				double scale = (lengthIndexedLine.getEndIndex() - lengthIndexedLine.getStartIndex()) / segment.length;

				List<TripLine> tripLines = new ArrayList<TripLine>();

				tripLines.add(createTripLine(segment, 1, lengthIndexedLine, (OSMDataStore.INTERSECTION_MARGIN_METERS) * scale, OSMDataStore.INTERSECTION_MARGIN_METERS));
				tripLines.add(createTripLine(segment, 2, lengthIndexedLine, ((segment.length - OSMDataStore.INTERSECTION_MARGIN_METERS) * scale), segment.length - OSMDataStore.INTERSECTION_MARGIN_METERS));

				for(TripLine tripLine : tripLines) {
					triplineItems.add(tripLine);
				}
			}
			else {
				jumperDataStore.addJumper(new Jumper(segment));
			}
			
			if(!keepCompleteGeometries)
				segment.truncateGeometry();

			segmentItems.add(segment);

		}

		streetSegments.save(segmentItems);
		jumperDataStore.save();

		triplines.save(triplineItems);

		long zoneOffset =  timeZoneConverter.getOffsetForCoord(env.centre());

		OSMArea osmArea = new OSMArea(osmAreaIds.getNextId(), tile.a, tile.b, Z_INDEX, placeName, placePop, zoneOffset, env);

		osmAreas.put(tile, osmArea);
		db.commit();

		System.out.println("Loaded OSM " + tile.a + ", " + tile.b);
		if(placeName != null)
			System.out.println("\t" + placeName + ", " + placePop);

		return osmArea;
	}