示例#1
0
def buildStyles():
    ''' Build the various styles to be used for the placemarks'''
    kmlStyles = []
    for level in ADVISORY_SCALE:
        # build the dot style
        innerIconStyle = styles.IconStyle(NAME_SPACE,
                                          scale=.7,
                                          icon_href=buildDotIconUrl(level))
        iconStyle = styles.Style(NAME_SPACE,
                                 id=getDotIconId(level),
                                 styles=[innerIconStyle])
        kmlStyles.append(iconStyle)

        # build the polygon style
        innerPolyStyle = styles.PolyStyle(NAME_SPACE,
                                          color='33' + ADVISORY_SCALE[level],
                                          fill=1,
                                          outline=1)
        innerLineStyle = styles.LineStyle(NAME_SPACE,
                                          color='FF' + ADVISORY_SCALE[level],
                                          width=2)
        polyStyle = styles.Style(NAME_SPACE,
                                 id=getPolyStyleId(level),
                                 styles=[innerLineStyle, innerPolyStyle])
        kmlStyles.append(polyStyle)
    return kmlStyles
示例#2
0
文件: color.py 项目: rsavoye/gosm
 def campground(self, data):
     self.description = ""
     icon = styles.IconStyle(icon_href="icons/campground.png")
     self.icons.append(icon.icon_href)
     self.styles = styles.Style(styles=[icon])
     self.description = ""
     if 'drinking_water' in data:
         if data['drinking_water'] == 'yes':
             self.description += "Water Available"
     if 'toilets' in data:
         if data['toilets'] == 'yes':
             self.description += "Toilet Available"
     return self.styles, self.description
示例#3
0
文件: color.py 项目: rsavoye/gosm
    def milestones(self, data):
        #print(data)
        self.description = ""
        id = data['osm_id']
        num = data['name']
        if 'alt_name' in data:
            street = data['alt_name']
        else:
            street = "unknown"
        self.description = "%s Highway %s" % (num, street)

        icon = styles.IconStyle(icon_href="icons/mm_highway_milestone.png")
        self.icons.append(icon.icon_href)
        self.styles = styles.Style(styles=[icon])

        return self.styles, self.description
示例#4
0
文件: color.py 项目: rsavoye/gosm
    def campsite(self, data=dict(), ground=None):
        self.description = ""
        icon = styles.IconStyle(icon_href="icons/mx_tourism_camp_site.png")
        self.icons.append(icon.icon_href)
        self.styles = styles.Style(styles=[icon])

        if ground is not None:
            self.description += ground

        if len(data) > 2:
            self.description += "<br><i>Has these features</i>:"

        if 'fee' in data:
            if data['fee'] == 'yes':
                self.description += "<brHas fee"
        if 'openfire' in data:
            if data['openfire'] == 'yes':
                self.description += "<br>Open fires allowed"
        if 'internet_access' in data:
            if data['internet_access'] == 'yes':
                self.description += "<br>Internet Available"
        if 'caravans' in data:
            if data['caravans'] == 'yes':
                self.description += "<br>RVs allowed"
        if 'parking' in data:
            if data['parking'] == 'yes':
                self.description += "<br>Parking Available"

        if 'drinking_water' in data:
            if data['drinking_water'] == 'yes':
                self.description += "<br>Drinking Water Available"
        if 'toilets' in data:
            if data['toilets'] == 'yes':
                self.description += "<br>Toilet Available"
        if 'bbq' in data:
            if data['bbq'] == 'yes':
                self.description += "<br>Grill Available"
        if 'power_supply' in data:
            if data['power_supply'] == 'yes':
                self.description += "<br>AC Power Available"
        if 'picnic_table' in data:
            if data['picnic_table'] == 'yes':
                self.description += "<br>Picbic table Available"
        if 'leisure' in data:
            self.description += "<br>Firepit"
        return self.styles, self.description
示例#5
0
文件: color.py 项目: rsavoye/gosm
    def addresses(self, data):
        #print(data)
        self.description = ""
        color = "ffffff00"
        id = data['osm_id']
        name = ""
        if 'name' in data:
            if data['name'] is not None:
                name = data['name'] + '\n'

        if 'addr_street' in data:
            self.description = "%s %s %s" % (name, str(
                data['addr_housenumber']), data['addr_street'])
        # label = styles.LabelStyle(color='black', scale=1.0)
        icon = styles.IconStyle(icon_href="icons/mm_building.png")
        self.icons.append(icon.icon_href)
        self.styles = styles.Style(styles=[icon])

        return self.styles, self.description
示例#6
0
文件: color.py 项目: rsavoye/gosm
    def firewater(self, data):
        self.description = ""
        if 'water_tank' in data:
            icon = styles.IconStyle(
                icon_href="icons/mx_fire_hydrant_type_pillar.png")

        if 'emergency' in data:
            if data['emergency'] == "fire_hydrant":
                icon = styles.IconStyle(
                    icon_href="icons/mx_fire_hydrant_type_pillar.png")
            elif data['emergency'] == "water_tank":
                icon = styles.IconStyle(icon_href="icons/mx_storage_tank.png")
            elif data['emergency'] == "fire_water_pond":
                icon = styles.IconStyle(icon_href="icons/water.png")
            elif data['emergency'] == "suction_point":
                icon = styles.IconStyle(icon_href="icons/water.png")
            else:
                icon = styles.IconStyle(icon_href="icons/water.png")

        self.icons.append(icon.icon_href)
        self.styles = styles.Style(styles=[icon])
        return self.styles, self.description
示例#7
0
if True:
  snp = snap()
  snp.snap_segments()
  snp.statistics()

  # debug: placemarks from individual masurements in the cut_list
  # (those from which stat was calculated)
  if False:
   for pt in snp.cut_list: # every one for statistics
    flip_heading = 0
    if pt["directional_index"] < 0:
      flip_heading = 180;
    iri_avg = (pt["iri_left"] + pt["iri_right"]) / 2
    is0 = styles.IconStyle(ns, "id",
              color=("%08X" % color32(iri_avg/red_iri)),
              scale=0.7,
              heading=(180+pt["heading"]+flip_heading)%360,
              icon_href=arrow_icon_href)
    isty0 = styles.Style(styles = [is0])
    p0 = kml.Placemark(ns, 'id',
              name=("%.2f" % iri_avg),
              description=("L=%.2f mm/m\nR=%.2f mm/m\nL2=%.2f, R2=%.2f\ndir_ind=%d\nsnapstate=%d" %
                (pt["iri_left"], pt["iri_right"],
                 srvz[0] / (n_buf_points*1000), srvz[1] / (n_buf_points*1000),
                 pt["directional_index"], pt["snapstate"],
                )),
              styles=[isty0])
    p0.geometry = Point(pt["lonlat"])
    t.timestamp, dummy = t.parse_str(pt["timestamp"])
    p0.timeStamp = t.timestamp
    f2.append(p0)
示例#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()
示例#9
0
文件: color.py 项目: rsavoye/gosm
 def hotsprings(self, data):
     self.description = ""
     icon = styles.IconStyle(icon_href="icons/mx_natural_hot_spring.png")
     self.icons.append(icon.icon_href)
     self.styles = styles.Style(styles=[icon])
     return self.styles, self.description
示例#10
0
文件: color.py 项目: rsavoye/gosm
 def landingzones(self, data):
     self.description = ""
     icon = styles.IconStyle(icon_href="icons/heliport.png")
     self.icons.append(icon.icon_href)
     self.styles = styles.Style(styles=[icon])
     return self.styles, self.description
示例#11
0
文件: cli.py 项目: laserson/myspots
def write_kml(ctx, no_styles, default_invisible, hierarchical):
    from fastkml import kml, styles
    from shapely.geometry import Point
    import pandas as pd

    df1 = get_airtable_as_dataframe(ctx.obj["config"],
                                    "categories",
                                    view="Grid view")
    df2 = df1.drop("places", axis=1).explode("parent")
    # TODO: need to repeatedly self-join until reach the root
    df3 = pd.merge(
        df2,
        df2,
        how="left",
        left_on="parent",
        right_on="airtable_record_id",
        suffixes=("", "_join"),
    )
    categories_df = df3
    df1 = get_airtable_as_dataframe(ctx.obj["config"], "places")
    df2 = df1.explode("primary_category")
    df3 = pd.merge(
        df2,
        categories_df,
        how="left",
        left_on="primary_category",
        right_on="airtable_record_id",
    )
    places_df = df3

    ns = "{http://www.opengis.net/kml/2.2}"
    k = kml.KML()

    # construct all nodes in hierarchy of categories
    folders = {
        "_root":
        kml.Document(
            ns=ns,
            id="myspots-document",
            name="myspots-document",
            description="myspots-document",
        ),
        "_uncat":
        kml.Folder(ns=ns, id="_uncat", name="uncategorized"),
    }
    for tup in categories_df.itertuples(index=False):
        folders[tup.category] = kml.Folder(ns=ns,
                                           id=tup.category,
                                           name=tup.category)

    # append folders into each other; works bc of mutability
    k.append(folders["_root"])
    folders["_root"].append(folders["_uncat"])
    for tup in categories_df.itertuples(index=False):
        parent = "_root" if pd.isna(tup.category_join) else tup.category_join
        container = parent if hierarchical else "_root"
        folders[container].append(folders[tup.category])

    # add places to approp folders
    for tup in places_df.itertuples(index=False):
        category = "_uncat" if pd.isna(tup.category) else tup.category
        style = None if no_styles else f"#style-{category}"
        p = kml.Placemark(ns=ns, id=str(tup.id), name=tup.name, styleUrl=style)
        p.geometry = Point(tup.longitude, tup.latitude)
        folders[category].append(p)

    # set default visibility
    visibility = 0 if default_invisible else 1
    for container in folders.values():
        container.visibility = visibility
    folders["_root"].visibility = 1

    # define icon styles for placemarks
    if not no_styles:
        doc = folders["_root"]
        doc.append_style(
            styles.Style(
                ns=ns,
                id="style-_uncat",
                styles=[
                    styles.IconStyle(
                        icon_href=
                        "https://raw.githubusercontent.com/google/material-design-icons/master/maps/1x_web/ic_place_black_48dp.png"
                    )
                ],
            ))
        for tup in categories_df.itertuples(index=False):
            if pd.isna(tup.icon_href):
                continue
            style = styles.Style(
                ns=ns,
                id=f"style-{tup.category}",
                styles=[styles.IconStyle(icon_href=tup.icon_href)],
            )
            doc.append_style(style)

    print(k.to_string(prettyprint=True))