Пример #1
0
 def kml_done(self):
     return """
     <Placemark id="%s">
         <visibility>1</visibility>
         <styleUrl>#%s-default</styleUrl>
         %s
     </Placemark>
     """ % ( self.uid, self.model_uid(),
             asKml(self.geometry.transform( settings.GEOMETRY_CLIENT_SRID, clone=True ))
           )        
Пример #2
0
 def kml(self):  
     #the following list appendation strategy was a good 10% faster than string concatenation
     #(biggest improvement however came by adding/populating a geometry_client column in leaseblock table)
     combined_kml_list = []
     if len(self.lease_blocks) == 0:  #empty result
         leaseblock_ids = []
         combined_kml_list.append('<Folder id="%s"><name>%s -- 0 Leaseblocks</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
     else:
         leaseblock_ids = [int(id) for id in self.lease_blocks.split(',')]
         combined_kml_list.append('<Folder id="%s"><name>%s</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
     combined_kml_list.append('<LookAt><longitude>-73.5</longitude><latitude>39</latitude><heading>0</heading><range>600000</range></LookAt>')
     combined_kml_list.append('<styleUrl>#%s-default</styleUrl>' % (self.model_uid()))
     combined_kml_list.append('%s' % self.leaseblock_style())
     print 'Generating KML for %s Lease Blocks' % len(leaseblock_ids)
     start_time = time.time()
     leaseblocks = LeaseBlock.objects.filter(pk__in=leaseblock_ids)
     for leaseblock in leaseblocks:
         try:
             kml =   """
                 <Placemark>
                     <visibility>1</visibility>
                     <styleUrl>#%s-leaseblock</styleUrl>
                     <ExtendedData>
                         <Data name="header"><value>%s</value></Data>
                         <Data name="prot_number"><value>%s</value></Data>
                         <Data name="depth_range_output"><value>%s</value></Data>
                         <Data name="substrate"><value>%s</value></Data>
                         <Data name="sediment"><value>%s</value></Data>
                         <Data name="wea_label"><value>%s</value></Data>
                         <Data name="wea_state_name"><value>%s</value></Data>
                         <Data name="distance_to_shore"><value>%.0f</value></Data>
                         <Data name="distance_to_awc"><value>%.0f</value></Data>
                         <Data name="wind_speed_output"><value>%s</value></Data>
                         <Data name="ais_density"><value>%s</value></Data>
                         <Data name="user"><value>%s</value></Data>
                         <Data name="modified"><value>%s</value></Data>
                     </ExtendedData>
                     %s
                 </Placemark>
                 """ % ( self.model_uid(), self.name, leaseblock.prot_numb,                             
                         leaseblock.depth_range_output, 
                         leaseblock.majority_seabed, #LeaseBlock Update: might change back to leaseblock.substrate
                         leaseblock.majority_sediment, #TODO: might change sediment to a more user friendly output
                         leaseblock.wea_label,
                         leaseblock.wea_state_name,
                         leaseblock.avg_distance, leaseblock.awc_min_distance,
                         #LeaseBlock Update: added the following two entries (min and max) to replace avg wind speed for now
                         leaseblock.wind_speed_output,
                         leaseblock.ais_density,
                         self.user, self.date_modified.replace(microsecond=0), 
                         #asKml(leaseblock.geometry.transform( settings.GEOMETRY_CLIENT_SRID, clone=True ))
                         asKml(leaseblock.geometry_client)
                       ) 
         except: 
             #this is in place to handle (at least one - "NJ18-05_6420") instance in which null value was used in float field max_distance
             print "The following leaseblock threw an error while generating KML:  %s" %leaseblock.prot_numb
             continue
         combined_kml_list.append(kml )
     combined_kml_list.append("</Folder>")
     combined_kml = ''.join(combined_kml_list)
     elapsed_time = time.time() - start_time
     print 'Finished generating KML (with a list) for %s Lease Blocks in %s seconds' % (len(leaseblock_ids), elapsed_time)
     
     return combined_kml