Пример #1
0
def split_tile(request):
    job_id = request.matchdict['job']
    x = request.matchdict['x']
    y = request.matchdict['y']
    zoom = request.matchdict['zoom']
    session = DBSession()
    job = session.query(Job).get(job_id)
    tile = session.query(Tile).get((x, y, zoom, job_id))
    session.delete(tile)

    new_tiles = []
    t = []
    for i in range(0, 2):
        for j in range(0, 2):
            tile = Tile(int(x)*2 + i, int(y)*2 + j, int(zoom)+1)
            tile.job = job
            t.append(tile)
    for tile in t:
        new_tiles.append(Feature(geometry=tile.to_polygon(),
            id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom)))
    return dict(success=True, split_id="-".join([x, y, zoom]),
            new_tiles=FeatureCollection(new_tiles))
Пример #2
0
def split_tile(request):
    job_id = request.matchdict['job']
    x = request.matchdict['x']
    y = request.matchdict['y']
    zoom = request.matchdict['zoom']
    session = DBSession()
    job = session.query(Job).get(job_id)
    tile = session.query(Tile).get((x, y, zoom, job_id))
    session.delete(tile)

    new_tiles = []
    t = []
    for i in range(0, 2):
        for j in range(0, 2):
            tile = Tile(int(x) * 2 + i, int(y) * 2 + j, int(zoom) + 1)
            tile.job = job
            t.append(tile)
    for tile in t:
        new_tiles.append(
            Feature(geometry=tile.to_polygon(),
                    id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom)))
    return dict(job=tile.job,
                split_id="-".join([x, y, zoom]),
                new_tiles=FeatureCollection(new_tiles))
from sqlalchemy import create_engine
from OSMTM.models import (
    Tile,
    DBSession
)
import json

engine = create_engine('sqlite:///OSMTM.db')
DBSession.configure(bind=engine)


json_data=open('census.geojson')
data = json.load(json_data)
json_data.close()

x = 0
for f in data['features']:
  wkt = ''
  for c in f['geometry']['coordinates'][0]:
    if wkt != '':
      wkt = wkt + ','
    wkt = wkt + str(c[0]) + " " + str(c[1])

  t = Tile(x,0,0,'POLYGON((' + wkt + '))')
  x = x + 1
  t.job_id = 7

  with transaction.manager:
    DBSession.add(t)
    DBSession.flush()
Пример #4
0
def split_tile(request):
    """
    Split the tile and copy history of the parent tile
    """
    job_id = request.matchdict['job']
    x = request.matchdict['x']
    y = request.matchdict['y']
    zoom = request.matchdict['zoom']
    session = DBSession()
    job = session.query(Job).get(job_id)
    tile = session.query(Tile).get((x, y, zoom, job_id))
    session.delete(tile)

    # reference tile history
    tileHistory = (
        session.query(TileHistory)
        .filter_by(x=x, y=y, zoom=zoom, job_id=job_id)
        .order_by(TileHistory.update)
        .all()
    )

    new_tiles = []
    t = []
    for i in range(0, 2):
        for j in range(0, 2):
            # add new tile
            X = int(x) * 2 + i
            Y = int(y) * 2 + j
            Zoom = int(zoom) + 1
            newTile = Tile(X, Y, Zoom)
            newTile.job = job

            for idx, historyRecord in enumerate(tileHistory):
                # copy tileHistory... use negative versions to prevent unique
                # key conflicts, and enable filtering (exclusion) when
                # generating stats
                newTileHistory = TileHistory(
                    x=newTile.x,
                    y=newTile.y,
                    zoom=newTile.zoom,
                    username=historyRecord.username,
                    update=historyRecord.update,
                    checkout=historyRecord.checkout,
                    checkin=historyRecord.checkin,
                    change=historyRecord.change,
                    comment=historyRecord.comment,
                    job_id=job.id,
                    version=-idx
                )
                session.add(newTileHistory)

            t.append(newTile)
    for tile in t:
        new_tiles.append(
            Feature(
                geometry=tile.to_polygon(),
                id=str(tile.x) + '-' + str(tile.y) + '-' + str(tile.zoom)))
    return dict(
        success=True, split_id="-".join([x, y, zoom]),
        new_tiles=FeatureCollection(new_tiles)
    )