Exemplo n.º 1
0
def create_overlay(container, datadir, document):
    """Create a KML file and intensity map.

    Args:
        container (ShakeMapOutputContainer): Results of model.conf.
        datadir (str): Path to data directory where output KMZ will be written.
        document (SubElement): KML document where the overlay tags should go.
    Returns:
        tuple: (Path to output KMZ file, Path to output overlay image)
    """
    # create the overlay image file
    overlay_img_file = os.path.join(datadir, OVERLAY_IMG)
    geodict = create_overlay_image(container, overlay_img_file)
    if geodict is None:
        return None
    box = skml.LatLonBox(north=geodict.ymax, south=geodict.ymin,
                         east=geodict.xmax, west=geodict.xmin)
    icon = skml.Icon(refreshinterval=300,
                     refreshmode='onInterval',
                     href=OVERLAY_IMG)
    document.newgroundoverlay(name='IntensityOverlay',
                              color='ffffffff',
                              draworder=0,
                              latlonbox=box,
                              icon=icon)

    return overlay_img_file
Exemplo n.º 2
0
 def CreateGroundOverlay(self,img,n,s,e,w,**kwargs):
     if kwargs.has_key('transparency'):
         transparency = kwargs['transparency']
     else:
         transparency = 0xb5
     
     picOverlay = self.kml.newgroundoverlay(name='MapOverlay')
     picOverlay.icon.href=img
     picOverlay.color= Color.changealpha("%x"%(0xb5),Color.white)
     llbox = simplekml.LatLonBox()
     llbox.north,llbox.south,llbox.east,llbox.west = n,s,e,w
     picOverlay.latlonbox = llbox
    def state(self, state):
        name, counties = statecounties[state]
        print("** Get data for state %s's counties" % name)
        
        if not self._need_state_updates[state]:
            print("No update needed...")
            return nupstring
         
        print("Update needed, regenerating...")
       
        # Create new version of the state's counties
        kml = simplekml.Kml()
        
        for county in counties:
            ind = county["properties"]["STATE"] + county["properties"]["COUNTY"]
            val, col, desc = self.mapData(data_county[ind], indexmap_county)
                
            box = simplekml.LatLonBox(north=-1000, south=1000, west=1000, east=-1000)
            
            # Create multi geo to hold outline
            geo = kml.newmultigeometry()

            geo.name = county["properties"]["NAME"] + " - " + county["properties"]["COUNTY"]
            geo.description = geo.name
        
                        
            if county["geometry"]["type"] == "Polygon":
                p = geo.newpolygon()
                p.altitudemode = "relativeToGround"
                p.extrude=1
                #p.outerboundaryis = county["geometry"]["coordinates"][0]
                p.outerboundaryis = self.addZ(county["geometry"]["coordinates"][0], (((self._scale * val)/1000)*2692)+308)
            else:     
                for poly in county["geometry"]["coordinates"]:
                    p = geo.newpolygon()
                    p.altitudemode = "relativeToGround"
                    p.extrude=1
                    #p.outerboundaryis = poly[0]
                    p.outerboundaryis = self.addZ(poly[0], (((self._scale * val)/1000)*2692)+308)
 
            # Map data to color
            
            
            
 
            geo.description = desc   
            geo.style.polystyle.color = col
        
        
        self._need_state_updates[state] = False      
        
        return kml.kml(False)
    def updateKml(self, *args, **kwargs):
        print("updateKml: args=%s kwargs=%s" % (args, kwargs))
        
        if not self._need_update:
            print("No update needed...")
            return nupstring
        
        
        print("Update needed, regenerating...")
        
 
        kml = simplekml.Kml()
        
        pnt = kml.newpoint(name="Machu Picchu, Peru")
        ##pnt.coordinates = simplekml.Coordinates(-72.516244)
        pnt.lookat = simplekml.LookAt(gxaltitudemode=simplekml.GxAltitudeMode.relativetoseafloor,
                              latitude=-13.209676, longitude=-72.503364, altitude=0.0,
                              range=14794.882995, heading=71.131493, tilt=66.768762)
                              
        # Generate data for states
        for state in geo_state["features"]:
 
            val, col, desc = self.mapData(data_state[state["properties"]["STATE"]], indexmap_state)
            
            fold = kml.newfolder(name = state["properties"]["NAME"])
            
            geo = fold.newmultigeometry()

            geo.name = state["properties"]["NAME"]

            box = simplekml.LatLonBox(north=-1000, south=1000, west=1000, east=-1000)

            if state["geometry"]["type"] == "Polygon":
                p = geo.newpolygon()
                p.altitudemode = "relativeToGround"
                p.extrude=1
                p.outerboundaryis = self.addZ(state["geometry"]["coordinates"][0], (((self._scale * val)/1000)*2692)+308)
                update_box(box, state["geometry"]["coordinates"][0])
            else:     
                for poly in state["geometry"]["coordinates"]:
                    p = geo.newpolygon()
                    p.altitudemode = "relativeToGround"
                    p.extrude=1
                    p.outerboundaryis = self.addZ(poly[0], (((self._scale * val)/1000)*2692)+308)
                    update_box(box, poly[0])

            switchsize = 600
            fadesize = 100

            geo.region = simplekml.Region(box, simplekml.Lod(minlodpixels = 0, maxlodpixels = switchsize, minfadeextent = 0, maxfadeextent = fadesize))

            # Network link for counties
            clink = kml.newnetworklink(name = "Counties for %s" % geo.name)
            clink.region = simplekml.Region(box, simplekml.Lod(minlodpixels = switchsize - fadesize, maxlodpixels = -1, minfadeextent = fadesize, maxfadeextent = 0))
            clink.link.href="http://127.0.0.1:20605/state?state=%s" % state["properties"]["STATE"]
            clink.link.refreshmode = "onInterval"
            clink.link.refreshinterval = 2


            geo.style.polystyle.outline = 0

            # Map data to color
            geo.description = desc
            geo.style.polystyle.color = col

            geo = None


        stateskml = kml
        
        self._need_update = False        
        
        return stateskml.kml(False)