Exemplo n.º 1
0
def zoning_dict2map(zones,translated_geoms):
    threshold = .00000005  #choose this by trial and error, or inspecting VWSimplifier.ordered_thresholds of an example polygon
    mymap = Map()
    n = len(zoning.keys())
    n = 3 if n<3 else n
    colors = get_map('Dark2','Qualitative',n).hex_colors.__iter__()
    print("building datasets")
    for appname,datasets in zoning.items():
       appcolor = colors.next()
       thisapp = App(sanitize_id(appname),title=appname)
       mymap.apps.append(thisapp)
       num_datasets = len(datasets)+3 #don't go to gradient.end
       datacoloriter = gradient(num_datasets,
                                 start=hex2rgb(appcolor))
       for dataname,zone_fields in sorted(datasets.items()):
          color = datacoloriter.next()
          dset = DataSet(sanitize_id(dataname),title=dataname,
                   latlon=False,key_color=color,precision=9)
          thisapp.datasets.append(dset)
          for i,z in enumerate(zones):
            for target in zone_fields:
              if target in z:
               geom = translated_geoms[i]
               if geom.geom_name == 'POLYGON':
                 dset.add_polygon([geom.tuple],
                           threshold=threshold,fillColor=color,
                           strokeColor=color)
               elif geom.geom_name == 'MULTIPOLYGON':
                 dset.add_polygon(geom.tuple,
                           threshold=threshold,fillColor=color,
                           strokeColor=color)
    print("building map")
    mymap.build_page(zoom=13)
Exemplo n.º 2
0
    #translate all geoms to (lon,lat)
    _world_spatref = SpatialReference('WGS84')
    coord_transform = CoordTransform(geoms[0].srs,_world_spatref)
    for geom in geoms:
      geom.transform(coord_transform)

    print("building datasets")
    bigmap = Map()
    appcolor = -1 #used to generate a unique color for each app
    for app_name in zone_dict.keys():
      appcolor += 1
      this_app = App(app_name,title=app_name)
      bigmap.apps.append(this_app)
      n = len(zone_dict[app_name])+1
      colors = gradient(n,start=int2rgb(appcolor))
      for datasetname, indices in sorted(zone_dict[app_name].items(),key=lambda item: len(item[1]),reverse=True):
        color = colors.next()
        #the x is to uniqueify the dataset id from the app
        sane_name = '%sx'%'x'.join(datasetname.split('-'))
        dset = DataSet(sane_name,key_color=color,title=datasetname,latlon=False,precision=8)
        this_app.datasets.append(dset)
        for i in indices:
          geom = geoms[i]
          if geom.geom_name == 'POLYGON':
            dset.add_polygon([geom.tuple],threshold=.005,fillColor=color)
          elif geom.geom_name == 'MULTIPOLYGON':
            dset.add_polygon(geom.tuple,threshold=.005,fillColor=color)
    print("building map")
    bigmap.build_page(zoom=11)