Beispiel #1
0
def make_kml(x, y, alt, c, type):

    ns = '{http://www.opengis.net/kml/2.2}'
    if type == "wp":
        p= kml.Placemark(ns, name='WP', styleUrl='wp')
        s = styles.Style(id='wp')
        IS = styles.IconStyle(scale=1.2, icon_href='https://maps.google.com/mapfiles/kml/shapes/capital_big_highlight.png', heading=(int(c) - 90))
        s.append_style(IS)
        d = kml.Document(ns=ns, name='WP')
    elif type == "ac":
        p= kml.Placemark(ns, name='AC', styleUrl='ac')
        s = styles.Style(id='ac')
        IS = styles.IconStyle(scale=1.2, icon_href='https://maps.google.com/mapfiles/kml/shapes/airports.png', heading=(int(c)))
        s.append_style(IS)
        d = kml.Document(ns=ns, name='AC')
    elif type == "solo":
        p= kml.Placemark(ns, name='SOLO', styleUrl='solo')
        s = styles.Style(id='solo')
        IS = styles.IconStyle(scale=1.2, icon_href='https://maps.google.com/mapfiles/kml/shapes/camera.png', heading=(int(c) - 90))
        s.append_style(IS)
        d = kml.Document(ns=ns, name='SOLO')
    else:
        return

    geom = Geometry()
    geom.geometry = Point(float(y), float(x), float(alt))
    geom.altitude_mode = 'relativeToGround'
    p.geometry = geom
    d.append_style(s)
    d.append(p)

    return d
Beispiel #2
0
def kml_write(x, y, c):

    #Put coordinates into an xml file

    ns = '{http://www.opengis.net/kml/2.2}'
    d = kml.Document(ns=ns, name='MOBILE GCS')
    k = kml.KML(ns=ns)

    p= kml.Placemark(ns, name='MOBILE GCS', styleUrl='sn_van')
    s = styles.Style(id='sn_van')
    IS = styles.IconStyle(scale=1.2, icon_href='http://maps.google.com/mapfiles/kml/shapes/truck.png', heading=(c - 90))
    s.append_style(IS)

    #AC Geometry

    geom = Geometry()
    geom.geometry = Point(x, y, 0)
    geom.altitude_mode = 'relativeToGround'
    p.geometry = geom
    d.append_style(s)
    d.append(p)

    #Write

    k.append(d)
    kmlfile = open('TOL_GCS.kml',"w")
    kmlfile.write(k.to_string(prettyprint=True))
    kmlfile.close()
Beispiel #3
0
def _flight_export_kml(
    flight: Flight,
    styleUrl: Optional[kml.StyleUrl] = None,
    color: Optional[str] = None,
    alpha: float = 0.5,
    **kwargs,
) -> kml.Placemark:
    if color is not None:
        # the style will be set only if the kml.export context is open
        styleUrl = toStyle(color)
    params = {
        "name": flight.callsign,
        "description": flight._info_html(),
        "styleUrl": styleUrl,
    }
    for key, value in kwargs.items():
        params[key] = value
    placemark = kml.Placemark(**params)
    placemark.visibility = 1
    # Convert to meters
    coords = np.stack(flight.coords)  # type: ignore
    coords[:, 2] *= 0.3048
    placemark.geometry = Geometry(
        geometry=LineString(coords),
        extrude=True,
        altitude_mode="relativeToGround",
    )
    return placemark
    def get_coord_folder(self, coord):
        folder = self.coord_cache.get(coord)
        if folder:
            return folder

        folder = fkml.Folder(ns=self.NS, name=coord, id='f-{}'.format(coord))

        folder.extended_data = fkml.SchemaData(
            ns=self.NS,
            schema_url=self.schema_set['coordinate_metadata'],
            data=[{
                'name': 'coord',
                'value': coord
            }])

        visible_marker = fkml.Placemark(ns=self.NS,
                                        name=coord,
                                        id='pl-{}'.format(coord))

        # Dummy data required by QGIS to display all columns
        dummy_data = [
            {
                'name': 'uuid',
                'value': None
            },
            {
                'name': 'wrs2_path_row',
                'value': None
            },
            {
                'name': 'netcdf_slice',
                'value': None
            },
        ]

        for band in self.bands:
            dummy_data.append({'name': 'band_{}'.format(band), 'value': None})

        visible_marker.extended_data = fkml.SchemaData(
            ns=self.NS,
            schema_url=self.schema_set['placemark_metadata'],
            data=dummy_data)

        visible_marker.geometry = Geometry(
            ns=self.NS,
            geometry=Polygon(
                get_grid_perimeter(*[int(i) for i in coord.split('_')])))

        visible_marker.description = ''
        folder.append(visible_marker)

        self.coord_container.append(folder)
        self.coord_cache[coord] = folder

        return folder
Beispiel #5
0
	def write_to_kml(self,filename):
		k = kml.KML()
		ns = '{http://www.opengis.net/kml/2.2}'
		d = kml.Document(ns=ns, name='SNOPT Stitched Trajectory')

		#styles
		s = styles.Style(id='yellowLineGreenPoly')
		ls = styles.LineStyle(color='7f00ff00',width=4)
		ps = styles.PolyStyle(color='7f00ff00')
		s.append_style(ls)
		s.append_style(ps)
		d.append_style(s)

		#placemark
		pm = kml.Placemark(name='Stitched Trajectory',description='Trajectory for EADDDAS',styleUrl='#yellowLineGreenPoly')
		geom = Geometry()
		coords = []
		for i,x in enumerate(self.east):
			coord = [0]*3
			coord[1] = self.ka.lat + self.north[i]/111111.0 #lat
			coord[0] = self.ka.lon + self.east[i]/(111111.0*cos(coord[1]*pi/180)) #lon
			coord[2] = self.ka.alt + self.up[i] #alt
			coords.append(tuple(coord))
		geom.geometry = LineString(coords)
		geom.extrude = True
		geom.tessellate = True
		geom.altitude_mode = 'absolute'
		pm.geometry = geom
		d.append(pm)
		k.append(d)
		kmlfile = open(filename,"w")
		kmlfile.write(k.to_string(prettyprint=True))
		kmlfile.close()	
Beispiel #6
0
    def main(self):
        with open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin as f:
            # read the whole contents and put it in memory
            lines = f.readlines()
            f.close()

        for line in lines:
            if self.current_line > 2:
                # TODO: establish YUV axis if undef.
                components = line.strip().split()
                if self.gradient_values is None:
                    self.gradient_values = self.setup_gradient_and_t(
                        int(components[1]))
                    # styles.append(kml.Style(self.name_space, styleid, this_style)

                if int(components[1]) > self.threshold:

                    style = self.gradient_values[int(components[1]) - 1]

                    # southwest corner
                    sw_lat_lon = self.mgrs.toLatLon(str.encode(components[0]))
                    ne_lat_lon = self.offset_corner(sw_lat_lon)

                    pm_ident = 'mgrs-'
                    pm_ident += str(self.current_line)
                    style_identifier = "#style-"
                    style_identifier += components[1]
                    # print (f'{components[0]}: lat: {lat_lon[0]:.5f} lon: {lat_lon[1]:.5f} value: {components[1]} {northing} {easting}')
                    p = kml.Placemark(self.name_space, pm_ident, components[0],
                                      ''.join(components), None,
                                      style_identifier)
                    p.geometry = Geometry(
                        self.name_space, '',
                        Polygon([(sw_lat_lon[1], sw_lat_lon[0], 170),
                                 (ne_lat_lon[1], sw_lat_lon[0], 170),
                                 (ne_lat_lon[1], ne_lat_lon[0], 170),
                                 (sw_lat_lon[1], ne_lat_lon[0], 170)]), True,
                        True, 'relativeToGround')
                    self.cell_document.append(p)
                # process line
            self.current_line += 1

        self.output_kml.append(self.cell_document)
        print(self.output_kml.to_string(prettyprint=True))
    def write(self, record_set):
        coord_folder = self.get_coord_folder(record_set.get('coordinate_set'))
        coord_mark = fkml.Placemark(
            ns=self.NS,
            name=record_set.get('observation_date')[0].strftime(
                self.TS_OUTPUT_FMT))
        coord_mark.begin, coord_mark.end = record_set.get('observation_date')
        coord_mark.visibility = 0

        coord_mark.geometry = Geometry(
            ns=self.NS,
            geometry=Polygon(
                *convert_grid_coords(record_set.get('polygon_point_bounds'))))

        coord_data = [{
            'name': 'uuid',
            'value': record_set.get('uuid')
        }, {
            'name': 'wrs2_path_row',
            'value': record_set.get('wrs2_path_row')
        }, {
            'name': 'netcdf_slice',
            'value': record_set.get('netcdf_slice')
        }]

        for band in self.bands:
            coord_data.append({
                'name': 'band_{}'.format(band),
                'value': record_set.get('band_{}'.format(band))
            })

        coord_mark.extended_data = fkml.SchemaData(
            ns=self.NS,
            schema_url=self.schema_set['placemark_metadata'],
            data=coord_data)
        coord_folder.append(coord_mark)
Beispiel #8
0
	def run(self):
		while True:
			#poison pill check
			if self.poison == True:
				break
			else:
				#read gps data (don't block)	
				msg = self.master.recv_match(type='GLOBAL_POSITION_INT', blocking=False)
				if msg:
					#print msg
					self.aclat = msg.lat/1e7
					self.aclon = msg.lon/1e7
					self.acalt = msg.alt/1e3
					self.achdg = msg.hdg/1e2

					#Find position relative to Ka-1 (ENU)
					#Convert degrees to radians:
					lat1 = self.kalat * pi/180
					lon1 = self.kalon * pi/180
					lat2 = self.aclat * pi/180
					lon2 = self.aclon * pi/180
					dlat  = lat2-lat1
					dlong = lon2-lon1

					#Haversine formula
					R = 6371000
					a = sin(dlat/2)*sin(dlat/2) + cos(lat1)*cos(lat2)*sin(dlong/2.0)*sin(dlong/2.0)
					c = 2.0 * atan2( sqrt(a), sqrt(1-a) )
					d = R * c;	#distance
					b = atan2( sin(dlong)*cos(lat2), cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(dlong) )

					self.east = d*cos(pi/2-b)	#x meters offset from Datum (ENU)
					self.north = d*sin(pi/2-b)	#y meters offset from Datum (ENU)
					self.up = self.acalt - self.kaalt #z meters offset from Datum (ENU), should never be negative lol

					#write KML for plane
					ns = '{http://www.opengis.net/kml/2.2}'
					d = kml.Document(ns=ns, name='TOL GCS')
					k = kml.KML(ns=ns)

					#AIRCRAFT
					p= kml.Placemark(ns, name='sUAS(' + '{0:.2f}'.format(self.east) +','+ '{0:.2f}'.format(self.north) +','+ '{0:.2f}'.format(self.up) + ')', styleUrl='sn_airports')
					#AC Style
					s = styles.Style(id='sn_airports')
					IS = styles.IconStyle(scale=1.2, icon_href='http://maps.google.com/mapfiles/kml/shapes/airports.png', heading=self.achdg)
					s.append_style(IS)
					#AC Geometry
					geom = Geometry()
					geom.geometry = Point(self.aclon, self.aclat, self.acalt)
					geom.altitude_mode = 'absolute'
					p.geometry = geom
					d.append_style(s)
					d.append(p)

					#MGS
					p = kml.Placemark(ns, name='MGS (0,0,0)',styleUrl='sn_truck')
					s = styles.Style(id='sn_truck')
					IS = styles.IconStyle(scale=1.2, icon_href='http://maps.google.com/mapfiles/kml/shapes/truck.png')
					s.append_style(IS)
					#MGS Geometry
					geom = Geometry()
					geom.geometry = Point(self.kalon, self.kalat, self.kaalt)
					geom.altitude_mode = 'absolute'
					p.geometry = geom
					d.append_style(s)
					d.append(p)

					#WRITE
					k.append(d)
					kmlfile = open('TOL_GCS.kml',"w")
					kmlfile.write(k.to_string(prettyprint=True))
					kmlfile.close()
Beispiel #9
0
    def run(self):
        while True:
            #poison pill check
            if self.poison == True:
                break
            else:
                #read gps data (don't block)
                msg = self.master.recv_match(type='GLOBAL_POSITION_INT',
                                             blocking=False)
                if msg:
                    #print msg
                    self.aclat = msg.lat / 1e7
                    self.aclon = msg.lon / 1e7
                    self.acalt = msg.alt / 1e3
                    self.achdg = msg.hdg / 1e2

                    #Find position relative to Ka-1 (ENU)
                    #Convert degrees to radians:
                    lat1 = self.kalat * pi / 180
                    lon1 = self.kalon * pi / 180
                    lat2 = self.aclat * pi / 180
                    lon2 = self.aclon * pi / 180
                    dlat = lat2 - lat1
                    dlong = lon2 - lon1

                    #Haversine formula
                    R = 6371000
                    a = sin(dlat / 2) * sin(dlat / 2) + cos(lat1) * cos(
                        lat2) * sin(dlong / 2.0) * sin(dlong / 2.0)
                    c = 2.0 * atan2(sqrt(a), sqrt(1 - a))
                    d = R * c
                    #distance
                    b = atan2(
                        sin(dlong) * cos(lat2),
                        cos(lat1) * sin(lat2) -
                        sin(lat1) * cos(lat2) * cos(dlong))

                    self.east = d * cos(
                        pi / 2 - b)  #x meters offset from Datum (ENU)
                    self.north = d * sin(
                        pi / 2 - b)  #y meters offset from Datum (ENU)
                    self.up = self.acalt - self.kaalt  #z meters offset from Datum (ENU), should never be negative lol

                    #write KML for plane
                    ns = '{http://www.opengis.net/kml/2.2}'
                    d = kml.Document(ns=ns, name='TOL GCS')
                    k = kml.KML(ns=ns)

                    #AIRCRAFT
                    p = kml.Placemark(ns,
                                      name='sUAS(' +
                                      '{0:.2f}'.format(self.east) + ',' +
                                      '{0:.2f}'.format(self.north) + ',' +
                                      '{0:.2f}'.format(self.up) + ')',
                                      styleUrl='sn_airports')
                    #AC Style
                    s = styles.Style(id='sn_airports')
                    IS = styles.IconStyle(
                        scale=1.2,
                        icon_href=
                        'http://maps.google.com/mapfiles/kml/shapes/airports.png',
                        heading=self.achdg)
                    s.append_style(IS)
                    #AC Geometry
                    geom = Geometry()
                    geom.geometry = Point(self.aclon, self.aclat, self.acalt)
                    geom.altitude_mode = 'absolute'
                    p.geometry = geom
                    d.append_style(s)
                    d.append(p)

                    #MGS
                    p = kml.Placemark(ns,
                                      name='MGS (0,0,0)',
                                      styleUrl='sn_truck')
                    s = styles.Style(id='sn_truck')
                    IS = styles.IconStyle(
                        scale=1.2,
                        icon_href=
                        'http://maps.google.com/mapfiles/kml/shapes/truck.png')
                    s.append_style(IS)
                    #MGS Geometry
                    geom = Geometry()
                    geom.geometry = Point(self.kalon, self.kalat, self.kaalt)
                    geom.altitude_mode = 'absolute'
                    p.geometry = geom
                    d.append_style(s)
                    d.append(p)

                    #WRITE
                    k.append(d)
                    kmlfile = open('TOL_GCS.kml', "w")
                    kmlfile.write(k.to_string(prettyprint=True))
                    kmlfile.close()