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 datetime import datetime
|
||||
|
||||
from sqlalchemy import delete, select, and_
|
||||
from sqlalchemy import delete, func, select, and_
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from obs.face.importer import ImportMeasurementsCsv
|
||||
|
@ -306,11 +306,16 @@ async def import_overtaking_events(session, track, overtaking_events):
|
|||
hex_hash=hex_hash,
|
||||
way_id=m.get("OSM_way_id"),
|
||||
direction_reversed=m.get("OSM_way_orientation", 0) < 0,
|
||||
geometry=json.dumps(
|
||||
{
|
||||
"type": "Point",
|
||||
"coordinates": [m["longitude"], m["latitude"]],
|
||||
}
|
||||
geometry=func.ST_Transform(
|
||||
func.ST_GeomFromGeoJSON(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "Point",
|
||||
"coordinates": [m["longitude"], m["latitude"]],
|
||||
}
|
||||
)
|
||||
),
|
||||
3857,
|
||||
),
|
||||
latitude=m["latitude"],
|
||||
longitude=m["longitude"],
|
||||
|
|
|
@ -191,9 +191,7 @@ async def stats(req):
|
|||
.select_from(Region)
|
||||
.join(
|
||||
OvertakingEvent,
|
||||
func.ST_Within(
|
||||
func.ST_Transform(OvertakingEvent.geometry, 3857), Region.geometry
|
||||
),
|
||||
func.ST_Within(OvertakingEvent.geometry, Region.geometry),
|
||||
)
|
||||
.group_by(
|
||||
Region.id,
|
||||
|
|
|
@ -3,7 +3,7 @@ RETURNS TABLE(event_id bigint, geometry geometry, distance_overtaker float, dist
|
|||
|
||||
SELECT
|
||||
overtaking_event.id::bigint as event_id,
|
||||
ST_Transform(overtaking_event.geometry, 3857) as geometry,
|
||||
overtaking_event.geometry as geometry,
|
||||
distance_overtaker,
|
||||
distance_stationary,
|
||||
(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
|
||||
FULL OUTER JOIN road ON road.way_id = overtaking_event.way_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 (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);
|
||||
|
|
|
@ -19,7 +19,7 @@ layer:
|
|||
zone: |
|
||||
rural or urban
|
||||
defaults:
|
||||
srs: EPSG:3785
|
||||
srs: EPSG:3857
|
||||
datasource:
|
||||
srid: 3857
|
||||
geometry_field: geometry
|
||||
|
|
|
@ -16,7 +16,7 @@ RETURNS TABLE(
|
|||
region.name as name,
|
||||
count(overtaking_event.id)::int as overtaking_event_count
|
||||
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
|
||||
zoom_level >= 3 AND
|
||||
zoom_level <= 12 AND
|
||||
|
|
|
@ -9,7 +9,7 @@ layer:
|
|||
name: |
|
||||
Name of the region
|
||||
defaults:
|
||||
srs: EPSG:3785
|
||||
srs: EPSG:3857
|
||||
datasource:
|
||||
srid: 3857
|
||||
geometry_field: geometry
|
||||
|
|
|
@ -27,7 +27,7 @@ layer:
|
|||
offset_direction: |
|
||||
Factor for offset to shift the line to the driving side. One of -1, 0, 1.
|
||||
defaults:
|
||||
srs: EPSG:3785
|
||||
srs: EPSG:3857
|
||||
datasource:
|
||||
srid: 3857
|
||||
geometry_field: geometry
|
||||
|
|
Loading…
Reference in a new issue