---
# System prepended metadata

title: Untitled

---

## Klasy do opakowania Postgisa

Musi dostraczać:
* funkcjonalności:
    * FastestRoute(point, point) <- przyjmuje jakiś obiekt punktu
    * POIPointInBuffer(point, distance) -> Jakiś obiekt punktu
    * PointOnRouteAfter(distance)
    * FindPoint(x, y) lub (lon, lat) lub nazwa -> Jakiś obiekt punktu

```python=
    NEAREST_START_POINT_QUERY = "SELECT t.source, ST_SetSrid(ST_MakePoint(t.x1, t.y1), " \
                                "4326) FROM (SELECT source, x1, y1 FROM hh_2po_4pgr " \
                                "ORDER BY sqrt((x1 - {})*(x1 - {}) + (y1 - {})*(y1 - {}))" \
                                "LIMIT 1) as t;"
    NEAREST_END_POINT_QUERY = "SELECT t.target, ST_SetSrid(ST_MakePoint(t.x2, t.y2), " \
                              "4326) FROM (SELECT target, x2, y2 FROM hh_2po_4pgr " \
                              "ORDER BY sqrt((x2 - {})*(x2 - {}) + (y2 - {})*(y2 - {}))" \
                              "LIMIT 1) as t;"
    ROUTE_LENGTH_QUERY = "SELECT ST_Length('{}'::geography);"
    LOCATIONS_NEAR_ROUTE_QUERY = "SELECT * FROM (SELECT id, geom_coords, ST_Distance" \
                                 "('{}'::geography, geom_coords::geography) AS dist FROM " \
                                 "locations) AS t WHERE t.dist < {}"
    POINTS_DISTANCE_QUERY = "SELECT ST_Distance('{}'::geography, '{}'::geography);"
    HUMAN_READABLE_QUERY = "SELECT ST_AsText('{}');"
    DUMP_POINTS_QUERY = "SELECT ST_DumpPoints('{}');"
    ROUTE_AND_TIME_QUERY = "SELECT geom_way, km / kmh as time FROM pgr_dijkstra('" \
                           "SELECT id, source, target, km as cost FROM hh_2po_4pgr', " \
                           "{}, {}, false) AS route1 LEFT JOIN hh_2po_4pgr as route2 " \
                           "ON (route1.edge = route2.id) ORDER BY seq;"
    UNION_ROUTE_QUERY = "SELECT ST_Union(%s);"

    FORMAT_STRING_POINT = "POINT({:f} {:f})"
    FORMAT_STRING_DUMP_POINTS = "(\"<{:d},{:d}>\",{})"

```
## UI
[https://github.com/openlayers/openlayers](https://github.com/openlayers/openlayers)

```javascript=
olMap.on('click', function(event) {
	if (startPoint.getGeometry() == null) {
		startPoint.setGeometry(new ol.geom.Point(event.coordinate));
	} else if (destPoint.getGeometry() == null) {
		destPoint.setGeometry(new ol.geom.Point(event.coordinate));

		var startCoord = transform(startPoint.getGeometry().getCoordinates());
		var destCoord = transform(destPoint.getGeometry().getCoordinates());
		var viewparams = {
			'start' : { 'x' : startCoord[0], 'y' : startCoord[1] },
			'end' : { 'x' : destCoord[0], 'y' : destCoord[1] }
		};
		params.viewparams = viewparams;
	}
});

drawPath = function(points) {
	let locations = new Array();
	for(let point of points) {
		locations.push([point.x, point.y]);
	}

	var route = new ol.geom.LineString(locations).transform('EPSG:4326', 'EPSG:3857');

	var feature = new ol.Feature({
		type: 'route',
		geometry: route
	});

	feature.setStyle(styles.route);
	vectorSource.addFeature(feature);
}

```