Skip to content

Commit

Permalink
Merge pull request #3 from Terralego/geostore_0.5.1_compat
Browse files Browse the repository at this point in the history
Fix deprecated functions from geostore
  • Loading branch information
submarcos committed Oct 28, 2020
2 parents 4950bd8 + f38001e commit 00f4a07
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/python-package.yml
Expand Up @@ -12,6 +12,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest

services:
postgres:
image: pgrouting/pgrouting:10-2.5-2.6.3
Expand Down Expand Up @@ -40,6 +41,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
continue-on-error: ${{ matrix.experimental }}

- name: Install dependencies
run: |
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.md
@@ -1,9 +1,11 @@
CHANGELOG
=========

0.9.4.dev0 (XXXX-XX-XX)
0.9.4 (2020-10-28)
---------------------------

* Improve compatibility with django-geostore > 0.5.0


0.9.3 (2020-10-27)
---------------------------
Expand Down
2 changes: 1 addition & 1 deletion geostore_routing/VERSION.md
@@ -1 +1 @@
0.9.4.dev0
0.9.4
6 changes: 6 additions & 0 deletions geostore_routing/functions.py
@@ -0,0 +1,6 @@
from django.contrib.gis.db.models import GeometryField
from django.contrib.gis.db.models.functions import GeoFunc


class LineSubstring(GeoFunc):
output_field = GeometryField()
17 changes: 9 additions & 8 deletions geostore_routing/helpers.py
@@ -1,17 +1,18 @@
import json

from django import VERSION as DJANGO_VERSION
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.db.models.functions import Distance, LineLocatePoint

from geostore_routing.functions import LineSubstring

if DJANGO_VERSION >= (3, 0):
from django.contrib.gis.db.models.functions import GeometryDistance
from django.contrib.gis.geos import GEOSGeometry, MultiLineString, LineString, Point
from django.core.cache import cache
from django.db import connection
from django.db.models import F, Value
from django.db.models import F

from geostore_routing import settings as app_settings
from geostore.tiles.funcs import ST_LineLocatePoint, ST_LineSubstring


class RoutingException(Exception):
Expand Down Expand Up @@ -128,7 +129,7 @@ def _serialize_routes(self, routes):
}

def _get_points_in_lines(self, points):
'''Returns position of the point in the closed geometry'''
""" Returns position of the point in the closed geometry """
snapped_points = []

for point in points:
Expand All @@ -155,7 +156,7 @@ def _get_closest_geometry(self, point):

def _snap_point_on_feature(self, point, feature):
return self.layer.features.filter(pk=feature.pk).annotate(
fraction=ST_LineLocatePoint(F('geom'), Value(str(point))),
fraction=LineLocatePoint('geom', point),
).only('id', 'geom').first()

def _points_route(self):
Expand Down Expand Up @@ -187,9 +188,9 @@ def _get_segment(self, from_point, to_point):

def _get_line_substring(self, feature, fractions):
feature = self.layer.features.annotate(
splitted_geom=ST_LineSubstring(F('geom'),
float(min(fractions)),
float(max(fractions)))
splitted_geom=LineSubstring('geom',
float(min(fractions)),
float(max(fractions)))
).get(pk=feature.pk)

return {
Expand Down

0 comments on commit 00f4a07

Please sign in to comment.