Use ESPG 3857 for all geometry columns
This commit is contained in:
parent
ce8054b7ae
commit
dd72ed791f
|
@ -0,0 +1,30 @@
|
||||||
|
"""transform overtaking_event geometry to 3857
|
||||||
|
|
||||||
|
Revision ID: 587e69ecb466
|
||||||
|
Revises: f4b0f460254d
|
||||||
|
Create Date: 2023-04-01 14:30:49.927505
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "587e69ecb466"
|
||||||
|
down_revision = "f4b0f460254d"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute("UPDATE overtaking_event SET geometry = ST_Transform(geometry, 3857);")
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE overtaking_event ALTER COLUMN eometry TYPE geometry(POINT, 3857);"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE overtaking_event ALTER COLUMN overtaking_event.geometry TYPE geometry;"
|
||||||
|
)
|
||||||
|
op.execute("UPDATE overtaking_event SET geometry = ST_Transform(geometry, 4326);")
|
|
@ -8,7 +8,7 @@ import pytz
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import delete, select, and_
|
from sqlalchemy import delete, func, select, and_
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from obs.face.importer import ImportMeasurementsCsv
|
from obs.face.importer import ImportMeasurementsCsv
|
||||||
|
@ -306,11 +306,16 @@ async def import_overtaking_events(session, track, overtaking_events):
|
||||||
hex_hash=hex_hash,
|
hex_hash=hex_hash,
|
||||||
way_id=m.get("OSM_way_id"),
|
way_id=m.get("OSM_way_id"),
|
||||||
direction_reversed=m.get("OSM_way_orientation", 0) < 0,
|
direction_reversed=m.get("OSM_way_orientation", 0) < 0,
|
||||||
geometry=json.dumps(
|
geometry=func.ST_Transform(
|
||||||
|
func.ST_GeomFromGeoJSON(
|
||||||
|
json.dumps(
|
||||||
{
|
{
|
||||||
"type": "Point",
|
"type": "Point",
|
||||||
"coordinates": [m["longitude"], m["latitude"]],
|
"coordinates": [m["longitude"], m["latitude"]],
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
3857,
|
||||||
),
|
),
|
||||||
latitude=m["latitude"],
|
latitude=m["latitude"],
|
||||||
longitude=m["longitude"],
|
longitude=m["longitude"],
|
||||||
|
|
|
@ -191,9 +191,7 @@ async def stats(req):
|
||||||
.select_from(Region)
|
.select_from(Region)
|
||||||
.join(
|
.join(
|
||||||
OvertakingEvent,
|
OvertakingEvent,
|
||||||
func.ST_Within(
|
func.ST_Within(OvertakingEvent.geometry, Region.geometry),
|
||||||
func.ST_Transform(OvertakingEvent.geometry, 3857), Region.geometry
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.group_by(
|
.group_by(
|
||||||
Region.id,
|
Region.id,
|
||||||
|
|
|
@ -3,7 +3,7 @@ RETURNS TABLE(event_id bigint, geometry geometry, distance_overtaker float, dist
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
overtaking_event.id::bigint as event_id,
|
overtaking_event.id::bigint as event_id,
|
||||||
ST_Transform(overtaking_event.geometry, 3857) as geometry,
|
overtaking_event.geometry as geometry,
|
||||||
distance_overtaker,
|
distance_overtaker,
|
||||||
distance_stationary,
|
distance_stationary,
|
||||||
(case when direction_reversed then -1 else 1 end)::int as direction,
|
(case when direction_reversed then -1 else 1 end)::int as direction,
|
||||||
|
@ -14,7 +14,7 @@ RETURNS TABLE(event_id bigint, geometry geometry, distance_overtaker float, dist
|
||||||
FROM overtaking_event
|
FROM overtaking_event
|
||||||
FULL OUTER JOIN road ON road.way_id = overtaking_event.way_id
|
FULL OUTER JOIN road ON road.way_id = overtaking_event.way_id
|
||||||
JOIN track on track.id = overtaking_event.track_id
|
JOIN track on track.id = overtaking_event.track_id
|
||||||
WHERE ST_Transform(overtaking_event.geometry, 3857) && bbox
|
WHERE overtaking_event.geometry && bbox
|
||||||
AND zoom_level >= 8
|
AND zoom_level >= 8
|
||||||
AND (user_id is NULL OR user_id = track.author_id)
|
AND (user_id is NULL OR user_id = track.author_id)
|
||||||
AND time BETWEEN COALESCE(min_time, '1900-01-01'::timestamp) AND COALESCE(max_time, '2100-01-01'::timestamp);
|
AND time BETWEEN COALESCE(min_time, '1900-01-01'::timestamp) AND COALESCE(max_time, '2100-01-01'::timestamp);
|
||||||
|
|
|
@ -19,7 +19,7 @@ layer:
|
||||||
zone: |
|
zone: |
|
||||||
rural or urban
|
rural or urban
|
||||||
defaults:
|
defaults:
|
||||||
srs: EPSG:3785
|
srs: EPSG:3857
|
||||||
datasource:
|
datasource:
|
||||||
srid: 3857
|
srid: 3857
|
||||||
geometry_field: geometry
|
geometry_field: geometry
|
||||||
|
|
|
@ -16,7 +16,7 @@ RETURNS TABLE(
|
||||||
region.name as name,
|
region.name as name,
|
||||||
count(overtaking_event.id)::int as overtaking_event_count
|
count(overtaking_event.id)::int as overtaking_event_count
|
||||||
FROM region
|
FROM region
|
||||||
LEFT OUTER JOIN overtaking_event on ST_Within(ST_Transform(overtaking_event.geometry, 3857), region.geometry)
|
LEFT OUTER JOIN overtaking_event on ST_Within(overtaking_event.geometry, region.geometry)
|
||||||
WHERE
|
WHERE
|
||||||
zoom_level >= 3 AND
|
zoom_level >= 3 AND
|
||||||
zoom_level <= 12 AND
|
zoom_level <= 12 AND
|
||||||
|
|
|
@ -9,7 +9,7 @@ layer:
|
||||||
name: |
|
name: |
|
||||||
Name of the region
|
Name of the region
|
||||||
defaults:
|
defaults:
|
||||||
srs: EPSG:3785
|
srs: EPSG:3857
|
||||||
datasource:
|
datasource:
|
||||||
srid: 3857
|
srid: 3857
|
||||||
geometry_field: geometry
|
geometry_field: geometry
|
||||||
|
|
|
@ -27,7 +27,7 @@ layer:
|
||||||
offset_direction: |
|
offset_direction: |
|
||||||
Factor for offset to shift the line to the driving side. One of -1, 0, 1.
|
Factor for offset to shift the line to the driving side. One of -1, 0, 1.
|
||||||
defaults:
|
defaults:
|
||||||
srs: EPSG:3785
|
srs: EPSG:3857
|
||||||
datasource:
|
datasource:
|
||||||
srid: 3857
|
srid: 3857
|
||||||
geometry_field: geometry
|
geometry_field: geometry
|
||||||
|
|
Loading…
Reference in a new issue