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 ))
           )        
Beispiel #2
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)))
 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
Beispiel #4
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.planning_units) == 0:  #empty result
            planningunit_ids = []
            combined_kml_list.append(
                '<Folder id="%s"><name>%s -- 0 Planning Units</name><visibility>0</visibility><open>0</open>'
                % (self.uid, self.name))
        else:
            planningunit_ids = [
                int(id) for id in self.planning_units.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.planningunit_style())
        print('Generating KML for %s Planning Units' % len(planningunit_ids))
        start_time = time.time()
        planningunits = PlanningUnit.objects.filter(pk__in=planningunit_ids)
        for planningunit in planningunits:
            try:
                kml = """
                    <Placemark>
                        <visibility>1</visibility>
                        <styleUrl>#%s-planningunit</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,
                    # planningunit.prot_numb,
                    # planningunit.depth_range_output,
                    # planningunit.majority_seabed, #LeaseBlock Update: might change back to leaseblock.substrate
                    # planningunit.majority_sediment, #TODO: might change sediment to a more user friendly output
                    # planningunit.wea_label,
                    # planningunit.wea_state_name,
                    # planningunit.avg_distance,
                    # planningunit.awc_min_distance,
                    # #LeaseBlock Update: added the following two entries (min and max) to replace avg wind speed for now
                    # planningunit.wind_speed_output,
                    # planningunit.ais_density,
                    self.user,
                    self.date_modified.replace(microsecond=0),
                    #asKml(leaseblock.geometry.transform( settings.GEOMETRY_CLIENT_SRID, clone=True ))
                    asKml(planningunit.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 planning unit threw an error while generating KML:  %s" %planningunit.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 Planning Units in %s seconds'
            % (len(planningunit_ids), elapsed_time))

        return combined_kml