Esempio n. 1
0
    def test_utm_latlon_conversion(self):
        "check utm to latlon conversion of Dry Creek actually maps there"
        # bbox corners from upper left clockwise around
        east0 = 569029.6
        east1 = 569452.1
        north0 = 4842544.9
        north1 = 4842177.4

        utm_zone = 11
        utm_letter = 'T'

        latlons = utm2latlon(bsamp=east0, bline=north0, dsamp=east1-east0,
                             dline=north1-north0, nsamp=2, nline=2,
                             utm_zone=utm_zone, utm_letter=utm_letter)

        from utm import to_latlon
        ll0 = to_latlon(east0, north0, utm_zone, utm_letter)
        ll1 = to_latlon(east1, north0, utm_zone, utm_letter)
        ll2 = to_latlon(east1, north1, utm_zone, utm_letter)
        ll3 = to_latlon(east0, north1, utm_zone, utm_letter)

        assert (ll0 == latlons[0]).all
        assert (ll1 == latlons[1]).all
        assert (ll2 == latlons[2]).all
        assert (ll3 == latlons[3]).all
Esempio n. 2
0
def distance(UTM_ini, UTM_fin):
    """
    distance returns the calculated distance (in kms) between two points
    defined in the UTM coordinate system
    """

    UTM_ini_x = UTM_ini[0]
    UTM_ini_y = UTM_ini[1]
    UTM_ini_zone = UTM_ini[2]

    UTM_fin_x = UTM_fin[0]
    UTM_fin_y = UTM_fin[1]
    UTM_fin_zone = UTM_fin[2]

    [LAT_INI, LONG_INI] = utm.to_latlon(
        UTM_ini_x, UTM_ini_y, int(UTM_ini_zone[0:2]), str(UTM_ini_zone[3])
    )  # to get dd.dd from utm
    [LAT_FIN, LONG_FIN] = utm.to_latlon(
        UTM_fin_x, UTM_fin_y, int(UTM_fin_zone[0:2]), str(UTM_fin_zone[3])
    )  # to get dd.dd from utm

    point_i = (LAT_INI, LONG_INI)
    point_f = (LAT_FIN, LONG_FIN)

    distance = great_circle(
        point_i, point_f
    ).kilometers  # gives you a distance (in kms) between two coordinate in dd.dd

    return distance
Esempio n. 3
0
    def get_LOS_vector(self, locations):
        """
            calculate beta - the angle at earth center between reference point
            and satellite nadir
        """

        utmZone = self.location_UTM_zone
        refPoint = vmath.Vector3(self.ref[0], self.ref[1], 0)
        satAltitude = self.satellite_altitude
        satAzimuth = self.satellite_azimuth
        satIncidence = self.ref_incidence
        earthRadius = self.local_earth_radius

        DEG2RAD = np.pi / 180.
        alpha = satIncidence * DEG2RAD
        beta = (earthRadius / (satAltitude + earthRadius)) * np.sin(alpha)
        beta = alpha - np.arcsin(beta)
        beta = beta / DEG2RAD

        # calculate angular separation of (x,y) from satellite track passing
        # through (origx, origy) with azimuth satAzimuth

        # Long lat **NOT** lat long
        origy, origx = utm.to_latlon(
            refPoint.x, refPoint.y, np.abs(utmZone), northern=utmZone > 0
        )

        xy = np.array([
            utm.to_latlon(u[0], u[1], np.abs(utmZone), northern=utmZone > 0)
            for u in locations
        ])
        y = xy[:, 0]
        x = xy[:, 1]

        angdist = self._ang_to_gc(x, y, origx, origy, satAzimuth)

        # calculate beta2, the angle at earth center between roaming point and
        # satellite nadir track, assuming right-looking satellite

        beta2 = beta - angdist
        beta2 = beta2 * DEG2RAD

        # calculate alpha2, the new incidence angle

        alpha2 = np.sin(beta2) / (
            np.cos(beta2) - (earthRadius / (earthRadius + satAltitude))
        )
        alpha2 = np.arctan(alpha2)
        alpha2 = alpha2 / DEG2RAD

        # calculate pointing vector

        satIncidence = 90 - alpha2
        satAzimuth = 360 - satAzimuth

        los_x = -np.cos(satAzimuth * DEG2RAD) * np.cos(satIncidence * DEG2RAD)
        los_y = -np.sin(satAzimuth * DEG2RAD) * np.cos(satIncidence * DEG2RAD)
        los_z = np.sin(satIncidence * DEG2RAD)

        return vmath.Vector3(los_x, los_y, los_z)
Esempio n. 4
0
File: track.py Progetto: QRAAT/QRAAT
  def export_kml(self, name, tx_id):
    # TODO I've changed some stuff ... make sure this output is still sensible. 
  
    # E.g.: https://developers.google.com/kml/documentation/kmlreference#gxtrack 
    # TODO The file is way longer than it needs to be, since I wanted to display
    # the coordinates and datetime in the tooltip that appears in Google Earth.
    # Perhaps what we want is not a gx:track, but something fucnctionally 
    # similar.

    # TODO Add northing, easting to output.
    try:
      import utm
    except ImportError:
      print "function export_kml() requires \"utm\" library, please install"
      raise

    fd = open('%s_track.kml' % name, 'w')
    fd.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fd.write('<kml xmlns="http://www.opengis.net/kml/2.2"\n')
    fd.write(' xmlns:gx="http://www.google.com/kml/ext/2.2">\n')
    fd.write('<Folder>\n')
    fd.write('  <Placemark>\n')
    fd.write('    <name>%s (deploymentID=%d)</name>\n' % (name, tx_id))
    fd.write('    <gx:Track>\n')
    for (pos_id, dep_id, t, easting, northing, utm_number, utm_letter, ll, activity) in self.table: 
      tm = time.gmtime(t)
      t = '%04d-%02d-%02dT%02d:%02d:%02dZ' % (tm.tm_year, tm.tm_mon, tm.tm_mday,
                                              tm.tm_hour, tm.tm_min, tm.tm_sec)
      fd.write('      <when>%s</when>\n' % t)
    for (pos_id, dep_id, t, easting, northing, utm_number, utm_letter, ll, activity) in self.table: 
      (lat, lon) = utm.to_latlon(easting, northing, utm_number, utm_letter) 
      fd.write('      <gx:coord>%f %f 0</gx:coord>\n' % (lon, lat))
    fd.write('      <ExtendedData>\n')
    fd.write('        <SchemaData schemaUrl="#schema">\n')
    fd.write('          <gx:SimpleArrayData name="Time">\n')
    for (pos_id, dep_id, t, easting, northing, utm_number, utm_letter, ll, activity) in self.table: 
      tm = time.gmtime(t)
      t = '%04d-%02d-%02d %02d:%02d:%02d' % (tm.tm_year, tm.tm_mon, tm.tm_mday,
                                              tm.tm_hour, tm.tm_min, tm.tm_sec)
      fd.write('          <gx:value>%s</gx:value>\n' % t)
    fd.write('          </gx:SimpleArrayData>\n')
    fd.write('          <gx:SimpleArrayData name="(lat, long)">\n')
    for (pos_id, dep_id, t, easting, northing, utm_number, utm_letter, ll, activity) in self.table: 
      (lat, lon) = utm.to_latlon(easting, northing, utm_number, utm_letter) 
      fd.write('          <gx:value>%fN, %fW</gx:value>\n' % (lat, lon))
    fd.write('          </gx:SimpleArrayData>\n')
    fd.write('          <gx:SimpleArrayData name="positionID">\n')
    for (pos_id, dep_id, t, easting, northing, utm_number, utm_letter, ll, activity) in self.table: 
      tm = time.gmtime(t)
      t = '%04d-%02d-%02d %02d:%02d:%02d' % (tm.tm_year, tm.tm_mon, tm.tm_mday,
                                              tm.tm_hour, tm.tm_min, tm.tm_sec)
      fd.write('          <gx:value>%d</gx:value>\n' % pos_id)
    fd.write('          </gx:SimpleArrayData>\n')
    fd.write('        </SchemaData>\n')
    fd.write('      </ExtendedData>\n')
    fd.write('    </gx:Track>\n')
    fd.write('  </Placemark>\n')
    fd.write('</Folder>\n')
    fd.write('</kml>')
    fd.close() 
Esempio n. 5
0
File: gis.py Progetto: renj/TrajMap
def to_gps(x = 0.0, y = 0.0):
    #print x, y, type(x), type(y)
    if x < 400000:
        lat, lon = utm.to_latlon(x, y, 51,'R')
        return lon, lat
    elif x > 400000:
        lat, lon = utm.to_latlon(x, y, 16,'T')
        return lon, lat
Esempio n. 6
0
    def test_to_latlon(self):
        '''to_latlon should give known result with known input'''
        for latlon, utm, utm_kw in self.known_values:
            result = UTM.to_latlon(*utm)
            self.assert_latlon_equal(latlon, result)

            result = UTM.to_latlon(*utm[0:3], **utm_kw)
            self.assert_latlon_equal(latlon, result)
Esempio n. 7
0
    def test_to_latlon_range_checks(self):
        '''to_latlon should fail with out-of-bounds input'''
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 0, 5000000, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 99999, 5000000, 32, 'U')
        for i in range(100000, 999999, 1000):
            UTM.to_latlon(i, 5000000, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 1000000, 5000000, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 100000000000, 5000000, 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, -100000, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, -1, 32, 'U')
        for i in range(10, 10000000, 1000):
            UTM.to_latlon(500000, i, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 10000001, 32, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 50000000, 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 0, 'U')
        for i in range(1, 60):
            UTM.to_latlon(500000, 5000000, i, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 61, 'U')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 1000, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'A')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'B')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'I')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'O')
        for i in range(ord('C'), ord('X')):
            i = chr(i)
            if i != 'I' and i != 'O':
                UTM.to_latlon(500000, 5000000, 32, i)
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'Y')
        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, 500000, 5000000, 32, 'Z')
Esempio n. 8
0
 def rectilinear(self, nx, ny):
     """
     function that generates a rectilinear grid
     """
     #### Step 1) define a regular grid ####
     #NW = (29.017842, -95.174746)
     NW = (29.036487, -95.131658)
     #NE = (29.459124, -94.413252)
     NE = (29.439981, -94.465266)
     #SW = (28.777523, -94.979306)
     SW = (28.807300, -95.005893)
     
     #### Calculate the length in x- and y- direction ####
     Lx = self.distance_on_unit_sphere(NW[0], NW[1], NE[0], NE[1])
     Ly = self.distance_on_unit_sphere(NW[0], NW[1], SW[0], SW[1])
     
     new_NW = utm.from_latlon(NW[0], NW[1])[0:2]
     #new_SW = (new_NW[0]-Ly, new_NW[1])
     #new_NE = (new_NW[0], new_NW[1]+Lx)
     
     y = np.linspace(new_NW[1]-Ly, new_NW[1], ny)
     x = np.linspace(new_NW[0], new_NW[0]+Lx, nx)
     
     xv, yv = np.meshgrid(x, y)        
     #origin = (xv[0,-1], yv[0,-1])
     origin = new_NW
     
     tem_xv = xv - origin[0]
     tem_yv = yv - origin[1]
     
     #### Step 2) rotate the grid from an angle ####                    
     def rotate(yv, xv, theta):
         """Rotates the given polygon which consists of corners represented as (x,y),
         around the ORIGIN, clock-wise, theta degrees"""
         theta = math.radians(theta)
         out_yv = np.zeros_like(yv)
         out_xv = np.zeros_like(xv)
         (nx, ny) = xv.shape
         for i in range(nx):
             for j in range(ny):
                 out_yv[i,j] = yv[i,j]*math.cos(theta)-xv[i,j]*math.sin(theta)
                 out_xv[i,j] = yv[i,j]*math.sin(theta)+xv[i,j]*math.cos(theta)
         
         return out_yv, out_xv
         
     tem_yv, tem_xv = rotate(tem_yv, tem_xv, -35)
     
     new_xv = tem_xv + origin[0]   #lon 
     new_yv = tem_yv + origin[1]   #lat
     
     lon = np.zeros_like(new_xv)
     lat = np.zeros_like(new_yv)
     #pdb.set_trace()
     for i in range(ny):
         for j in range(nx):
             (lat[i,j], lon[i,j]) = utm.to_latlon(new_xv[i,j], new_yv[i,j],15,'U')[0:2]
     
     dx = Lx / nx
     dy = Ly / ny                  
     return lon, lat, dx, dy   
Esempio n. 9
0
def utm_to_latlong(input_data_file=None, output_data_file=None, log_file=None, log_level=DEFAULT_LOG_LEVEL):
    """Converts UTM coordinates into latitude/longitude.
    assumes rows are easting, northing, zone number, either 'N' for northern
    hemisphere or 'S' for southern hemisphere
    """
    logger = logger_message(__name__, log_file, log_level)

    # Check required input and output data file names were given.
    assert input_data_file is not None, 'An input CSV file with columns of values.'
    assert output_data_file is not None, 'An output CSV file to write new values.'

    _in = open(input_data_file, 'r')
    try:
        _out = open(output_data_file, 'w')
        try:
            data = csv.reader(_in)
            output = csv.writer(_out)
            for row_ind, row in enumerate(data):
                east = float(row[0])
                north = float(row[1])
                zone = int(row[2])

                latlong = utm.to_latlon(east, north, zone, northern=('N' == row[3]))
                logger.info('Changed row {} from: {}  to: {}'.format(row_ind,
                                                                     (row[0], row[1]), latlong))

                output.writerow(latlong)
        finally:
            _out.close()
    finally:
        _in.close()
Esempio n. 10
0
  def insert_db(self, db_con, dep_id, bearing_ids, zone):
    ''' Insert position and bearings into the database. 
    
      Inputs: 
        
        db_con, dep_id, zone

        bearing_ids -- bearingIDs (serial identifiers in the database) of the bearings
                       corresponding to bearing data. These are used for provenance 
                       in the database. 
    ''' 
    if self.p is None: 
      return None
    number, letter = zone
    lat, lon = utm.to_latlon(self.p.imag, self.p.real, number, letter)
    cur = db_con.cursor()
    cur.execute('''INSERT INTO position
                     (deploymentID, timestamp, latitude, longitude, easting, northing, 
                      utm_zone_number, utm_zone_letter, likelihood, 
                      activity, number_est_used)
                   VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''',
                     (dep_id, self.t, round(lat,6), round(lon,6),
                      self.p.imag, self.p.real, number, letter, 
                      self.likelihood, self.activity,
                      self.num_est))
    pos_id = cur.lastrowid
    handle_provenance_insertion(cur, {'bearing': tuple(bearing_ids)}, 
                                     {'position' : (pos_id,)})
    return pos_id
Esempio n. 11
0
def get_data(path='data/Historical Marker_20150521_145030_254.csv'):
    with open(path, 'r') as fp:
        reader = csv.DictReader(fp)
        for row in reader:
            text = row['markertext']
            years = find_years(text)
            row['address'] = row['address'].strip()

            # add our own data
            row['years'] = years
            row['classifications'] = Classifier(years, text=text).classify()
            try:
                lat, lon = utm.to_latlon(
                    int(row['utm_east']),
                    int(row['utm_north']),
                    int(row['utm_zone']),
                    northern=True,
                )
                row['location'] = {
                    "lat": lat,
                    "lon": lon,
                }
            except ValueError:
                # log warn missing
                pass
            yield row
Esempio n. 12
0
def sync_gis():
  request_cookie = requests.get(app.config['GIS_URL_COOKIE'])
  request_data = requests.get(app.config['GIS_URL_DATA'], cookies=request_cookie.cookies)
  data = request_data.json()['features']
  for dataset in data:
    if Tree.query.filter_by(external_id=dataset['attributes']['OBJECTID']).count() == 0:
      print "Add new Dataset with external ID %s" % dataset['attributes']['OBJECTID']
      new_tree = Tree()
      new_tree.external_id = dataset['attributes']['OBJECTID']
      lat_lng = utm.to_latlon(dataset['geometry']['x'], dataset['geometry']['y'], 32, 'U')
      new_tree.lat = lat_lng[0]
      new_tree.lng = lat_lng[1]
      if len(dataset['attributes']['ADRESSE'].strip()):
        new_tree.address = dataset['attributes']['ADRESSE']
      if len(dataset['attributes'][u'GEH\xf6lZFL\xe4c'].strip()):
        new_tree.tree_type_old = dataset['attributes'][u'GEH\xf6lZFL\xe4c']
      if len(dataset['attributes'][u'F\xe4lLGRUND'].strip()):
        new_tree.chop_reason = dataset['attributes'][u'F\xe4lLGRUND']
      descr = ''
      if len(dataset['attributes'][u'F\xe4lLUNG'].strip()):
        descr += u'Zeitpunkt der Fällung: ' + dataset['attributes'][u'F\xe4lLUNG'].strip()
      new_tree.descr = descr
      new_tree.created_at = datetime.datetime.now()
      new_tree.updated_at = datetime.datetime.now()
      new_tree.author = 'Stadt Bochum'
      new_tree.email = '*****@*****.**'
      new_tree.city = 'Bochum'
      new_tree.public = 1
      new_tree.postalcode = ''
      new_tree.type = 4
      new_tree.source = 'Stadt Bochum'
      db.session.add(new_tree)
      db.session.commit()
Esempio n. 13
0
def local_to_global(origin, x, y, theta=0.0):
    """
    Converts from a local frame in meters into a global frame in lon/lat.
    Note that heading is in degrees!

    @param origin (lon, lat, heading)
    @param point shapely.geometry.Point() in local frame
    @return (longitude, latitude, heading) in WGS84
    """
    # Create local transformation frame.
    import utm
    ox, oy, zone, hemi = utm.from_latlon(origin[1], origin[0])
    o_theta = (90 - origin[2]) * (math.pi/180.0)

    # Translate and rotate point to origin.
    point = shapely.geometry.Point(x, y)
    point = shapely.affinity.rotate(point, o_theta,
                                    origin=ORIGIN, use_radians=True)
    point = shapely.affinity.translate(point, ox, oy)
    p_theta = theta + o_theta
    heading = 90 - (p_theta * 180.0/math.pi)

    # Return transformed point.
    lat, lon = utm.to_latlon(point.x, point.y, zone, hemi)
    return lon, lat, heading
Esempio n. 14
0
File: track.py Progetto: QRAAT/QRAAT
  def export_kml(self, name, dep_id):

    fd = open('%s_pos.kml' % name, 'w')
    fd.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fd.write('<kml xmlns="http://www.opengis.net/kml/2.2"\n')
    fd.write(' xmlns:gx="http://www.google.com/kml/ext/2.2">\n')
    fd.write('<Folder>\n')
    fd.write('  <Placemark>\n')
    fd.write('  <MultiGeometry>\n')
    fd.write('    <name>%s (deploymentID=%d) position cloud</name>\n' % (name, dep_id))
    for row in self.table:
      (P, t, ll, pos_id) = (np.complex(row[0], row[1]), 
                            float(row[2]), 
                            float(row[3]), 
                            int(row[4]))
      tm = time.gmtime(t)
      t = '%04d-%02d-%02d %02d:%02d:%02d' % (tm.tm_year, tm.tm_mon, tm.tm_mday,
                                              tm.tm_hour, tm.tm_min, tm.tm_sec)
      (lat, lon) = utm.to_latlon(P.imag, P.real, self.zone, self.letter) 
      fd.write('    <Point id="%d">\n' % pos_id)
      fd.write('      <coordinates>%f,%f,0</coordinates>\n' % (lon, lat))
      fd.write('    </Point>\n')
    fd.write('  </MultiGeometry>\n')
    fd.write('  </Placemark>\n')
    fd.write('</Folder>\n')
    fd.write('</kml>')
    fd.close() 
Esempio n. 15
0
def ChangeXYView(request):
    if request.method == "POST":
        form = ChangeXYForm(request.POST)
        if form.is_valid():
            obs = Occurrence.objects.get(pk=request.POST["DB_id"])
            coordinates = utm.to_latlon(int(request.POST["new_easting"]), int(request.POST["new_northing"]), 37, "N")
            pnt = GEOSGeometry("POINT (" + str(coordinates[1]) + " " + str(coordinates[0]) + ")", 4326)  # WKT
            obs.geom = pnt
            obs.save()
            messages.add_message(request, messages.INFO, 'Successfully Updated Coordinates For %s.' % obs.catalog_number)
            return redirect("/admin/mlp/occurrence")
    else:
        selected = list(request.GET.get("ids", "").split(","))
        if len(selected) > 1:
            messages.error(request, "You can't change the coordinates of multiple points at once.")
            return redirect("/admin/mlp/occurrence")
        selected_object = Occurrence.objects.get(pk=int(selected[0]))
        initial_data = {"DB_id": selected_object.id,
                        "barcode": selected_object.barcode,
                        "old_easting": selected_object.easting,
                        "old_northing": selected_object.northing,
                        "item_scientific_name": selected_object.item_scientific_name,
                        "item_description": selected_object.item_description
                        }
        the_form = ChangeXYForm(initial=initial_data)
        return render_to_response('projects/changeXY.html', {"theForm": the_form}, RequestContext(request))
Esempio n. 16
0
    def ProcessLocalization(self, msg):
        """Process Localization, stat mileages and save driving path."""
        localization = LocalizationEstimate()
        localization.ParseFromString(msg)
        timestamp = localization.header.timestamp_sec
        cur_pos = localization.pose.position

        # Stat mileages.
        if (self._last_position is not None and
            self._current_driving_mode is not None):
            driving_mode = Chassis.DrivingMode.Name(self._current_driving_mode)
            meters = utm_distance_meters(self._last_position, cur_pos)
            if driving_mode in self.record.stat.mileages:
                self.record.stat.mileages[driving_mode] += meters
            else:
                self.record.stat.mileages[driving_mode] = meters

        # Sample driving path.
        G = gflags.FLAGS
        if (self._last_position_sampled is None or
            (timestamp - self._last_position_sampled_time >
                 G.pos_sample_min_duration and
             utm_distance_meters(self._last_position_sampled, cur_pos) >
                 G.pos_sample_min_distance)):
            self._last_position_sampled = cur_pos
            self._last_position_sampled_time = timestamp
            lat, lon = utm.to_latlon(cur_pos.x, cur_pos.y,
                                     G.utm_zone_id, G.utm_zone_letter)
            self.record.stat.driving_path.add(lat=lat, lon=lon)
        # Update position.
        self._last_position = cur_pos
def start_simulator_spin():

    rospy.init_node("Controller_Tester", anonymous=True)
    simulator_pub = rospy.Publisher('Pose', Pose, queue_size=10)
    c_tester = ControllerTester()
    command_listener = rospy.Subscriber("Command", Command, c_tester.command_callback)

    #initialize()


    while not rospy.is_shutdown():
        #apply the model
        #use np.dot(a, b) for matrix product of two 2d-lists a and b
        #print(model)
        c_tester.x = np.dot(c_tester.model, c_tester.x)

        #publish a new pose message using simulator_pub
        simulated_pose = Pose()

        #lat_long is a 2-tuple
        #for syntax of the utm package see python package index
        #The syntax is utm.to_latlon(EASTING, NORTHING, ZONE NUMBER, ZONE LETTER).
        #The return has the form (LATITUDE, LONGITUDE).
        
        lat_long = utm.to_latlon(c_tester.x[0][0], c_tester.x[1][0], c_tester.utm_zone_number, c_tester.utm_zone_letter)
        simulated_pose.latitude_deg = lat_long[0]
        simulated_pose.longitude_deg = lat_long[1]
        simulated_pose.heading_rad = c_tester.x[3][0]

        simulator_pub.publish(simulated_pose)
        c_tester.updateModel(c_tester.x)
        #rospy.spin()

        c_tester.rate.sleep()
def derive_taz_attributes(cur, list_taz):
    
    description_taz=[]
    for taz_id in list_taz:
        
        s='select ST_AsText(ST_Centroid(TAZ.geom)) from taz_boundary_scag_2009 TAZ where TAZ.gid = '+str(taz_id)+';'
        cur.execute(s)
        rows=cur.fetchall()
        for row in rows:
            pos_centroid_UTM = (str(row[0]))
            pos_centroid_UTM = pos_centroid_UTM[6:len(pos_centroid_UTM)-1]
            pos_centroid_UTM = pos_centroid_UTM.split()
            pos_centroid_UTM = map(float, pos_centroid_UTM)
            lat_centroid, lng_centroid = utm.to_latlon(pos_centroid_UTM[0], pos_centroid_UTM[1] , 11, 'N') #The shapefiles are in the UTM "11N" coordinates
    
        if is_in_LA_Box(lat_centroid, lng_centroid):
            s='select count(*) from taz_boundary_scag_2009 TAZ, la_network_nodes_v2 nodes where TAZ.gid = '+str(taz_id)+' AND ST_Contains(TAZ.geom, nodes.geom);'
            cur.execute(s)
            rows=cur.fetchall()
            for row in rows:
                nb_nodes_in_taz = int(str(row[0]))
            s='select TAZ.area_ from taz_boundary_scag_2009 TAZ where TAZ.gid = '+str(taz_id)+';'
            cur.execute(s)
            rows=cur.fetchall()
            for row in rows:
                area_taz = float(str(row[0]))
        
            description_taz.append([taz_id, lat_centroid, lng_centroid, nb_nodes_in_taz, area_taz])
            
    return description_taz
Esempio n. 19
0
def calc_list( l_points, EP, func_fretch ):
    if not calc_list_precheck(l_points, func_fretch):
        return None
    pr, level = calc_list_core(l_points, EP, func_fretch)
    if pr:
        latitude, longitude = utm.to_latlon(pr.x, pr.y, pr.zone, pr.mark)
        return latitude, longitude, pr.r, level
    return None
Esempio n. 20
0
    def eval(self, values, X):
        if self.tnci_time != self.t:    
            self.tnci.set_time(self.t)
            self.tnci_time = self.t

        latlon = utm.to_latlon(X[0], X[1], utm_zone, utm_band)
        # OTPS has lon, lat coordinates!
        values[0] = self.tnci.get_val((latlon[1], latlon[0]), allow_extrapolation=True)
    def test_to_latlon_numpy(self):
        if not use_numpy:
            return
        result = UTM.to_latlon(np.array([166021.44317933032,
                                         277707.83075574087,
                                         544268.12794623]),
                               np.array([0.0,
                                         331796.29167519242,
                                         663220.7198366751]),
                               31, northern=True)
        self.assert_latlon_equal((np.array([0.0, 3.0, 6.0]),
                                  np.array([0.0, 1.0, 3.4])),
                                 result)

        for latlon, utm, utm_kw in self.known_values:
            utm = [np.array([x]) for x in utm[:2]] + list(utm[2:])
            result = UTM.to_latlon(*utm)
            self.assert_latlon_equal(latlon, result)
def add_node_attribute(G, burr_dict):

	for node in G.nodes():
		if burr_dict[node][0] > 0 and  burr_dict[node][1] >0:
			latitude, longitude = utm.to_latlon(burr_dict[node][0], burr_dict[node][1], 11, northern = True)
			G.node[node]["Latitude"] = latitude
			G.node[node]["Longitude"] = longitude
		else: print ("node with missing location"), node
	return G
Esempio n. 23
0
def convert_lon(context):
    if context:
        utm_e = context.current_parameters.get('coord_utm_e')
        utm_n = context.current_parameters.get('coord_utm_n')
        utm_zone_n = context.current_parameters.get('coord_utm_zone_n')
        utm_zone_letter = context.current_parameters.get('coord_utm_zone_letter')
        if utm_e and utm_n:
            lat, lon = utm.to_latlon(utm_e, utm_n, utm_zone_n, utm_zone_letter)
            return lon
Esempio n. 24
0
  def convert_to_lonlat(self,zone_number,northern=False):
    import utm
    lon=np.zeros(self.x.size,dtype=self.x.dtype)
    lat=np.zeros(self.x.size,dtype=self.x.dtype)
    for i in range(self.x.size):
      lat[i],lon[i]=utm.to_latlon(self.x[i], self.y[i], zone_number=zone_number, northern=northern)

    self.lon=lon
    self.lat=lat
Esempio n. 25
0
def pix_2_latlon(gt, px, py, zone_number, northern):
    x = px * gt[1] + gt[0]
    y = py * gt[5] + gt[3]

    if zone_number is not None:
        lat, lon = utm.to_latlon(x, y, zone_number, northern=northern)
    else:
        lat, lon = y, x

    return lon, lat, 0
Esempio n. 26
0
def coonvert():
    for tree in tqdm.tqdm(Tree.query(), total=Tree.query().count()):
        utm_e = tree.coord_utm_e
        utm_n = tree.coord_utm_n
        if utm_e and utm_n:
            if 100000 < utm_e < 999999 and utm_n:
                lat, lon = utm.to_latlon(utm_e, utm_n, 19, northern=False)
                tree.coord_lat = lat
                tree.coord_lon = lon
                tree.save()
Esempio n. 27
0
def LatLngConvert(UTMpoints):
    import utm

    points = []

    pt = utm.to_latlon([UTMpoints[1], UTMpoints[0]])
    spt = Point(pt[1], pt[0])
    points.append(spt)
    
    return points
Esempio n. 28
0
 def set_position(self, true_position):
     """
     Set True Position and update LAT, LON, ALT
     """
     lat, lon = utm.to_latlon(
         self._initial_utm[0] + true_position[0],
         self._initial_utm[1] + true_position[1],
         self._initial_utm[2],
         self._initial_utm[3])
     self.set_true_value(numpy.array([lat, lon, true_position[2]]))
    def generate_ground_truth_message(self):
        (x, y) = (self.x[0], self.x[1])
        (lat, lon) = utm.to_latlon(x, y, self.utm_zone, self.utm_letter)

        msg = Pose()
        msg.latitude_deg = lat
        msg.longitude_deg = lon
        msg.heading_rad = self.x[3]
        
        return msg
Esempio n. 30
0
    def eval(self, values, X):
        global tnci_time
        if tnci_time != self.t:
            print0("Setting Tidal forcing time to %f " % self.t)
            self.tnci.set_time(self.t)
            tnci_time = self.t

        latlon = utm.to_latlon(X[0], X[1], self.utm_zone, self.utm_band)
        # OTPS has lon, lat coordinates!
        values[0] = self.tnci.get_val((latlon[1], latlon[0]), allow_extrapolation=True)
Esempio n. 31
0
    mymap = tiff.imread(result_path + map_tif)
    bin_mask_array = postprocess_masks(mymat, mymat.shape)
    this_slice = result_tif[:-11]
    mask_array_to_poly_json(bin_mask_array,
                            result_path,
                            this_slice,
                            reqd_class_label=['Trees', 'Crops', 'Water'])
    print("Written Polygons from binary mask into json for {}".format(
        result_tif))
    print("Completed {} out of {}".format(current_file_count + 1,
                                          total_files_count))

# In[4]:

x1, y1 = 358011.19999999995, 3038709.5999999996
x2, y2 = utm.to_latlon(x1, y1, 17, 'N')
print(x2, y2)

# ## Define functions and path

# In[5]:

result_path = '/home/ekbana/computer_vision/satellite-image/Planet.com/Planet_Data_Sliced/tif/result/'
post_proc_temp_path = result_path + 'Post-Process-Temp/'
result_filenames = os.listdir(result_path)
result_filenames = [
    file for file in result_filenames if file[-10:] == 'polys.json'
]

meta_path = '/home/ekbana/computer_vision/satellite-image/Planet.com/Planet-Data/'
Esempio n. 32
0
def generate_csv(x_resolution, y_resolution, x1, y1, x2, y3, GSD, zone_no,
                 zone_name, pixel_to_km):
    import utm
    # print x_resolution, y_resolution, x1, y1, x2, y3,  GSD, zone_no, zone_name
    centres = mesh(
        x_resolution, y_resolution, x1, y1, x2, y3, GSD,
        pixel_to_km)  # generates a matrix of coordinates for the path
    # print centres, 'centres'
    line_path = pathline(
        centres)  # converts the matrix into a 1d list, for the final path
    name_int = 0
    centre_lat, centre_lon = utm.to_latlon((x1 + x2) / 2, (y1 + y3) / 2,
                                           zone_no, zone_name)
    while (1):
        try:
            temp_file = KMLFile.objects.get(
                name=str(name_int))  # Files are named using plain integers
            name_int += 1
            # print name_int
            continue
        except:
            break
    path = os.path.join(settings.MEDIA_ROOT, 'csv',
                        'csv' + str(name_int) + '.csv')
    # print path
    proj = Proj(proj='utm', zone=zone_no,
                ellps='WGS84')  # Proj instance for utm to lat long conversions
    elevation_dir = os.path.join(settings.MEDIA_ROOT, 'hgt')
    heightmap = SrtmHeightMap(centre_lat, centre_lon, x_resolution,
                              y_resolution, proj, pixel_to_km, GSD, x1, y1, x2,
                              y3, elevation_dir)
    csvfile = open(str(path), "w+b")
    filewriter = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
    filewriter.writerow(['X', 'Y', 'Elevation'])
    tiles = {}
    for i in range(0, len(line_path)):
        lat, lng = utm.to_latlon((line_path[i]['X']), (line_path[i]['Y']),
                                 zone_no, zone_name)
        tile_key = SrtmHeightMap._tileKey(lat, lng)
        if not tiles.has_key(tile_key):
            try:
                tiles[tile_key] = SrtmHeightMap._loadTile(
                    heightmap.data_dir, lat, lng)
            except:
                return HttpResponse(
                    "HGT data does not exist. Please copy %s file in the media/hgt folder."
                    % (SrtmHeightMap._tileKey(lat, lng)))
            # print 'Loaded tile', tile_key
        v = tiles[tile_key].getAltitudeFromLatLon(lat, lng)
        # print line_path[i]['X'], line_path[i]['Y']
        filewriter.writerow(
            [str(line_path[i]['X']),
             str(line_path[i]['Y']), v]
        )  # , str(get_elevation(utm.to_latlon((line_path[i]['X']), (line_path[i]['Y']), zone_no, zone_name)))
    csvfile.close()
    # t = datetime.now()
    # print t
    dev = get_projection_north_deviation(heightmap.proj, heightmap.lat,
                                         heightmap.lng)
    # observer at the centre of the point of interest
    gatech = ephem.Observer()
    gatech.lon, gatech.lat = '%.2f' % heightmap.lng, '%.2f' % heightmap.lat  # pyephem takes input as strings and not float!!!
    sun = ephem.Sun()
    # print gatech.date, heightmap.lng, heightmap.lat   # date by default is UTC which should be used as other calculations are made accordingly
    # print gatech.lon, gatech.lat
    sun.compute(gatech)
    # print("%s %s" % (sun.alt, sun.az))
    azimuth = sun.az
    altitude = sun.alt
    sunpos = {
        'azimuth': degree_to_rad(azimuth),
        'altitude': degree_to_rad(altitude)
    }
    sun_x = -sin(sunpos['azimuth'] - dev) * cos(sunpos['altitude'])
    sun_y = -cos(sunpos['azimuth'] - dev) * cos(sunpos['altitude'])
    sun_z = sin(sunpos['altitude'])
    shadowmap = ShadowMap(centre_lat, centre_lon, x_resolution, y_resolution,
                          heightmap.size_x, heightmap.size_y, heightmap.proj,
                          pixel_to_km, GSD, x1, y1, x2, y3, sun_x, sun_y,
                          sun_z, heightmap, 1.5)
    render_matrix = shadowmap.render()
    # 0 means shadow, 1 means lit
    print render_matrix
    # print shadowmap.size_y, shadowmap.size_x
    #print render_matrix
    s = ephem.Sun()
    s.compute()
    o = ephem.Observer()
    o.lat = '%0.2f' % heightmap.lat
    o.lon = '%0.2f' % heightmap.lng
    # print o.lat, o.lon
    # print 'O', o.date
    # print render_matrix
    render_matrix = rever(render_matrix,
                          shadowmap)  # Single lined path for render_matrix
    # print o.next_rising(s), o.previous_setting(s)
    next_rising = ephem_to_datetime(o.next_rising(s))
    previous_setting = ephem_to_datetime(o.previous_setting(s))
    current_time = ephem_to_datetime(o.date)
    # print previous_setting, current_time, next_rising
    # Check if the path isn't plotted after sunset or before sunrise
    if next_rising.day == previous_setting.day:  # Sun is set
        for i in xrange(0, len(render_matrix)):
            render_matrix[i] = 0
    kml_file = KMLFile()
    kml_file.name = str(name_int)
    # f = open(path)
    # kml_file.csv_file.save(str(kml_file.name)+'.csv', File(f))
    # kml_file.file_path.name = kml_path
    kml_file.save()
    kml_file.zone_name = zone_name
    kml_file.zone_no = zone_no
    kml_file.save()
    # print len(centres) == len(render_matrix)
    generate_kml(path, kml_file, render_matrix)
    i = 0
    new_path = os.path.join(settings.MEDIA_ROOT, 'csv',
                            'csv_final' + str(name_int) + '.csv')
    with open(path, 'rb') as inp, open(str(new_path), 'wb') as out:
        writer = csv.writer(out)
        count = 0
        for row in csv.reader(inp):
            if render_matrix[i] != 0:
                writer.writerow(row)
                count += 1
        if count == 0:
            writer.writerow(['X', 'Y', 'Elevation'])
        i += 1
    f = open(new_path)
    kml_file.csv_file.save(str(kml_file.name) + '.csv', File(f))
    os.remove(path)
    # print heightmap.heights
    # print render_matrix
    # print len(render_matrix) == shadowmap.size_x * shadowmap.size_y
    return kml_file
Esempio n. 33
0
    '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">'
)
file.write('<Document>\n')

row_count = ws.max_row
for i in range(2, row_count - 1):
    cP1 = Coordenadas(sheet_ranges['A' + str(i)].value,
                      sheet_ranges['B' + str(i)].value,
                      sheet_ranges['C' + str(i)].value,
                      sheet_ranges['D' + str(i)].value)
    print('{0}, {1}, {2}, {3}'.format(cP1.nome, cP1.pX, cP1.pY, cP1.pZ))
    file.write('<Placemark>')
    file.write('<name>' + cP1.nome + '</name>')
    file.write('<Point>')
    if (tipoCoord == 1):
        zoneNumber = int(input("Digite o numero da zona: "))
        zoneLetter = input("Digite a letra da zona: ")
        uLatLon = utm.to_latlon(cP1.pX, cP1.pY, zoneNumber, zoneLetter)
        file.write('<coordinates> {1}, {0}, {2}'.format(
            uLatLon[0], uLatLon[1], cP1.pZ) + '</coordinates>')
    else:
        file.write(
            '<coordinates> {0}, {1}, {2}'.format(cP1.pX, cP1.pY, cP1.pZ) +
            '</coordinates>')
        file.write('</Point>')
        file.write('</Placemark>')

file.write('</Document>\n')
file.write('</kml>')
file.close()
Esempio n. 34
0
def getUTMs(row):
    tup = utm.to_latlon(row.ix[0], row.ix[1], 10, 'U')
    return pd.Series(tup[:2])
Esempio n. 35
0
def pixel_to_latlon(trans, row, col, zone_num, zone_let):
    px, py = imagexy2geo(trans, row, col)
    lat, lon = utm.to_latlon(px, py, zone_num, zone_let)
    return lat, lon
Esempio n. 36
0
# time = 24 #seconds or min?

# Integrate on the x direction
velocityX = cumtrapz(accelerationX)
# Integrate on the x direction
velocityY = cumtrapz(accelerationY)

# Integrate velocity to get x position
positionX = cumtrapz(velocityX)
# Integrate velocity to get y position
positionY = cumtrapz(velocityY)

# Insert initial position
positionX = np.concatenate([[x0], positionX])
positionY = np.concatenate([[y0], positionY])

# Using cumulative sum instead of for
positionX = np.cumsum(positionX)
positionY = np.cumsum(positionY)

# Gets latitude and longitude of an object in the fluid waste
lat, lon = utm.to_latlon(
    positionX[-1], positionY[-1], utmZoneNumber, utmZoneLetter)

print(
    '''Final position:
        lat: %f
        lon: %f
    ''' % (lat, lon)
)
Esempio n. 37
0
    def extract(self):
        msp = self.doc.modelspace()
        poles = []
        labels = []
        # iterate through all drawing entities
        for e in msp:
            # grab any labels
            if e.dxftype() == 'MTEXT':
                # process the label text
                new_label = {
                    'type': e.dxftype(),
                    # remove special characters from pole names and flag for manual check
                    'text': self.flag_special_label(e.text),
                    'x': e.dxf.insert[0],
                    'y': e.dxf.insert[1],
                }
                # flag duplicate pole names
                if labels:
                    for l in labels:
                        if new_label['text'] == l['text']:
                            new_label['text'] = "xxx" + f"{len(labels)}" + new_label['text']
                labels.append(new_label)

            # grab any poles
            if e.dxftype() == 'INSERT':
                # print(e.dxftype(), e.dxf.layer, e.dxf.name, e.dxf.insert)
                x = e.dxf.insert[0]
                y = e.dxf.insert[1]
                lat_lon = utm.to_latlon(x, y, 17, "T")
                new_pole = {
                    'type': e.dxftype(),
                    'text': e.dxf.name,
                    'x': x,
                    'y': y,
                    'lat': lat_lon[0],
                    'lon': lat_lon[1],
                }
                poles.append(new_pole)

        # find nearest label for each pole
        self.poles_labels = []
        for n, p in enumerate(poles):
            shortest_dist = 10
            i = -1
            for index, l in enumerate(labels):
                dist = self.find_dist(p, l)
                if dist < shortest_dist:
                    i = index
                    shortest_dist = dist
            if i != -1:
                new_pair = {
                    'pole': p,
                    'label': labels[i]
                }
            else:
                new_pair = {
                    'pole': p,
                    'label': {
                        'text': f"xxx{n}None",
                    }
                }
            # poles, their lat/lon and label
            self.poles_labels.append(new_pair)
Esempio n. 38
0
def convert_to_latlon(easting, northing, zone_number, zone_letter):
    return utm.to_latlon(easting, northing, zone_number, zone_letter)
Esempio n. 39
0
def timeseries():
	global date
	global DATA
	global NODE_KEY

	with open(file_path, 'r') as f:
		print 'PROCESSING: '+str(file_path)

		node = 0
		for line in f:
			line = line.strip().split(' ')
			if len(line)==9 or len(line)==4: # NODE
				if len(line)==9:
					try:
						line = [float(i) for i in line]
					except Exception, e:
						print e
						continue												
					node += 1
					lat, lng = utm.to_latlon(line[0], line[1], UTM_ZONE, 'U')
					u = line[3]
					v = line[4]
					speed = round(math.sqrt((u**2)+(v**2)), 3)
					direction = round(math.degrees(math.atan2(v, u)), 2)
					# NORTH
					if direction>0 and direction<=90: # Q1
						direction = 90-direction
					if direction>90 and direction<=180: # Q4
						direction = 450-direction
					if direction>-90 and direction<=0: # Q2
						direction = 90-direction
					if direction>-180 and direction<=-90: # Q3
						direction = 90-direction
					direction = round(direction, 2)

					key = '{}:{}'.format(lng, lat)
					day = str(date.timetuple().tm_yday)
					mins = '{}'.format(date.hour*60+date.minute)
					NODE_KEY[node] = key
					DATA[key] = {}
					DATA[key][day] = {}
					DATA[key][day][mins] = [speed, direction]
				elif len(line)==4:
					line = [float(i) for i in line]
					node += 1
					u = line[1]
					v = line[2]
					speed = round(math.sqrt((u**2)+(v**2)), 3)
					direction = round(math.degrees(math.atan2(v, u)), 2)
					# NORTH
					if direction>0 and direction<=90: # Q1
						direction = 90-direction
					if direction>90 and direction<=180: # Q4
						direction = 450-direction
					if direction>-90 and direction<=0: # Q2
						direction = 90-direction
					if direction>-180 and direction<=-90: # Q3
						direction = 90-direction
					direction = round(direction, 2)

					key = NODE_KEY[node]
					day = str(date.timetuple().tm_yday)
					mins = '{}'.format(date.hour*60+date.minute)
					if day in DATA[key]:
						DATA[key][day][mins] = [speed, direction]
					else:
						DATA[key][day] = {}
						DATA[key][day][mins] = [speed, direction]
			
			if node==NODE_COUNT:
				node = 0
				date += timestep
				print 'TIMESTEP: '+str(date)
Esempio n. 40
0
 # mm = np.unravel_index(np.argmin(result), result.shape)
 aVol = loc(dst, r, 8, e, [0, dst.shape[0]], [0, dst.shape[1]],
            [0, dst.shape[2]])
 #aSup= loc
 mm = aVol['mPos']
 m = aVol['min']
 # if aVol['min']<aSup['min']:
 #     mm=aVol['mPos']
 #     m=aVol['min']
 # else:
 #     mm = aSup['mPos']
 #     m = aSup['min']
 x = grid[0, mm[0], mm[1], mm[2]]
 y = grid[1, mm[0], mm[1], mm[2]]
 z = grid[2, mm[0], mm[1], mm[2]]
 lat, lon = utm.to_latlon(x, y, 25, 'L')
 lat = lat + (np.random.rand() * 2 - 1) / 10000
 lon = lon + (np.random.rand() * 2 - 1) / 10000
 ttt = UTCDateTime(tt)
 #ttt.day=UTCDateTime.now().day
 #ttt.month = UTCDateTime.now().month
 ev = {
     'id': UTCDateTime(ttt).strftime("%Y%m%d%H%M%S"),
     'time': UTCDateTime(ttt),
     # 'text': 'SWARM ev. mag' + str(pp[5]),
     'lat': lat,
     'lon': lon,
     'dpt': z,
     'mag': 1.5,  #np.log(np.max(vpp)/0.000001),
     'note': 'error ' + str(m)
 }
Esempio n. 41
0
            if way_points[index].latitude > 0:
                utm_data = utm.from_latlon(way_points[index].latitude,
                                           way_points[index].longitude)
                video_kalman.update_estimations(np.array(utm_data[:2]).T)
            print(way_points[index])
            index += 1

        success, image = video.read()
        if not success:
            print("Error in reading video!", file=sys.stderr)
            break
        cv.imshow("Good Weather", image)
        video_kalman.predict_values()
        zone_num, zone_letter = utm_data[2], utm_data[3]
        lat, long = utm.to_latlon(video_kalman.predicted_data[0],
                                  video_kalman.predicted_data[1], zone_num,
                                  zone_letter)
        nearest_data = geographic_db.retrieve_nearest_point(long, lat)
        if nearest_data is not None:
            # print(nearest_data["distance"])
            if current_image != nearest_data["image_path"]:
                current_image = nearest_data["image_path"]
                threading.Thread(target=image_load_job,
                                 args=(current_image, )).start()
        if near_image is not None:
            cv.imshow("Bad Weather", near_image)
        cv.waitKey(1)
        clock.tick(target_fps)
        new_time = time.time()
        current_diff = new_time - prev_time
        print(f'FPS: {1 / current_diff}')
Esempio n. 42
0
def parse_html(xml):
    soup = BeautifulSoup(xml, "html.parser")

    data = {
        "lots": [],
        "last_updated": soup.find('wfs:featurecollection')["timestamp"][:-1]
    }

    region = "Hamburg"
    forecast = False

    for member in soup.find('wfs:featurecollection').find_all('gml:featuremember'):
        name = member.find('de.hh.up:name').string
        count = 0
        try:
            count = int(member.find('de.hh.up:stellplaetze_gesamt').string)
        except AttributeError:
            pass
        free = 0
        state = "nodata"
        situation = member.find('de.hh.up:situation')
        if situation and situation.string != "keine Auslastungsdaten":
            free = int(member.find('de.hh.up:frei').string)
            status = member.find('de.hh.up:status').string
            if status == "frei" or status == "besetzt":
                state = "open"
            else:
                state = "closed"
        lot_type = member.find('de.hh.up:art').string
        if lot_type == "Straßenrand":
            lot_type = "Parkplatz"
        lot_id = member.find('de.hh.up:id').string
        address = ""
        try:
            address = member.find('de.hh.up:einfahrt').string
        except AttributeError:
            try:
                address = member.find('de.hh.up:strasse').string
                try:
                    address += " " + member.find('de.hh.up:hausnr').string
                except (AttributeError, TypeError):
                    pass
            except AttributeError:
                pass

        coord_member = member.find('gml:pos')
        if coord_member:
            coord_string = coord_member.string.split()
            latlon = utm.to_latlon(float(coord_string[0]), float(coord_string[1]), 32, 'U')
            coords = {
                "lat": latlon[0],
                "lng": latlon[1]
            }
        else:
            coords = None
        data['lots'].append({
           "coords":coords,
           "name":name,
           "id": lot_id,
           "lot_type": lot_type,
           "total":count,
           "free":free,
           "state":state,
           "region":region,
           "forecast":forecast,
           "address":address
        })

    return data
Esempio n. 43
0
def foliumMapGenerator(file_names, field_values, innerCells):
    #generates a map based on coords
    fullField = fieldShape(file_names.fieldFileName, field_values.bufferGiven)
    xmin, ymin, xmax, ymax = fiona.open(file_names.fieldFileName).bounds
    x, y = utm.to_latlon((xmax + xmin) / 2, (ymax + ymin) / 2, 12, 'T')
    field_map = folium.Map([x, y], zoom_start=15)

    #applies field shape and field grid to the map
    fieldGrid = gpd.read_file(file_names.fieldFileName + "_grid.shp")
    field = gpd.read_file(file_names.fieldFileName)
    newshape = gpd.GeoDataFrame()
    newshape['geometry'] = None
    index = 0
    newshape.loc[index, 'geometry'] = transform(project, fullField)
    field_map.choropleth(geo_data=newshape.to_json(),
                         data=None,
                         columns=['geometry'],
                         line_opacity=1,
                         fill_opacity=0,
                         fill_color="Purple")
    newdata = gpd.GeoDataFrame()
    newdata['geometry'] = None

    index = 0
    for items in fieldGrid["geometry"]:
        items = transform(project, items)
        newdata.loc[index, 'geometry'] = items
        index = index + 1

    #takes cells and makes them into something that can be applied to folium
    for cells in innerCells:
        bounds = [cells.ur_x, cells.ur_y, cells.bl_x, cells.bl_y]
        shapeOfFeature = Polygon([(cells.bl_x, cells.bl_y),
                                  (cells.ur_x, cells.bl_y),
                                  (cells.ur_x, cells.ur_y),
                                  (cells.bl_x, cells.ur_y)])
        shapeOfFeature = transform(project, shapeOfFeature)
        bl_x, bl_y, ur_x, ur_y = shapeOfFeature.bounds
        bounds = [ur_y, ur_x, bl_y, bl_x]
        field_values.nitrogenList.sort()
        fill_color = str(color(field_values, cells.nitrogen))
        folium.features.RectangleMarker(
            bounds=bounds,
            popup=
            "Protein: %.2f <br> Yield: %.2f <br> Nitrogen: %d <br> Entry: %d" %
            (cells.protein, cells.cropYield, cells.nitrogen, cells.entryNum),
            color="Black",
            fill_color=fill_color,
            fill_opacity=1).add_to(field_map)

    #popups on field. Probably want to change these
    html = """
    <p><strong> map of field </strong></p>
    """
    iframe = folium.IFrame(html=html, width=200, height=50)
    popup = folium.Popup(iframe, max_width=2650)
    x, y = utm.to_latlon((xmax + xmin) / 2, (ymax + 25), 12, 'T')
    folium.Marker([x, y], popup=popup).add_to(field_map)
    html = """<p> Color Guide </p> <br>"""
    i = 0
    while i < len(field_values.nitrogenList):
        opening = "<p><font color = " + color(
            field_values, field_values.nitrogenList[i]) + ">"
        newString = "&#9608 nitrogen level of %d" % (
            field_values.nitrogenList[i])
        closing = "</font></p>"
        breakLine = "<br>"
        fullstring = opening + newString + closing + breakLine
        html = html + fullstring
        i = i + 1
    iframe = folium.IFrame(html=html, width=100, height=300)
    popup = folium.Popup(iframe, max_width=2650)
    x, y = utm.to_latlon((xmin - 25), (ymax + ymin) / 2, 12, 'T')
    folium.Marker([x, y], popup=popup).add_to(field_map)
    folium.LatLngPopup().add_to(field_map)

    #saves and opens
    field_map.save("created_map.html")
    webbrowser.open_new_tab("created_map.html")
    return
Esempio n. 44
0
 def CovertToLatLon(self, east, north, zoneNumber, zoneLetter):
     lat, lon = utm.to_latlon(east, north, zoneNumber, zoneLetter)
     return [lat, lon]
Esempio n. 45
0
def longitude(row,zone,E_off,N_off):
    EastNorth = (row['Easting']+E_off, row['Northing']+N_off)
    latlon = utm.to_latlon(*EastNorth, zone, northern=True)
    return(round(latlon[1],4))
Esempio n. 46
0
def UTMconversion(UTM_XY):
    WGS84_XY = utm.to_latlon(UTM_XY[0], UTM_XY[1], 15, 'N')
    return WGS84_XY
Esempio n. 47
0
def coordenadas_utm(utm_norte, utm_este, zona, letra):
    return utm.to_latlon(utm_este, utm_norte, zona, letra)
Esempio n. 48
0
import utm
import csv
import sys

TIMESTAMP = 1354579200

if (len(sys.argv) <= 4):
    print 'Error. Usage: input output zone_number zone_letter'
    exit()

input = open(sys.argv[1])
#input.readline()
csv_reader = csv.reader(input, delimiter=' ')
output = open(sys.argv[2], 'w+')

output.write(str(TIMESTAMP) + '\n')
output.write(str(TIMESTAMP) + '\n')

for point in csv_reader:
    try:
        x = float(point[0])
        y = float(point[1])
        #print x, y
        latlng = utm.to_latlon(x, y, int(sys.argv[3]), sys.argv[4])

        output.write(
            str(TIMESTAMP) + ',' + str(latlng[0]) + ',' + str(latlng[1]) +
            '\n')
    except ValueError:
        print 'Skipped ' + str(point)
Esempio n. 49
0
    def __init__(self,
                 dataConfig,
                 topo,
                 start_date,
                 end_date,
                 time_zone='UTC',
                 dataType='wrf',
                 tempDir=None,
                 forecast_flag=False,
                 day_hour=0,
                 n_forecast_hours=18):

        if (tempDir is None) | (tempDir == 'WORKDIR'):
            tempDir = os.environ['WORKDIR']

        self.tempDir = tempDir
        self.dataConfig = dataConfig
        self.dataType = dataType
        self.start_date = start_date
        self.end_date = end_date
        self.time_zone = time_zone
        self.forecast_flag = forecast_flag
        self.day_hour = day_hour
        self.n_forecast_hours = n_forecast_hours

        # degree offset for a buffer around the model domain
        self.offset = 0.1

        self.force_zone_number = None
        if 'zone_number' in dataConfig:
            self.force_zone_number = dataConfig['zone_number']

        # The data that will be output
        self.variables = [
            'air_temp', 'vapor_pressure', 'precip', 'wind_speed',
            'wind_direction', 'cloud_factor', 'thermal'
        ]

        # get the bounds of the model so that only the values inside
        # the model domain are used
        self.x = topo.x
        self.y = topo.y
        self.lat = topo.topoConfig['basin_lat']
        self.lon = topo.topoConfig['basin_lon']

        # get the zone number and the bounding box
        u = utm.from_latlon(topo.topoConfig['basin_lat'],
                            topo.topoConfig['basin_lon'],
                            self.force_zone_number)
        self.zone_number = u[2]
        self.zone_letter = u[3]

        ur = np.array(
            utm.to_latlon(np.max(self.x), np.max(self.y), self.zone_number,
                          self.zone_letter))
        ll = np.array(
            utm.to_latlon(np.min(self.x), np.min(self.y), self.zone_number,
                          self.zone_letter))

        buff = 0.1  # buffer of bounding box in degrees
        ur += buff
        ll -= buff
        self.bbox = np.append(np.flipud(ll), np.flipud(ur))

        self._logger = logging.getLogger(__name__)

        # load the data
        if dataType == 'wrf':
            self.load_from_wrf()
        elif dataType == 'netcdf':
            self.load_from_netcdf()
        elif dataType == 'hrrr_grib':
            self.load_from_hrrr()
        else:
            raise Exception('Could not resolve dataType')
Esempio n. 50
0
reference_file_name = 'orkney.dat'

times = (0., 100.)
boundary_xy = numpy.loadtxt('orkney.xy')

tide = uptide.Tides(constituents)
tide.set_initial_time(initial_time)
tnci = uptide.tidal_netcdf.OTPSncTidalInterpolator(tide, grid_file_name,
                                                   data_file_name, ranges)

vals_t = []
for t in times:
    tnci.set_time(t)
    vals = []
    for xy in boundary_xy:
        latlon = utm.to_latlon(xy[0], xy[1], utm_zone, utm_band)
        vals.append(
            tnci.get_val((latlon[1], latlon[0]), allow_extrapolation=True))

    vals_t.append(vals)

vals_t = numpy.array(vals_t).T
# uncomment to update reference:
#numpy.savetxt(reference_file_name, vals_t)

reference = numpy.loadtxt(reference_file_name)
err = numpy.abs(reference - vals_t).max()
print("err = ", err)
if err > 1e-3:
    print("Error too large")
    sys.exit(1)
Esempio n. 51
0
        url = bus127.buses[busurl]
        res = requests.get(url).json()
        points = res['Sc']['Crs'][0]['Ps']
        for point in points:
            route.append([point['Y'], point['X']])
        # print(route)


# 	stations = res['Sc']['Crs'][0]['Ss']
# 	for station in stations:
# 		# print(station['Pt']['Y'])
# 		station_point.append([station['Pt']['X'], station['Pt']['Y']])

bus_lt, bus_ln = utm.to_latlon(658048,
                               4790628,
                               43,
                               zone_letter='T',
                               northern=None,
                               strict=True)
station_lt, station_ln = 43.26525, 76.948869
print(bus_lt, bus_ln)

get_route()


def route_dir():
    dist_list = []
    clockwise = True
    segments = 0
    # расстояние до автобуса всех точек
    for i in range(0, len(route)):
        dist_list.append(get_dist(route[i][0], route[i][1], bus_lt, bus_ln))
Esempio n. 52
0
def UTM(E, N, zone_num, zone_let):
    return utm.to_latlon(E, N)
Esempio n. 53
0
    def test_to_latlon_range_checks(self):
        '''to_latlon should fail with out-of-bounds input'''

        # test easting range

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(0),
                          np.array(5000000), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(99999),
                          np.array(5000000), 32, 'U')

        for i in range(100000, 999999, 1000):
            UTM.to_latlon(np.array(i), np.array(5000000), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon,
                          np.array(1000000), np.array(5000000), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon,
                          np.array(100000000000), np.array(5000000), 32, 'U')

        # test northing range

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(-100000), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(-1), 32, 'U')
        for i in range(10, 10000000, 1000):
            UTM.to_latlon(np.array(500000), np.array(i), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(10000001), 32, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(50000000), 32, 'U')

        # test zone numbers

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 0, 'U')

        for i in range(1, 60):
            UTM.to_latlon(np.array(500000), np.array(5000000), i, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 61, 'U')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 1000, 'U')

        # test zone letters

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'A')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'B')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'I')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'O')

        for i in range(ord('C'), ord('X')):
            i = chr(i)
            if i != 'I' and i != 'O':
                UTM.to_latlon(np.array(500000), np.array(5000000), 32, i)

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'Y')

        self.assertRaises(UTM.OutOfRangeError, UTM.to_latlon, np.array(500000),
                          np.array(5000000), 32, 'Z')
Esempio n. 54
0
        'lightblue', 'lightgreen', 'gray', 'black', 'lightgray'
    ]))
colour = defaultdict(lambda: next(colour_iter))

m = folium.Map(location=[50.75, -1], zoom_start=10)

#It's zone 30N UTM, so EPSG code is 32630

#pickle.dump(tracks, open("./ss.pkl", "wb"))

for track in tracks:
    print(detector.zone_number, detector.northern, measurement_model.mapping)

    points = [
        utm.to_latlon(*state.state_vector[measurement_model.mapping, :],
                      detector.zone_number,
                      northern=detector.northern,
                      strict=False) for state in track
    ]

    folium.PolyLine(points, color=colour[track.metadata.get('MMSI')]).add_to(m)
    folium.Marker(points[-1],
                  icon=folium.Icon(icon='fa-ship',
                                   prefix="fa",
                                   color=colour[track.metadata.get('MMSI')]),
                  popup="\n".join(
                      "{}: {}".format(key, value)
                      for key, value in track.metadata.items())).add_to(m)

# %%

# sphinx_gallery_thumbnail_path = '_static/sphinx_gallery/AIS_Solent_Tracker_thumb.png'
Esempio n. 55
0
def getPoint(row):
    x = float(row['Gis_X'].replace(',', '.'))
    y = float(row['Gis_Y'].replace(',', '.'))
    latlon = utm.to_latlon(x, y, 30, northern=True)
    point = geojson.Point(latlon[::-1], precision=8)
    return point
    def getStationsFromDomain(self, maxlat, maxlon, minlat, minlon, height):
        """Searches station list for radar stations that would be relevant
        to the domain provided.

        maxlat: maximum latitude of domain
        maxlon: maximum longitude of domain
        minlat: minimum lattitude of domain
        minlon: minimum longitude of domain
        height: height above sealevel in meters for domain

        returns: list of station ids ex. ['KIND', 'KLVX']
        """

        # http://geokov.com/education/utm.aspx
        # easting values increase towards east
        # max lon is east side
        # max lat is north

        maxeast_domain, maxnorth_domain, max_zone_number, max_zone_letter = utm.from_latlon(
            maxlat, maxlon)

        mineast_domain, minnorth_domain, min_zone_number, min_zone_letter = utm.from_latlon(
            minlat, minlon)

        relevant_stations = []
        possibly_relevant_stations = []
        for i, latlon in enumerate(STATION_LATLONS):
            lat, lon = latlon

            station_radius = self._calculateRadiusAtHeight(
                height, STATION_INDEX[i]['station_elevation'])
            if station_radius is None:
                continue

            relevant_radius = RELEVANT_DISTANCE_COEFFICENT * station_radius

            maxeast = maxeast_domain + relevant_radius
            maxnorth = maxnorth_domain + relevant_radius
            domain_maxlat, domain_maxlon = utm.to_latlon(maxeast,
                                                         maxnorth,
                                                         max_zone_number,
                                                         max_zone_letter,
                                                         strict=False)

            mineast = mineast_domain - relevant_radius
            minnorth = minnorth_domain - relevant_radius
            domain_minlat, domain_minlon = utm.to_latlon(mineast,
                                                         minnorth,
                                                         min_zone_number,
                                                         min_zone_letter,
                                                         strict=False)

            # Vertical band of relevant domain bounded by user-given domain
            if ((lat <= domain_maxlat and lat >= domain_minlat)
                    and (lon <= maxlon and lon >= minlon)):
                relevant_stations.append(STATION_INDEX[i]['station_id'])

            # Horizontal band of relevant domain bounded by user-given domain
            elif ((lat <= maxlat and lat >= minlat)
                  and (lon <= domain_maxlon and lon >= domain_minlon)):
                relevant_stations.append(STATION_INDEX[i]['station_id'])

            # north east corner of relevant domain
            elif ((lat <= domain_maxlat and lat >= maxlat)
                  and (lon <= domain_maxlon and lon >= maxlon)
                  and _isStationInDomainCorner(
                      maxlat, maxlon, STATION_INDEX[i]['latitude'],
                      STATION_INDEX[i]['longitude'], relevant_radius)):

                relevant_stations.append(STATION_INDEX[i]['station_id'])

            # south east corner of relevant domain
            elif ((lat <= domain_minlat and lat >= minlat)
                  and (lon <= domain_maxlon and lon >= maxlon)
                  and _isStationInDomainCorner(
                      minlat, maxlon, STATION_INDEX[i]['latitude'],
                      STATION_INDEX[i]['longitude'], relevant_radius)):

                relevant_stations.append(STATION_INDEX[i]['station_id'])

            # south west corner of relevant domain
            elif ((lat <= domain_minlat and lat >= minlat)
                  and (lon <= domain_minlon and lon >= minlon)
                  and _isStationInDomainCorner(
                      minlat, minlon, STATION_INDEX[i]['latitude'],
                      STATION_INDEX[i]['longitude'], relevant_radius)):

                relevant_stations.append(STATION_INDEX[i]['station_id'])

            # north west corner of relevant domain
            elif ((lat <= domain_maxlat and lat >= maxlat)
                  and (lon <= domain_minlon and lon >= minlon)
                  and _isStationInDomainCorner(
                      maxlat, minlon, STATION_INDEX[i]['latitude'],
                      STATION_INDEX[i]['longitude'], relevant_radius)):

                relevant_stations.append(STATION_INDEX[i]['station_id'])

        return relevant_stations
Esempio n. 57
0
def extract_state_arr_mean(state_crop_csv,
                           state_sm_dir,
                           point_no,
                           fdir=None,
                           point_level='high'):
    """
    Extract state array of field data from munich test sites.
    :param state_crop_csv: filename of crop field data csv
    :param state_sm_dir: directory location of soil moisture field data
    :param point_no: field point number, corresponding to munich test site numbering
    :param fdir: directory to save the output
    :param point_level: which point to use choice of: 'low', 'high', 'med', 'mean'
    :return:
    """
    state_dat = mlab.csv2rec(state_crop_csv, skiprows=1, delimiter=',')
    dates = state_dat['none']
    date_str = [a.strftime("%Y/%m/%d %H:%M") for a in dates]
    lai_high = state_dat['lai']
    lai_low = state_dat['lai_1']
    lai_med = state_dat['lai_2']
    lai_mean = state_dat['lai_mean_hants']
    lai_std = state_dat['lai_std']
    canht_high = state_dat['height_cm'] / 100.
    canht_low = state_dat['height_cm_1'] / 100.
    canht_med = state_dat['height_cm_2'] / 100.
    canht_mean = state_dat['height_cm_mean'] / 100.
    canht_std = state_dat['height_cm_std'] / 100.

    sm_loc_dat = mlab.csv2rec(state_sm_dir + '/locations_utm_epsg-32632.csv')
    easting = sm_loc_dat['point_x'][(sm_loc_dat['id'] == point_no)
                                    & (sm_loc_dat['esu'] == 'med')]
    northing = sm_loc_dat['point_y'][(sm_loc_dat['id'] == point_no)
                                     & (sm_loc_dat['esu'] == 'med')]
    file_head_1 = sm_loc_dat['esu_sm'][(sm_loc_dat['id'] == point_no)
                                       & (sm_loc_dat['esu'] == 'med')][0]
    file_head_2 = sm_loc_dat['esu_sm'][(sm_loc_dat['id'] == point_no)
                                       & (sm_loc_dat['esu'] == 'high')][0]
    file_head_3 = sm_loc_dat['esu_sm'][(sm_loc_dat['id'] == point_no)
                                       & (sm_loc_dat['esu'] == 'low')][0]
    lat, lon = utm.to_latlon(easting, northing, 32, 'U')
    sm_csv1 = glob.glob(state_sm_dir + '/' + file_head_1 + '*SM.csv')[0]
    sm_dat1 = mlab.csv2rec(sm_csv1)
    sm_csv2 = glob.glob(state_sm_dir + '/' + file_head_2 + '*SM.csv')[0]
    sm_dat2 = mlab.csv2rec(sm_csv2)
    sm_csv3 = glob.glob(state_sm_dir + '/' + file_head_3 + '*SM.csv')[0]
    sm_dat3 = mlab.csv2rec(sm_csv3)

    #sm_idx = [find_nearest(sm_dat['date'], dt.datetime.combine(x,dt.datetime.min.time()))[1] for x in dates]
    sm_dates = sm_dat1['date'][3:]
    date_str_sm = [a.strftime("%Y/%m/%d %H:%M") for a in sm_dates]
    sm1_port1 = sm_dat1['port1_sm'][3:]
    sm1_port2 = sm_dat1['port2_sm'][3:]
    sm1_mean = np.nanmean((sm1_port1, sm1_port2), axis=0)
    sm2_port1 = sm_dat2['port1_sm']
    sm2_port2 = sm_dat2['port2_sm']
    sm2_mean = np.nanmean((sm2_port1, sm2_port2), axis=0)
    sm3_port1 = sm_dat3['port1_sm'][3:]
    sm3_port2 = sm_dat3['port2_sm'][3:]
    sm3_mean = np.nanmean((sm3_port1, sm3_port2), axis=0)
    sm_mean = np.nanmean((sm1_mean, sm2_mean, sm3_mean), axis=0)
    sm_std = np.nanstd(
        (sm1_port1, sm1_port2, sm2_port1, sm2_port2, sm3_port1, sm3_port2),
        axis=0)

    save_arr_lai_canht = np.array([
        date_str, lai_mean, canht_mean,
        np.array([lat] * len(dates)),
        np.array([lon] * len(dates)), lai_std, canht_std
    ]).T
    fname_lai_canht = fdir + '/mni_lai_canht_field_' + str(
        point_no) + '_' + str(point_level) + '.csv'
    np.savetxt(fname_lai_canht,
               save_arr_lai_canht,
               fmt='%s',
               delimiter=',',
               header='date, lai, canht, lat, lon, lai_std, '
               'canht_std')

    save_arr_sm = np.array([
        date_str_sm, sm_mean,
        np.array([lat] * len(sm_dates)),
        np.array([lon] * len(sm_dates)), sm_std
    ]).T
    fname_sm = fdir + '/mni_sm_field_' + str(point_no) + '_' + str(
        point_level) + '.csv'
    np.savetxt(fname_sm,
               save_arr_sm,
               fmt='%s',
               delimiter=',',
               header='date, sm, lat, lon, sm_std')

    return sm_dates, lat, lon
zoneLetter = root.find("Georeference").find("zoneLetter").text
print("georeferenceMatrix", georeferenceMatrix)
print("zoneNumber", zoneNumber)
print("zoneLetter", zoneLetter)

coordinates_map = []
coordinates_gps = []
for t in root.find('Transformations'):
    gps_str = t.find("gps").text
    if gps_str is not None:
        #print (gps_str)
        d = gps_str.split()
        ll1 = d[0]
        ll2 = d[1]
        ll3 = d[2]

        coordinates_gps.append([ll1, ll2, ll3])
    m = t.find('Affine').find('Data').text
    mm = stringToNp(m)
    v = np.array([mm[3, 0], mm[3, 1], mm[3, 2], 1])
    b = georeferenceMatrix.dot(v)
    #print (b)
    (lat, lon) = utm.to_latlon(b[1],
                               b[0],
                               zone_number=zoneNumber,
                               zone_letter=zoneLetter)
    coordinates_map.append([lat, lon])

kfile = open(fname_base + "_map.kml", 'w')
generateKML(kfile, coordinates_map, coordinates_gps)
Esempio n. 59
0
    def get_LOS_vector(self, locations):
        """
        calculate beta - the angle at earth center between reference point
        and satellite nadir
        """
        if not isinstance(locations, list):
            locations = [locations]

        utmZone = self.location_UTM_zone
        refPoint = vmath.Vector3(self.ref.x, self.ref.y, 0)
        satAltitude = self.satellite_altitude
        satAzimuth = self.satellite_azimuth
        satIncidence = self.ref_incidence
        earthRadius = self.local_earth_radius

        DEG2RAD = np.pi / 180.
        alpha = satIncidence * DEG2RAD
        beta = (earthRadius / (satAltitude + earthRadius)) * np.sin(alpha)
        beta = alpha - np.arcsin(beta)
        beta = beta / DEG2RAD

        # calculate angular separation of (x,y) from satellite track passing
        # through (origx, origy) with azimuth satAzimuth

        # Long lat **NOT** lat long
        origy, origx = utm.to_latlon(
            refPoint.x, refPoint.y, np.abs(utmZone), northern=utmZone > 0
        )

        xy = np.array([
            utm.to_latlon(u[0], u[1], np.abs(utmZone), northern=utmZone > 0)
            for u in locations
        ])
        y = xy[:, 0]
        x = xy[:, 1]

        angdist = self._ang_to_gc(x, y, origx, origy, satAzimuth)

        # calculate beta2, the angle at earth center between roaming point and
        # satellite nadir track, assuming right-looking satellite

        beta2 = beta - angdist
        beta2 = beta2 * DEG2RAD

        # calculate alpha2, the new incidence angle

        alpha2 = np.sin(beta2) / (
            np.cos(beta2) - (earthRadius / (earthRadius + satAltitude))
        )
        alpha2 = np.arctan(alpha2)
        alpha2 = alpha2 / DEG2RAD

        # calculate pointing vector

        satIncidence = 90 - alpha2
        satAzimuth = 360 - satAzimuth

        los_x = -np.cos(satAzimuth * DEG2RAD) * np.cos(satIncidence * DEG2RAD)
        los_y = -np.sin(satAzimuth * DEG2RAD) * np.cos(satIncidence * DEG2RAD)
        los_z = np.sin(satIncidence * DEG2RAD)

        return vmath.Vector3Array([los_x, los_y, los_z])
Esempio n. 60
0
 def fromUTM(self, coords):
     # Conversion
     return utm.to_latlon(coords)