def pasarLogAdegreesPorIntervalo (fechaInicio, fechaFin):
	fechaInicio = pasarFechaTime(fechaInicio)
	fechaFin = pasarFechaTime(fechaFin)
	if not fechaInicio or not fechaFin:
		return False
	'''swapea las fechas por si estan desordenadas '''
	if fechaInicio > fechaFin:
		aux = fechaInicio
		fechaInicio = fechaFin
		fechaFin = aux

	lista_tiles_en_degrees = []
	for x in listaParseada:
		fb = pasarFechaTime(x[0][:19].strip())
		if fb >= fechaInicio and fb < fechaFin:
			tileBounds = globalmaptiles.GlobalMercator()
			bounds = tileBounds.TileLatLonBounds(float(x[2]), float(x[3]), float(x[1])) # tupla
			#~ ( minLat, minLon, maxLat, maxLon )
			esq_NW = Coordenada(bounds[2], bounds[1]) # maxLat y MinLon
			esq_SW = Coordenada(bounds[0], bounds[1]) # minLat y MinLon
			esq_NE = Coordenada(bounds[2], bounds[3]) # maxLat y MaxLon
			esq_SE = Coordenada(bounds[0], bounds[3]) # minLat y MaxLon
			
			cuadrado = {'NW': esq_NW,'SW': esq_SW,'NE': esq_NE,'SE': esq_SE, 
			'zoom': int(x[1]),'nombre': (x[2], x[3], x[1])}
			
			lista_tiles_en_degrees.append(cuadrado)
		
		if fb > fechaFin:
			return lista_tiles_en_degrees
	return lista_tiles_en_degrees
def api_execute_service(service_id, zoom, tx, ty):
    record = ServicesPersistence.get_by_id(service_id)
    if record is None or record["service_type"].lower() != 'xyz':
        return flask.make_response(
            jsonify(id=service_id,
                    code="ServiceNotFound",
                    message="The service does not exist.",
                    links=[]), 404)

    # https://www.maptiler.com/google-maps-coordinates-tile-bounds-projection/
    TILE_SIZE = 256
    ty = (2**zoom - 1) - ty  # convert from Google Tile XYZ to TMS
    minLat, minLon, maxLat, maxLon = globalmaptiles.GlobalMercator(
        tileSize=TILE_SIZE).TileLatLonBounds(tx, ty, zoom)
    variables = {
        "spatial_extent_west": minLon,
        "spatial_extent_south": minLat,
        "spatial_extent_east": maxLon,
        "spatial_extent_north": maxLat,
        "spatial_extent_crs": 4326,
        "tile_size": TILE_SIZE,
    }
    job_data = {
        'process_graph': json.loads(record["process_graph"]),
        'plan': record.get("plan"),
        'budget': record.get("budget"),
        'title': record.get("title"),
        'description': record.get("description"),
        'variables': variables,
    }
    return _execute_and_wait_for_job(job_data)
def pasarLogAdegrees ():
	lista_tiles_en_degrees = []
	for x in listaParseada:
		tileBounds = globalmaptiles.GlobalMercator()
		bounds = tileBounds.TileLatLonBounds(float(x[2]), float(x[3]), float(x[1])) # tupla
		#~ ( minLat, minLon, maxLat, maxLon )
		esq_NW = Coordenada(bounds[2], bounds[1]) # maxLat y MinLon
		esq_SW = Coordenada(bounds[0], bounds[1]) # minLat y MinLon
		esq_NE = Coordenada(bounds[2], bounds[3]) # maxLat y MaxLon
		esq_SE = Coordenada(bounds[0], bounds[3]) # minLat y MaxLon
		cuadrado = {'NW': esq_NW,'SW': esq_SW,'NE': esq_NE,'SE': esq_SE, 'zoom': int(x[1]),'nombre': (x[2], x[3], x[1])}
		lista_tiles_en_degrees.append(cuadrado)
	return lista_tiles_en_degrees
Exemplo n.º 4
0
def GridMap(quadkey="", ploygons_to_lookat=None):

  mercator = globalmaptiles.GlobalMercator()
 
  global PlotIt

  for quadkeyadd in range(4):
    curQuadKey=quadkey+str(quadkeyadd)

    tx, ty, zl=mercator.QuadTree2TMS(curQuadKey)
    grid_latlon=mercator.TileLatLonBounds(tx, ty, zl)    
    #print grid_latlon

    polygon=polygonize_grid(grid_latlon) 

    #print polygon

    obj_polygon=Polygon(polygon)

    inter_cnt=0
    
    Grid_Weather_Stations=[]    

    ploygons_to_lookat_new=[]
    for pobj in ploygons_to_lookat:
      #print pobj, obj_polygon
      if pobj[0].intersection(obj_polygon):
        inter_cnt+=1
        ploygons_to_lookat_new.append(pobj)


    #print inter_cnt
    if inter_cnt> 2 and zl<ClosestZoomLevel:
      GridMap(curQuadKey, ploygons_to_lookat_new)

      continue

    quadkeystr=get_quadkeystr(curQuadKey)
    

    
    for pobj in  ploygons_to_lookat_new:
      if PlotIt:
        x=[]
        y=[]      
        for point in list(obj_polygon.exterior.coords):
          x.append(point[0])
          y.append(point[1])
        plot(x,y, alpha=0.3)

      print quadkeystr+"\t"+pobj[1]+"\t"+str(pobj[2][0])+"\t"+str(pobj[2][1])
Exemplo n.º 5
0
def generate_tile(df, quadkey, level, append=False, fips=50):

    proj = gmt.GlobalMercator()
    google_tile = proj.QuadKeyToGoogleTile(quadkey)
    tms_tile = proj.GoogleToTMSTile(google_tile[0], google_tile[1], level)
    bounds = proj.TileBounds(tms_tile[0], tms_tile[1], level)

    tile_size = 512
    width = int(tile_size * 3)
    bkgrd = 0
    filename = os.path.join('tiles', str(level), str(tms_tile[0]),
                            "{}.png".format(tms_tile[1]))
    if append:
        try:
            img = Image.open(filename)
            img = img.resize((width, width), resample=Image.LANCZOS)
        except IOError:
            img = Image.new('RGBA', (width, width), (bkgrd, bkgrd, bkgrd, 0))
    else:
        img = Image.new('RGBA', (width, width), (bkgrd, bkgrd, bkgrd, 0))
    draw = ImageDraw.Draw(img)

    A = 1000
    tile_ll = bounds[0] / A
    tile_bb = bounds[1] / A
    tile_rr = bounds[2] / A
    tile_tt = bounds[3] / A

    xscale = width / (tile_rr - tile_ll)
    yscale = width / (tile_tt - tile_bb)
    scale = min(xscale, yscale)

    px = (scale * (df['x'] / A - tile_ll)).astype(int)
    py = (-scale * (df['y'] / A - tile_tt)).astype(int)
    rgb = choose_color(fips)
    draw.point(zip(px, py), fill=(rgb[0], rgb[1], rgb[2], transparent(level)))

    img = img.resize((tile_size, tile_size), resample=Image.BICUBIC)
    try:
        img.save(filename, 'PNG')
    except:
        try:
            os.makedirs(os.path.join('tiles', str(level), str(tms_tile[0])))
            img.save(filename, 'PNG')
        except OSError:
            img.save(filename, 'PNG')
def GridMap(quadkey="", ploygons_to_lookat=None):

    mercator = globalmaptiles.GlobalMercator()

    for quadkeyadd in range(4):
        curQuadKey = quadkey + str(quadkeyadd)

        tx, ty, zl = mercator.QuadTree2TMS(curQuadKey)
        grid_latlon = mercator.TileLatLonBounds(tx, ty, zl)
        #print grid_latlon

        polygon = polygonize_grid(grid_latlon)

        #print polygon

        obj_polygon = Polygon(polygon)

        inter_cnt = 0

        Grid_Weather_Stations = []

        ploygons_to_lookat_new = []
        for pobj in ploygons_to_lookat:
            #print pobj, obj_polygon
            if pobj[0].intersection(obj_polygon):
                inter_cnt += 1
                ploygons_to_lookat_new.append(pobj)

        #print inter_cnt
        if inter_cnt > 10 and zl < ClosestZoomLevel:
            GridMap(curQuadKey, ploygons_to_lookat_new)

            continue

        quadkeystr = get_quadkeystr(curQuadKey)

        global output
        global curDate

        for pobj in ploygons_to_lookat_new:
            #print output+=quadkeystr,
            print curDate[:4] + "\t" + curDate[
                4:] + "\t" + quadkeystr + "\t" + pobj[1][0] + "\t" + str(
                    pobj[2][0]) + "\t" + str(pobj[2][1]) + "\t" + "\t".join(
                        pobj[1][1:])
Exemplo n.º 7
0
def create_clusters_centers(markers, zoom, radius):
    mercator = globaltiles.GlobalMercator()
    return cluster_markers(mercator, markers, zoom, radius)
Exemplo n.º 8
0
    for i, point in enumerate(centers):
        json_clusts.append(cluster_json(point, get_cluster_size(i, clusters)))

    return {
        'clusters': json_clusts
    }

def calc_geo_centers(markers, centers, clusters):
    geo_centers = []
    
    for i in range(0, len(centers)):
        geo_centers.append(center_geolocation([
            markers[index] for index in findall(clusters, i)]))
        print len(geo_centers)
        print geo_centers[len(geo_centers)-1]
        print markers[centers[i]]

    return geo_centers

def findall(L, value, start=0):
    return [i for i, x in enumerate(L) if x == value]


##
if __name__ == '__main__':
    ##
    mercator = globaltiles.GlobalMercator()
    latlngs = [(28.43, 8), (28.43, 8), (28.44, 8), (35, 8)]
    centers, clusters = cluster_markers(mercator, latlngs, 21)
    ##
    def __init__(self, root):
        Tkinter.Frame.__init__(self, root)

        # 设置多行框架存放组件
        self.frame = [
            Tkinter.Frame(padx=3, pady=3),
            Tkinter.Frame(padx=3, pady=3),
            Tkinter.Frame(padx=3, pady=3),
            Tkinter.Frame(padx=3, pady=3)
        ]

        # 第一行控件
        Tkinter.Label(self.frame[0], text='框选左上角经纬度:经').pack(side=Tkinter.LEFT)

        ltlo = StringVar()
        ltlo.set('-179.9')  # 73.666667
        self.leftTopLon = Tkinter.Entry(self.frame[0], textvariable=ltlo)
        self.leftTopLon.pack(side=Tkinter.LEFT)

        Tkinter.Label(self.frame[0], text='维').pack(side=Tkinter.LEFT)

        ltla = StringVar()
        ltla.set('85')  # 53.550000
        self.leftTopLat = Tkinter.Entry(self.frame[0], textvariable=ltla)
        self.leftTopLat.pack(side=Tkinter.LEFT)

        Tkinter.Label(self.frame[0], text='框选右下角经纬度:经').pack(side=Tkinter.LEFT)

        rblo = StringVar()
        rblo.set('179.9')  # 135.041667
        self.rightBottomLon = Tkinter.Entry(self.frame[0], textvariable=rblo)
        self.rightBottomLon.pack(side=Tkinter.LEFT)

        Tkinter.Label(self.frame[0], text='维').pack(side=Tkinter.LEFT)

        rbla = StringVar()
        rbla.set('-85')  # 3.866667
        self.rightBottomLat = Tkinter.Entry(self.frame[0], textvariable=rbla)
        self.rightBottomLat.pack(side=Tkinter.LEFT)

        self.frame[0].pack(expand=0, fill=Tkinter.X)

        # 第二行控件
        Tkinter.Label(self.frame[1], text='选择下载地图的服务器').pack(side=Tkinter.LEFT)

        self.ss = Tkinter.StringVar()
        self.ss.set(mapServers[0])
        Tkinter.OptionMenu(self.frame[1], self.ss,
                           *mapServers).pack(side=Tkinter.LEFT)

        self.mapLevelStart = Tkinter.StringVar()
        self.mapLevelStart.set(0)
        self.mapLevelEnd = Tkinter.StringVar()
        self.mapLevelEnd.set(5)

        Tkinter.Label(self.frame[1], text='地图下载起始级别').pack(side=Tkinter.LEFT)
        Tkinter.OptionMenu(self.frame[1], self.mapLevelStart,
                           *range(0, 20)).pack(side=Tkinter.LEFT)
        Tkinter.Label(self.frame[1], text='地图下载终止级别').pack(side=Tkinter.LEFT)
        Tkinter.OptionMenu(self.frame[1], self.mapLevelEnd,
                           *range(0, 20)).pack(side=Tkinter.LEFT)

        # 存放目录
        self.btSaveFolder = Tkinter.Button(self.frame[1],
                                           text='选择存放目录',
                                           command=self.selectSaveFolder)
        self.btSaveFolder.pack(side=Tkinter.LEFT)

        self.btAction = Tkinter.Button(self.frame[1],
                                       text='开始下载',
                                       bg='red',
                                       fg='yellow',
                                       command=self.doDownload)
        self.btAction.pack(side=Tkinter.RIGHT, expand=1, fill=Tkinter.X)
        self.frame[1].pack(expand=0, fill=Tkinter.X)

        # 第三行控件

        # 文本框滚动条
        self.sl = Tkinter.Scrollbar(self.frame[2])
        self.sl.pack(side='right', fill='y')
        # 显示结果的文本框
        self.message = Tkinter.Text(self.frame[2], yscrollcommand=self.sl.set)
        # 将滚动条的值与文本框绑定,这样滚动条才有作用
        self.sl.config(command=self.message.yview)
        self.message.pack(expand=1, fill=Tkinter.BOTH)
        self.message.bind("<KeyPress>", lambda e: "break")

        self.frame[2].pack(expand=1, fill=Tkinter.BOTH)

        # 第四行控件
        self.clAction = Tkinter.Button(self.frame[3],
                                       text='清空日志',
                                       command=self.clear)
        self.clAction.pack(side=Tkinter.LEFT)

        Tkinter.Label(self.frame[3], text='Status:').pack(side=Tkinter.LEFT)
        self.lbcount = Tkinter.Label(self.frame[3], text='')
        self.lbcount.pack(side=Tkinter.LEFT)

        self.frame[3].pack(expand=0, fill=Tkinter.X)

        self.gm = globalmaptiles.GlobalMercator()
Exemplo n.º 10
0
def create_clusters_centers(markers, zoom, radius):
    mercator = globaltiles.GlobalMercator()
    centers, clusters, sizes = cluster_markers(mercator, markers, zoom, radius)
    centers_markers = [markers[i] for i in centers]
    return centers_markers, clusters, sizes
Exemplo n.º 11
0
    Usage("ERROR: Sorry, given profile is not implemented yet.")

if zoomlevel == None or lat == None or lon == None:
    Usage("ERROR: Specify at least 'zoomlevel', 'lat' and 'lon'.")
if latmax is not None and lonmax is None:
    Usage("ERROR: Both 'latmax' and 'lonmax' must be given.")

if latmax != None and lonmax != None:
    if latmax < lat:
        Usage("ERROR: 'latmax' must be bigger then 'lat'")
    if lonmax < lon:
        Usage("ERROR: 'lonmax' must be bigger then 'lon'")
    boundingbox = (lon, lat, lonmax, latmax)

tz = zoomlevel
mercator = globalmaptiles.GlobalMercator()
mx, my = mercator.LatLonToMeters(lat, lon)
tminx, tminy = mercator.MetersToTile(mx, my, tz)

if boundingbox:
    mx, my = mercator.LatLonToMeters(latmax, lonmax)
    tmaxx, tmaxy = mercator.MetersToTile(mx, my, tz)
else:
    tmaxx, tmaxy = tminx, tminy

f = open("tiles.html", "w")
f.write("<html><head></head><body>\n")
mt = 0

for ty in range(tminy, tmaxy + 1):
    for tx in range(tminx, tmaxx + 1):