def kmlGetSessionResponse(self, request, quotedId, method): sessionId = urllib.unquote_plus(quotedId) #print 'sessionId:', sessionId #print 'method:', method if method == 'initial': return KmlUtil.wrapKmlDjango(self.kmlGetInitialKml(request, sessionId)) elif method == 'update': return KmlUtil.wrapKmlDjango(self.kmlGetUpdateKml(request, sessionId)) else: raise Exception('method must be "initial" or "update"')
def kmlGetSessionResponse(self, request, quotedId, method): sessionId = urllib.unquote_plus(quotedId) #print 'sessionId:', sessionId #print 'method:', method if method == 'initial': return KmlUtil.wrapKmlDjango( self.kmlGetInitialKml(request, sessionId)) elif method == 'update': return KmlUtil.wrapKmlDjango( self.kmlGetUpdateKml(request, sessionId)) else: raise Exception('method must be "initial" or "update"')
def makeStyles(self): waypointStyle = KmlUtil.makeStyle( "station", "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png", 0.85) directionStyle = KmlUtil.makeStyle( "heading", iconUrl= "http://earth.google.com/images/kml-icons/track-directional/track-0.png" ) segmentStyle = KmlUtil.makeStyle("segment", lineWidth=2) return waypointStyle + directionStyle + segmentStyle
def convertUsngCsv(opts, inPath): inFile = file(inPath, 'r') inLines = csv.reader(inFile) coords = [] for latDms, lonDms, name in inLines: lat = parseDegMinSec(latDms) lon = parseDegMinSec(lonDms) easting, northing, zoneNumber, zoneLetter = usng.LLtoUTM(lat, lon) easting += opts.eastOffset northing += opts.northOffset usngCoords = usng.UTMtoUSNG(easting, northing, zoneNumber, zoneLetter, precision=5) print usngCoords, ' ', name clat, clon = usng.UTMtoLL(easting, northing, zoneNumber, zoneLetter) coords.append((clat, clon, name, usngCoords)) if opts.kml: kbits = [] kbits.append('<Folder>\n') for lat, lon, name, usngCoords in coords: kbits.append(""" <Placemark> <name>%(name)s</name> <description>%(usngCoords)s</description> <Point> <coordinates>%(lon)s,%(lat)s</coordinates> </Point> </Placemark> """ % dict(lat=lat, lon=lon, name=name, usngCoords=usngCoords)) kbits.append('</Folder>') text = ''.join(kbits) file(opts.kml, 'w').write(KmlUtil.wrapKml(text))
def transformStation(self, station, tsequence, context): lon, lat = station.geometry['coordinates'] name = station.name if not name: # use the number from the id sindex = station.id.find('STN') if sindex >=0: name = station.id[sindex+3:] else: name = station.id name = "__" + name directionStyle = None styleUrl = 'station' result = "" try: if station.isDirectional: if station.headingDegrees: headingDegrees = float(station.headingDegrees) styleUrl = 'heading' directionStyle = KmlUtil.makeStyle(iconHeading=headingDegrees) except AttributeError: pass result = result + (''' <Placemark> <name>%s</name> <styleUrl>%s</styleUrl>''' % (escape(name), styleUrl)) if directionStyle: result = result + directionStyle result = result + (''' <Point> <coordinates>%(lon)s,%(lat)s</coordinates> </Point> </Placemark>''' % {'lon': lon, 'lat': lat}) return result
def makeStyles(request, mapLayer): style = KmlUtil.makeStyle("xgds", iconUrl=request.build_absolute_uri(static('xgds_map_server/icons/point.png')), iconScale=0.5, lineColor='FFFF0000', lineWidth=4, polyColor='44FF0000') return style
def createBoundaryStyle(feature): if feature.style: style = feature.style[1:] else: style = "0000ff" color = getKmlColor(style, "ff") styleName = "boundary" + style style = KmlUtil.makeStyle(styleName, lineWidth=3, lineColor=color) return style
def createToleranceStyle(feature): if feature.style: style = feature.style[1:] else: style = "0000ff" color = getKmlColor(style, "80") styleName = "tolerance" + style style = KmlUtil.makeStyle(styleName, lineWidth=3, lineColor=color) return style
def makeStyles(self): if self.request: placemark_url = self.getFullUrl( 'xgds_planner2/images/placemark_circle.png') placemark_directional_url = self.getFullUrl( 'xgds_planner2/images/placemark_directional.png') waypointStyle = KmlUtil.makeStyle("station", placemark_url, 0.85) directionStyle = KmlUtil.makeStyle( "heading", iconUrl=placemark_directional_url) else: waypointStyle = KmlUtil.makeStyle( "station", "https://maps.google.com/mapfiles/kml/shapes/placemark_circle.png", 0.85) directionStyle = KmlUtil.makeStyle( "heading", iconUrl= "https://earth.google.com/images/kml-icons/track-directional/track-0.png" ) segmentStyle = KmlUtil.makeStyle("segment", lineWidth=2) return waypointStyle + directionStyle + segmentStyle
def makeStyles(self): waypointStyle = KmlUtil.makeStyle( "station", "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png", 0.85) directionStyle = KmlUtil.makeStyle( "heading", iconUrl= "http://earth.google.com/images/kml-icons/track-directional/track-0.png" ) segmentStyle = KmlUtil.makeStyle("segment", lineWidth=3, lineColor="FF00FFFF") boundaryStyle = KmlUtil.makeStyle("boundary", lineWidth=3, lineColor="FF0099FF") toleranceStyle = KmlUtil.makeStyle( "tolerance", lineWidth=3, lineColor="FF00FFFF", ) return waypointStyle + directionStyle + segmentStyle + boundaryStyle + toleranceStyle
def createStyle(request, feature): if feature.style: style = feature.style[1:] else: style = "0000ff" styleName = style + feature.type color = getKmlColor(style, "ff") iconLink = "" if (feature.type == "Point"): if hasattr(feature, 'shape'): styleName = style + feature.type + "_" + feature.shape if (feature.shape == "Triangle"): iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/triangle-point.png')) elif (feature.shape == "Square"): iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/square-point.png')) elif (feature.shape == "Star"): iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/star-point.png')) else: iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/point.png')) else: iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/point.png')) elif (feature.type == "Station"): request.build_absolute_uri( static('rest/xgds_map_server/icons/placemark_circle.png')) else: iconLink = request.build_absolute_uri( static('rest/xgds_map_server/icons/point.png')) style = KmlUtil.makeStyle(styleName, iconUrl=iconLink, iconColor=color, iconScale=0.5, lineColor=color, lineWidth=4, polyColor=color, polyFill=0) return style
def feed_messages_kml(request, recipient_username=None, author_username=None): _timestamp, messages, _message_count = get_messages(request, recipient_username, author_username) out = StringIO() iconHref = request.build_absolute_uri(settings.MEDIA_URL + 'geocamTalk/icons/word_bubble.png') out.write(""" <Document> <Style id="talkMarker"> <IconStyle> <Icon> <href>%(iconHref)s</href> </Icon> </IconStyle> </Style> """ % dict(iconHref=iconHref)) for msg in messages: out.write(msg.getKml()) out.write("</Document>") return KmlUtil.wrapKmlDjango(out.getvalue())
def feed_messages_kml(request, author_username=None): messages, _message_count = get_messages(request, author_username) out = StringIO() iconHref = request.build_absolute_uri(settings.MEDIA_URL + 'geocamMemo/icons/note.png') out.write(""" <Document> <Style id="memoMarker"> <IconStyle> <Icon> <href>%(iconHref)s</href> </Icon> </IconStyle> </Style> """ % dict(iconHref=iconHref)) for msg in messages: out.write(msg.getKml()) out.write("</Document>") return KmlUtil.wrapKmlDjango(out.getvalue())
def mapIndexKml(request): out = StringIO() writeMapIndexKml(request, out) return KmlUtil.wrapKmlDjango(out.getvalue())
def transformPlan(self, plan, tsequence, context): name = escape(plan.get("name")) if not name: name = escape(plan.get("id", "")) return KmlUtil.wrapKmlDocument( self.makeStyles() + '\n'.join(tsequence), name)
def kmlStartSession(self, request): searchQuery = request.REQUEST.get('q', None) sessionId = GoogleEarthSession.getSessionId(searchQuery) print >> sys.stderr, "ViewKml: started session %s" % sessionId return KmlUtil.wrapKmlDjango( self.kmlGetStartSessionKml(request, sessionId))
def kmlFeed(self, request): return KmlUtil.wrapKmlDjango(self.kmlGetInitialKml(request))
def transformStation(self, station, tsequence, context): lon, lat = station.geometry['coordinates'] name = station.name if not name: # use the number from the id sindex = station.id.find('STN') if sindex >= 0: name = station.id[sindex + 3:] else: name = station.id name = "__" + name directionStyle = None styleUrl = 'station' result = "" try: if station.isDirectional: if station.headingDegrees: headingDegrees = float(station.headingDegrees) styleUrl = 'heading' directionStyle = KmlUtil.makeStyle( iconHeading=headingDegrees) except AttributeError: pass result = result + (''' <Placemark> <name>%s</name> <styleUrl>%s</styleUrl>''' % (escape(name), styleUrl)) if directionStyle: result = result + directionStyle result = result + (''' <Point> <coordinates>%(lon)s,%(lat)s</coordinates> </Point> </Placemark>''' % { 'lon': lon, 'lat': lat }) if station.boundary: boundaryCircle = polycircles.Polycircle(latitude=lat, longitude=lon, radius=station.boundary, number_of_vertices=36) result += ''' <Placemark> <name>%(name)s</name> <styleUrl>#boundary</styleUrl> <MultiGeometry> <LineString> <tessellate>1</tessellate> <coordinates> ''' % { 'name': escape(name) + ' boundary' } for coord in boundaryCircle.vertices: result = result + str(coord[1]) + ',' + str(coord[0]) + '\n' result = result + str(boundaryCircle.vertices[0][1]) + ',' + str( boundaryCircle.vertices[0][0]) + '\n' result = result + ''' </coordinates> </LineString> </MultiGeometry> </Placemark> ''' if station.tolerance: toleranceCircle = polycircles.Polycircle(latitude=lat, longitude=lon, radius=station.tolerance, number_of_vertices=36) result += ''' <Placemark> <name>%(name)s</name> <styleUrl>#tolerance</styleUrl> <LineString> <tessellate>1</tessellate> <coordinates> ''' % { 'name': escape(name) + ' tolerance' } for coord in toleranceCircle.vertices: result = result + str(coord[1]) + ',' + str(coord[0]) + '\n' result = result + str(toleranceCircle.vertices[0][1]) + ',' + str( toleranceCircle.vertices[0][0]) + '\n' result = result + ''' </coordinates> </LineString> </Placemark> ''' return result
def kmlStartSession(self, request): searchQuery = request.REQUEST.get('q', None) sessionId = GoogleEarthSession.getSessionId(searchQuery) print >>sys.stderr, "ViewKml: started session %s" % sessionId return KmlUtil.wrapKmlDjango(self.kmlGetStartSessionKml(request, sessionId))
def mapTileKml(request, layerId, dayCode, level, x, y): level = int(level) x = int(x) y = int(y) # make links to sub-tiles if necessary if level < settings.XGDS_PLOT_MAP_ZOOM_RANGE[1] - 1: linkList = [] subLevel = level + 1 for offset in ((0, 0), (0, 1), (1, 0), (1, 1)): subX = 2 * x + offset[0] subY = 2 * y + offset[1] subUrl = (request.build_absolute_uri (reverse ('xgds_plot_mapTileKml', args=[layerId, dayCode, subLevel, subX, subY]))) linkList.append(""" <NetworkLink> <Region> %(box)s <Lod> <minLodPixels>%(minLodPixels)s</minLodPixels> <maxLodPixels>-1</maxLodPixels> </Lod> </Region> <Link> <href>%(subUrl)s</href> <viewRefreshMode>onRegion</viewRefreshMode> </Link> </NetworkLink> """ % dict(box=tile.getLatLonAltBox(tile.getTileBounds(subLevel, subX, subY)), subUrl=subUrl, minLodPixels=settings.XGDS_PLOT_MAP_PIXELS_PER_TILE // 2)) netLinks = '\n'.join(linkList) else: netLinks = '' #tileUrl = request.build_absolute_uri(reverse('mapTileImage', args=[level, x, y])) tileUrl = request.build_absolute_uri('%s/%s/%s/%d/%d/%d.png' % (MAP_DATA_PATH, layerId, dayCode, level, x, y)) bounds = tile.getTileBounds(level, x, y) minZoom, maxZoom = settings.XGDS_PLOT_MAP_ZOOM_RANGE if level < maxZoom - 1: maxLodPixels = settings.XGDS_PLOT_MAP_PIXELS_PER_TILE * 2 else: maxLodPixels = -1 if level > minZoom: minLodPixels = settings.XGDS_PLOT_MAP_PIXELS_PER_TILE // 2 else: minLodPixels = -1 return KmlUtil.wrapKmlDjango(""" <Folder> %(netLinks)s <GroundOverlay> <Icon> <href>%(tileUrl)s</href> <refreshMode>onInterval</refreshMode> <refreshInterval>5</refreshInterval> </Icon> %(llBox)s <drawOrder>%(level)s</drawOrder> <Region> %(llaBox)s <Lod> <minLodPixels>%(minLodPixels)s</minLodPixels> <maxLodPixels>%(maxLodPixels)s</maxLodPixels> </Lod> </Region> </GroundOverlay> <Style> <ListStyle> <listItemType>checkHideChildren</listItemType> </ListStyle> </Style> </Folder> """ % dict(netLinks=netLinks, llBox=tile.getLatLonBox(bounds), llaBox=tile.getLatLonAltBox(bounds), tileUrl=tileUrl, level=level, minLodPixels=minLodPixels, maxLodPixels=maxLodPixels))
def transformPlan(self, plan, tsequence, context): name = escape(plan.get("name")) if not name: name = escape(plan.get("id", "")) return KmlUtil.wrapKmlDocument(self.makeStyles() + '\n'.join(tsequence), name)
def makeStyles(self): waypointStyle = KmlUtil.makeStyle("station", "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png", 0.85) directionStyle = KmlUtil.makeStyle("heading", iconUrl="http://earth.google.com/images/kml-icons/track-directional/track-0.png") segmentStyle = KmlUtil.makeStyle("segment", lineWidth=2) return waypointStyle + directionStyle + segmentStyle
def mapTileKml(request, layerId, dayCode, level, x, y): level = int(level) x = int(x) y = int(y) # make links to sub-tiles if necessary if level < settings.XGDS_PLOT_MAP_ZOOM_RANGE[1] - 1: linkList = [] subLevel = level + 1 for offset in ((0, 0), (0, 1), (1, 0), (1, 1)): subX = 2 * x + offset[0] subY = 2 * y + offset[1] subUrl = (request.build_absolute_uri( reverse('xgds_plot_mapTileKml', args=[layerId, dayCode, subLevel, subX, subY]))) linkList.append(""" <NetworkLink> <Region> %(box)s <Lod> <minLodPixels>%(minLodPixels)s</minLodPixels> <maxLodPixels>-1</maxLodPixels> </Lod> </Region> <Link> <href>%(subUrl)s</href> <viewRefreshMode>onRegion</viewRefreshMode> </Link> </NetworkLink> """ % dict(box=tile.getLatLonAltBox(tile.getTileBounds(subLevel, subX, subY)), subUrl=subUrl, minLodPixels=settings.XGDS_PLOT_MAP_PIXELS_PER_TILE // 2)) netLinks = '\n'.join(linkList) else: netLinks = '' #tileUrl = request.build_absolute_uri(reverse('mapTileImage', args=[level, x, y])) tileUrl = request.build_absolute_uri( '%s/%s/%s/%d/%d/%d.png' % (MAP_DATA_PATH, layerId, dayCode, level, x, y)) bounds = tile.getTileBounds(level, x, y) minZoom, maxZoom = settings.XGDS_PLOT_MAP_ZOOM_RANGE if level < maxZoom - 1: maxLodPixels = settings.XGDS_PLOT_MAP_PIXELS_PER_TILE * 2 else: maxLodPixels = -1 if level > minZoom: minLodPixels = settings.XGDS_PLOT_MAP_PIXELS_PER_TILE // 2 else: minLodPixels = -1 return KmlUtil.wrapKmlDjango(""" <Folder> %(netLinks)s <GroundOverlay> <Icon> <href>%(tileUrl)s</href> <refreshMode>onInterval</refreshMode> <refreshInterval>5</refreshInterval> </Icon> %(llBox)s <drawOrder>%(level)s</drawOrder> <Region> %(llaBox)s <Lod> <minLodPixels>%(minLodPixels)s</minLodPixels> <maxLodPixels>%(maxLodPixels)s</maxLodPixels> </Lod> </Region> </GroundOverlay> <Style> <ListStyle> <listItemType>checkHideChildren</listItemType> </ListStyle> </Style> </Folder> """ % dict(netLinks=netLinks, llBox=tile.getLatLonBox(bounds), llaBox=tile.getLatLonAltBox(bounds), tileUrl=tileUrl, level=level, minLodPixels=minLodPixels, maxLodPixels=maxLodPixels))