Skip to content

Commit

Permalink
Fix the line length issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Oct 14, 2024
1 parent 4775f3b commit e020cf5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions envergo/hedges/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import uuid

from django.contrib.gis.geos import LineString
# from django.contrib.gis.geos import LineString
from django.db import models
from pyproj import Geod
from shapely import LineString

TO_PLANT = "TO_PLANT"
TO_REMOVE = "TO_REMOVE"
Expand All @@ -16,23 +18,26 @@
# Good for working in meters
EPSG_MERCATOR = 3857

EPSG_LAMB93 = 2154


class Hedge:
"""Represent a single hedge."""

def __init__(self, id, latLngs, type):
self.id = id # The edge reference, e.g A1, A2…
self.geometry = LineString(
[(latLng["lat"], latLng["lng"]) for latLng in latLngs], srid=EPSG_WGS84
[(latLng["lng"], latLng["lat"]) for latLng in latLngs]
)
self.geometry.transform(EPSG_MERCATOR)
self.type = type

@property
def length(self):
"""TODO this gives a different value than leaflet. Need to investigate more."""
"""Returns the geodesic length (in meters) of the line."""

return int(self.geometry.length)
geod = Geod(ellps="WGS84")
length = geod.geometry_length(self.geometry)
return int(length)


class HedgeData(models.Model):
Expand Down

0 comments on commit e020cf5

Please sign in to comment.