예제 #1
0
def createPoints(kmlDoc, epochTime, latitude, longitude):
  # This creates a <Placemark> element for a row of data.
  # A row is a dict.
  placemarkElement = kmlDoc.createElement('Placemark')
  styleUrl= '#point-style'
  styleUrlElement = kmlDoc.createElement('styleUrl')
  styleUrlElement.appendChild(kmlDoc.createTextNode(styleUrl))
  placemarkElement.appendChild(styleUrlElement)

##  time = int(time)
##  t=time.gmtime(epochTime)
##  timeString="%s-%s-%s %s:%s:%s"%(strftime("%Y", t),strftime("%m", t),strftime("%d", t),strftime("%H", t),strftime("%M", t),strftime("%S", t))

  timeString = str(utils.timestamp_todate(int(epochTime)))
  nameElement = kmlDoc.createElement('name')
  nameElement.appendChild(kmlDoc.createTextNode(timeString[0:19]))
  placemarkElement.appendChild(nameElement)
  
  
  extElement = kmlDoc.createElement('ExtendedData')
  placemarkElement.appendChild(extElement)
  
  # Loop through the columns and create a <Data> element for every field that has a value.
  dataElement = kmlDoc.createElement('Data')
  dataElement.setAttribute('name', 'timestamp')
  valueElement = kmlDoc.createElement('value')
  dataElement.appendChild(valueElement)
  valueText = kmlDoc.createTextNode(timeString)
  valueElement.appendChild(valueText)
  extElement.appendChild(dataElement)
  dataElement = kmlDoc.createElement('Data')
  dataElement.setAttribute('name', 'latitude')
  valueElement = kmlDoc.createElement('value')
  dataElement.appendChild(valueElement)
  valueText = kmlDoc.createTextNode(str(latitude))
  valueElement.appendChild(valueText)
  extElement.appendChild(dataElement)
  dataElement = kmlDoc.createElement('Data')
  dataElement.setAttribute('name', 'longitude')
  valueElement = kmlDoc.createElement('value')
  dataElement.appendChild(valueElement)
  valueText = kmlDoc.createTextNode(str(longitude))
  valueElement.appendChild(valueText)
  extElement.appendChild(dataElement)
  
  pointElement = kmlDoc.createElement('Point')
  placemarkElement.appendChild(pointElement)
  extrude= '1'
  extrudeElement = kmlDoc.createElement('extrude')
  extrudeElement.appendChild(kmlDoc.createTextNode(extrude))
  pointElement.appendChild(extrudeElement)
  altitudeMode= 'relativeToGround'
  altitudeModeElement = kmlDoc.createElement('altitudeMode')
  altitudeModeElement.appendChild(kmlDoc.createTextNode(altitudeMode))
  pointElement.appendChild(altitudeModeElement)
  coordinates = '%s,%s,1' % (longitude, latitude)
  coorElement = kmlDoc.createElement('coordinates')
  coorElement.appendChild(kmlDoc.createTextNode(coordinates))
  pointElement.appendChild(coorElement)
  return placemarkElement
예제 #2
0
def edit_deployment(request, project_id, deployment_id):
    query = get_query("deployment")
    deployment = query(deployment_id)

    if isinstance( deployment.time_end, (int, long) ):
        time_end = utils.strftime(utils.timestamp_todate(deployment.time_end))
    else:
        time_end = "None"

    return render_project_form(
        request=request,
        project_id=project_id,
        post_form=EditDeploymentForm(data=request.POST, instance=deployment),
        get_form=EditDeploymentForm(
            instance=deployment,
            initial={'time_start':
                     utils.strftime(
                         utils.timestamp_todate(deployment.time_start)),
                     'time_end': time_end}),
        template_path="project/edit-deployment.html",
        success_url="%s?new_element=True" % reverse(
            "project:edit-deployment", args=(project_id, deployment_id)))
예제 #3
0
 def get_end(self):
     if(self.time_end != None):
         return strftime(timestamp_todate(self.time_end))
     else:
         return ""
예제 #4
0
 def get_start(self):
     if(self.time_start != None):
         return strftime(timestamp_todate(self.time_start))
     else:
         return ""
예제 #5
0
def createKML(deploymentIDs, radius, numberOfIntervals, trackPath, trackLocation, histogram, timeArray, latitudeArray, longitudeArray):

  kmlDoc = xml.dom.minidom.Document()

  ## Add headings to the KML.
  kmlElement = kmlDoc.createElementNS('http://earth.google.com/kml/2.2', 'kml')
  kmlElement.setAttribute('xmlns', 'http://www.opengis.net/kml/2.2')
  kmlElement.setAttribute('xmlns:gx', 'http://www.google.com/kml/ext/2.2')
  kmlElement.setAttribute('xmlns:kml', 'http://www.opengis.net/kml/2.2')
  kmlElement.setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom')
  kmlElement = kmlDoc.appendChild(kmlElement)
  documentElement = kmlDoc.createElement('Document')
  documentElement = kmlElement.appendChild(documentElement)

  ##Add styles for different content.
  styleElement = createStyle(kmlDoc)
  documentElement.appendChild(styleElement)
  styleElement2 = createStyle2(kmlDoc)
  documentElement.appendChild(styleElement2)

  ##Sample the mean time, latitude, and longitude.
  [meanTimeArray, meanLatitudeArray, meanLongitudeArray] = meanTimeSampling(numberOfIntervals, timeArray, latitudeArray, longitudeArray)

  ##Convert time into Google Earth readable form.
  ## Time zone will need to be set or queried!!!
  convertedTime=[]
  for JStime in meanTimeArray:
#      tm=time.gmtime(float(JStime))
#      timeString="%s-%s-%sT%s:%s:%sZ"%(strftime("%Y", t),strftime("%m", t),strftime("%d", t),strftime("%H", t),strftime("%M", t),strftime("%S", t))
#      timeString = strftime("%Y-%m-%dT%H:%M:%SZ",tm)
      timeString = utils.timestamp_todate(int(JStime))
      timeString = str(timeString)[0:10]+'T'+str(timeString)[11:25]
      convertedTime.append(timeString)

  for dep in deploymentIDs:
    ##Create tracks if the setting is yes.
    if (trackPath=='Yes'):
      trackElement = createTrack(kmlDoc,dep,convertedTime,meanLongitudeArray,meanLatitudeArray)
      documentElement.appendChild(trackElement)

    ##Create track locatoins if the setting is yes.
    if (trackLocation=='Yes'):
      folderElement = kmlDoc.createElement('Folder')
      folderName = 'Track Locations %s' % (dep)
      nameElement = kmlDoc.createElement('name')
      nameElement.appendChild(kmlDoc.createTextNode(folderName))
      folderElement.appendChild(nameElement)
      meanArrayLength = len(meanTimeArray)
      for i in range(meanArrayLength):
        placemarkElement = createPoints(kmlDoc, meanTimeArray[i], meanLatitudeArray[i], meanLongitudeArray[i])
        folderElement.appendChild(placemarkElement)
      documentElement.appendChild(folderElement)

    ##Create histogram if the setting is yes.
    if (histogram=='Yes'):
      [altitudeArray, maxAltitude] = calculateAltitude(radius, latitudeArray, longitudeArray)
      folderElement2 = kmlDoc.createElement('Folder')
      folderName2 = 'Histogram %s' % (dep)
      nameElement2 = kmlDoc.createElement('name')
      nameElement2.appendChild(kmlDoc.createTextNode(folderName2))
      folderElement2.appendChild(nameElement2)
      arrayLength=len(altitudeArray)
      for i in range(arrayLength):
        placemarkElement = createPlacemark(kmlDoc, altitudeArray[i], latitudeArray[i], longitudeArray[i], maxAltitude)
        folderElement2.appendChild(placemarkElement)
      documentElement.appendChild(folderElement2)

  ##Output the file.
  ##fileName = 'deployment%s_python.kml'%(deploymentID)
  ##kmlFile = open(fileName, 'w')
  ##kmlFile.write(kmlDoc.toprettyxml('  ', newl = '\n', encoding = 'utf-8'))

  return kmlDoc.toprettyxml('  ', newl = '\n', encoding = 'utf-8')