Exemplo n.º 1
0
    def elevation(self, oid, segments=None, **params):
        if segments is not None and segments.isdigit():
            segments = int(segments)
            if segments > 500 or segments <= 0:
                segments = 500
        else:
            segments = 100

        w = cherrypy.request.app.config['DB']['map'].tables.ways.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')
                         ]).alias()
        field = sa.func.ST_LineInterpolatePoint(w.c.geom,
                                                gen.c.i / float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(w.c.id == oid)
        res = cherrypy.request.db.execute(sel).first()

        if res is None or res[0] is None:
            raise cherrypy.NotFound()

        ret = OrderedDict()
        ret['id'] = oid
        geom = to_shape(res[0])
        xcoord, ycoord = zip(*((p.x, p.y) for p in geom))
        geomlen = LineString(geom).length
        pos = [geomlen * i / float(segments) for i in range(segments)]
        compute_elevation(((xcoord, ycoord, pos), ), geom.bounds, ret)

        return ret
Exemplo n.º 2
0
    def elevation(self, oid, segments=None, **params):
        if segments is not None and segments.isdigit():
            segments = int(segments)
            if segments > 500 or segments <= 0:
                segments = 500
        else:
            segments = 100

        r = cherrypy.request.app.config['DB']['map'].tables.routes.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')]).alias()
        field = sa.func.ST_LineInterpolatePoint(r.c.geom, gen.c.i/float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(r.c.id == oid)\
                .where(r.c.geom.ST_GeometryType() == 'ST_LineString')

        res = cherrypy.request.db.execute(sel).first()

        if res is None or res[0] is None:
            raise cherrypy.NotFound()

        ret = OrderedDict()
        ret['id'] = oid
        compute_elevation(to_shape(res[0]), ret)

        return ret
Exemplo n.º 3
0
    def elevation(self, oid, segments=None, **params):
        if segments is not None and segments.isdigit():
            segments = int(segments)
            if segments > 500 or segments <= 0:
                segments = 500
        else:
            segments = 100

        w = cherrypy.request.app.config['DB']['map'].tables.ways.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')
                         ]).alias()
        field = sa.func.ST_LineInterpolatePoint(w.c.geom,
                                                gen.c.i / float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(w.c.id == oid)
        res = cherrypy.request.db.execute(sel).first()

        if res is None or res[0] is None:
            raise cherrypy.NotFound()

        ret = OrderedDict()
        ret['id'] = oid
        compute_elevation(to_shape(res[0]), ret)

        return ret
Exemplo n.º 4
0
    def elevation(self, oid, segments=None, **params):
        if segments is not None and segments.isdigit():
            segments = int(segments)
            if segments > 500 or segments <= 0:
                segments = 500
        else:
            segments = 100

        ret = OrderedDict()
        ret['id'] = oid

        r = cherrypy.request.app.config['DB']['map'].tables.routes.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')
                         ]).alias()
        field = sa.func.ST_LineInterpolatePoint(r.c.geom,
                                                gen.c.i / float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(r.c.id == oid)\
                .where(r.c.geom.ST_GeometryType() == 'ST_LineString')

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
            geom = to_shape(res[0])
            xcoord, ycoord = zip(*((p.x, p.y) for p in geom))
            geomlen = LineString(geom).length
            pos = [geomlen * i / float(segments) for i in range(segments)]
            compute_elevation(((xcoord, ycoord, pos), ), geom.bounds, ret)
            return ret

        # special treatment for multilinestrings
        sel = sa.select([r.c.geom,
                         sa.literal_column("""ST_Length2dSpheroid(ST_MakeLine(ARRAY[ST_Points(ST_Transform(geom,4326))]),
                             'SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY["EPSG",\"7030\"]]')"""),
                         r.c.geom.ST_NPoints()])\
                .where(r.c.id == oid)

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
            geom = to_shape(res[0])

            if res[2] > 10000:
                geom = geom.simplify(res[2] / 500, preserve_topology=False)
            elif res[2] > 4000:
                geom = geom.simplify(res[2] / 1000, preserve_topology=False)

            segments = []

            for seg in geom:
                p = seg.coords[0]
                xcoords = array('d', [p[0]])
                ycoords = array('d', [p[1]])
                pos = array('d')
                if segments:
                    prev = segments[-1]
                    pos.append(prev[2][-1] + \
                            Point(prev[0][-1], prev[1][-1]).distance(Point(*p)))
                else:
                    pos.append(0.0)
                for p in seg.coords[1:]:
                    pos.append(
                        pos[-1] +
                        Point(xcoords[-1], ycoords[-1]).distance(Point(*p)))
                    xcoords.append(p[0])
                    ycoords.append(p[1])

                segments.append((xcoords, ycoords, pos))

            compute_elevation(segments, geom.bounds, ret)

            ret['length'] = float(res[1])
            return ret

        raise cherrypy.NotFound()
Exemplo n.º 5
0
    def elevation(self, oid, segments=None, **params):
        if segments is not None and segments.isdigit():
            segments = int(segments)
            if segments > 500 or segments <= 0:
                segments = 500
        else:
            segments = 100

        ret = OrderedDict()
        ret['id'] = oid

        r = cherrypy.request.app.config['DB']['map'].tables.routes.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')]).alias()
        field = sa.func.ST_LineInterpolatePoint(r.c.geom, gen.c.i/float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(r.c.id == oid)\
                .where(r.c.geom.ST_GeometryType() == 'ST_LineString')

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
            geom = to_shape(res[0])
            xcoord, ycoord = zip(*((p.x, p.y) for p in geom))
            geomlen = LineString(geom).length
            pos = [geomlen*i/float(segments) for i in range(segments)]
            compute_elevation(((xcoord, ycoord, pos), ), geom.bounds, ret)
            return ret

        # special treatment for multilinestrings
        sel = sa.select([r.c.geom,
                         sa.literal_column("""ST_Length2dSpheroid(ST_MakeLine(ARRAY[ST_Points(ST_Transform(geom,4326))]),
                             'SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY["EPSG",\"7030\"]]')"""),
                         r.c.geom.ST_NPoints()])\
                .where(r.c.id == oid)

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
            geom = to_shape(res[0])

            if res[2] > 10000:
                geom = geom.simplify(res[2]/500, preserve_topology=False)
            elif res[2] > 4000:
                geom = geom.simplify(res[2]/1000, preserve_topology=False)

            segments = []

            for seg in geom:
                p = seg.coords[0]
                xcoords = array('d', [p[0]])
                ycoords = array('d', [p[1]])
                pos = array('d')
                if segments:
                    prev = segments[-1]
                    pos.append(prev[2][-1] + \
                            Point(prev[0][-1], prev[1][-1]).distance(Point(*p)))
                else:
                    pos.append(0.0)
                for p in seg.coords[1:]:
                    pos.append(pos[-1] + Point(xcoords[-1], ycoords[-1]).distance(Point(*p)))
                    xcoords.append(p[0])
                    ycoords.append(p[1])

                segments.append((xcoords, ycoords, pos))

            compute_elevation(segments, geom.bounds, ret)

            ret['length'] = float(res[1])
            return ret

        raise cherrypy.NotFound()