How to use the topojson.coordinatesystems.BaseCoordinateSystem function in topojson

To help you get started, we’ve selected a few topojson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github calvinmetcalf / topojson.py / topojson / coordinatesystems.py View on Github external
return str(distance)

    def ring_area(self, ring):
        raise Exception('Not implemented')

    def triangle_area(self, triangle):
        raise Exception('Not implemented')

    def distance(self, x0, y0, x1, y1):
        raise Exception('Not implemented')

    def absolute_area(self, area):
        return abs(area)


class Cartesian(BaseCoordinateSystem):
    name = "cartesian"

    def ring_area(self, ring):
        calc_area = lambda p1, p2: p1[1] * p2[0] - p1[0] * p2[1]
        # last and first
        area = calc_area(ring[-1], ring[0])
        for i, p in enumerate(ring[1:]):   # skip first so p is current and
            area += calc_area(p, ring[i])  # ring[i] is the previous
        return area * 0.5

    def triangle_area(self, triangle):
        return abs(
            (triangle[0][0] - triangle[2][0]) * (triangle[1][1] - triangle[0][1]) -
            (triangle[0][0] - triangle[1][0]) * (triangle[2][1] - triangle[0][1])
        )
github calvinmetcalf / topojson.py / topojson / coordinatesystems.py View on Github external
area += calc_area(p, ring[i])  # ring[i] is the previous
        return area * 0.5

    def triangle_area(self, triangle):
        return abs(
            (triangle[0][0] - triangle[2][0]) * (triangle[1][1] - triangle[0][1]) -
            (triangle[0][0] - triangle[1][0]) * (triangle[2][1] - triangle[0][1])
        )

    def distance(self, x0, y0, x1, y1):
        dx = x0 - x1
        dy = y0 - y1
        return sqrt(dx * dx + dy * dy)


class Spherical(BaseCoordinateSystem):
    name = 'spherical'

    def haversin(self, x):
        return sin(x / 2) ** 2

    def format_distance(self, distance):
        km = distance * 6371.0
        if km > 1:
            return u"{:0.03f}km".format(km)
        else:
            return u"{:0.03f} ({0.03f}°)".format(km * 1000, distance * 180 / pi)

    def ring_area(self, ring):
        if len(ring) == 0:
            return 0
        area = 0