Takes an object which is a [lat,lon] array, a geocodable string,
 or an object that implements +to_coordinates+ and returns a
 [lat,lon] array. Note that if a string is passed this may be a slow-
 running method and may return nil.
162050
def extract_coordinates(point)
      case point
      when Array
        if point.size == 2
          lat, lon = point
          if !lat.nil? && lat.respond_to?(:to_f) and
            !lon.nil? && lon.respond_to?(:to_f)
          then
            return [ lat.to_f, lon.to_f ]
          end
        end
      when String
        point = Geocoder.coordinates(point) and return point
      else
        if point.respond_to?(:to_coordinates)
          if Array === array = point.to_coordinates
            return extract_coordinates(array)
          end
        end
      end
      [ NAN, NAN ]
    end
1092386
def coords(self):
        
        x, y = ("lat", "lng") if self.order == "lat" else ("lng", "lat")
        try:
            return (self["location"][x], self["location"][y])

        except KeyError:
            return None
1209715
def to_array(self):
        
        array = super(Location, self).to_array()
        array['longitude'] = float(self.longitude)  # type float
        array['latitude'] = float(self.latitude)  # type float
        return array
700963
def fromGeoJson(struct, attributes=None):
    ""
    if isinstance(struct, basestring):
        struct = json.loads(struct)
    type_map = {
        'Point': Point,
        'MultiLineString': Polyline,
        'LineString': Polyline,
        'Polygon': Polygon,
        'MultiPolygon': Polygon,
        'MultiPoint': Multipoint,
        'Box': Envelope
    }
    if struct['type'] == "Feature":
        return fromGeoJson(struct, struct.get('properties', None))
    elif struct['type'] == "FeatureCollection":
        sr = None
        if 'crs' in struct:
            sr = SpatialReference(struct['crs']['properties']['code'])
            members = map(fromGeoJson, struct['members'])
            for member in members:
                member.spatialReference = sr
            return members
        else:
            return map(fromGeoJson, struct['members'])
    elif struct['type'] in type_map and hasattr(type_map[struct['type']], 
                                              'fromGeoJson'):
        instances = type_map[struct['type']].fromGeoJson(struct)
        i = []
        assert instances is not None, "GeoJson conversion returned a Null geom"
        for instance in instances:
            if 'properties' in struct:
                instance.attributes = struct['properties'].copy()
                if '@esri.sr' in instance.attributes:
                    instance.spatialReference = SpatialReference.fromJson(
                                               instance.attributes['@esri.sr'])
                    del instance.attributes['@esri.sr']
            if attributes:
                if not hasattr(instance, 'attributes'):
                    instance.attributes = {}
                for k, v in attributes.iteritems():
                    instance.attributes[k] = v
            i.append(instance)
        if i:
            if len(i) > 1:
                return i
            return i[0]
    raise ValueError("Unconvertible to geometry")
1287750
def gps
      return nil unless gps_latitude && gps_longitude

      altitude = gps_altitude.is_a?(Array) ? gps_altitude.first : gps_altitude

      GPS.new(gps_latitude.to_f * (gps_latitude_ref == 'S' ? -1 : 1),
              gps_longitude.to_f * (gps_longitude_ref == 'W' ? -1 : 1),
              altitude && (altitude.to_f * (gps_altitude_ref == "\1" ? -1 : 1)),
              gps_img_direction && gps_img_direction.to_f)
    end
613949
def geometry_linestring(lat, lon, elev):
    
    logger_excel.info("enter geometry_linestring")
    d = OrderedDict()
    coordinates = []
    temp = ["", ""]

    # Point type, Matching pairs.
    if lat[0] == lat[1] and lon[0] == lon[1]:
        logger_excel.info("matching geo coordinate")
        lat.pop()
        lon.pop()
        d = geometry_point(lat, lon, elev)

    else:
        # Creates coordinates list
        logger_excel.info("unique geo coordinates")
        for i in lon:
            temp[0] = i
            for j in lat:
                temp[1] = j
                coordinates.append(copy.copy(temp))
        if elev:
            for i in coordinates:
                i.append(elev)
        # Create geometry block
        d['type'] = 'Linestring'
        d['coordinates'] = coordinates
    logger_excel.info("exit geometry_linestring")
    return d
135006
def convert_coordinates(coords, origin, wgs84, wrapped):
    
    if isinstance(coords, list) or isinstance(coords, tuple):
        try:
            if isinstance(coords[0], list) or isinstance(coords[0], tuple):
                return [convert_coordinates(list(c), origin, wgs84, wrapped) for c in coords]
            elif isinstance(coords[0], float):
                c = list(transform(origin, wgs84, *coords))
                if wrapped and c[0] < -170:
                    c[0] = c[0] + 360
                return c

        except IndexError:
            pass

    return None
612105
function fromString(str) {
  let 
    tmp = str.match(regexLatLon),
    converted = null;

  // Format: "latitude, longitude"
  if (tmp !== null) {
    converted = toCoordinate(tmp[1], tmp[2]);
  }
  // Format: "<geohash>"
  else if (regexGeohash.test(str)) {
    tmp = geohash.decode(str);
    converted = toCoordinate(tmp.latitude, tmp.longitude);
  }

  return converted;
}
307963
def convertor(geometry, method="wgs2gcj"):
    
    if geometry['type'] == 'Point':
        coords = geometry['coordinates']
        coords[0], coords[1] = methods[method](coords[0], coords[1])
    elif geometry['type'] == 'LineString' or geometry['type'] == 'MutliPoint':
        coordinates = geometry['coordinates']
        for coords in coordinates:
            coords[0], coords[1] = methods[method](coords[0], coords[1])
    elif geometry['type'] == 'Polygon' or geometry['type'] == 'MultiLineString':
        coordinates = geometry['coordinates']
        for rings in coordinates:
            for coords in rings:
                coords[0], coords[1] = methods[method](coords[0], coords[1])
    elif geometry['type'] == 'MultiPolygon':
        coordinates = geometry['coordinates']
        for rings in coordinates:
            for lines in rings:
                for coords in lines:
                    coords[0], coords[1] = methods[method](coords[0], coords[1])
    return geometry
1244567
def _parse_json(self, json, exactly_one=True):
        ''''''
        features = json['features']
        if features == []:
            return None

        def parse_feature(feature):
            location = feature['place_name']
            place = feature['text']
            longitude = feature['geometry']['coordinates'][0]
            latitude = feature['geometry']['coordinates'][1]
            return Location(location, (latitude, longitude), place)
        if exactly_one:
            return parse_feature(features[0])
        else:
            return [parse_feature(feature) for feature in features]
1013646
def reverse_geocode_ban_fr_params(query)
      lat_lon = query.coordinates
      params = {
          lat: lat_lon.first,
          lon: lat_lon.last
      }
      unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
        params[:type] = type.downcase
      end
      params
    end
948101
def geom_dict_to_array_dict(geom_dict, coord_names=['Longitude', 'Latitude']):
    
    x, y = coord_names
    geom = geom_dict['geometry']
    new_dict = {k: v for k, v in geom_dict.items() if k != 'geometry'}
    array = geom_to_array(geom)
    new_dict[x] = array[:, 0]
    new_dict[y] = array[:, 1]
    if geom.geom_type == 'Polygon':
        holes = []
        for interior in geom.interiors:
            holes.append(geom_to_array(interior))
        if holes:
            new_dict['holes'] = [holes]
    elif geom.geom_type == 'MultiPolygon':
        outer_holes = []
        for g in geom:
            holes = []
            for interior in g.interiors:
                holes.append(geom_to_array(interior))
            outer_holes.append(holes)
        if any(hs for hs in outer_holes):
            new_dict['holes'] = outer_holes
    return new_dict
432387
def readObject(self, innode):
        ''''''
        #get name
        names=innode.getElementsByTagName('name')[0].childNodes[0].data.strip()
        
        #get type
        pointType = 'Unknown'
        if len(innode.getElementsByTagName('LineString')) == 0 and len(innode.getElementsByTagName('Point')) == 0:
            pointType = 'Polygon'
        elif len(innode.getElementsByTagName('Polygon')) == 0 and len(innode.getElementsByTagName('Point')) == 0:
            pointType = 'Polygon'
        elif len(innode.getElementsByTagName('LineString')) == 0 and len(innode.getElementsByTagName('Polygon')) == 0:
            pointType = 'Point'
            
        #get coords
        coords = innode.getElementsByTagName('coordinates')[0].childNodes[0].data.strip()
        coordsSplit = coords.split()
        ret_s = []
        for j in coordsSplit:
            jcoord = j.split(',')
            if len(jcoord) == 3 and jcoord[0] != '' and jcoord[1] != '':
                #print("Got lon " + jcoord[0] + " and lat " + jcoord[1])
                ret_s.append((float(jcoord[1]), float(jcoord[0])))
            
        #return tuple
        return (str(pointType), str(names), ret_s)
1101644
function decodeWildGeoObject(geoDogObj) {
  if (geoDogObj !== null && geoDogObj.hasOwnProperty("l") && Array.isArray(geoDogObj.l) && geoDogObj.l.length === 2) {
    return geoDogObj.l;
  } else {
    throw new Error("Unexpected WildGeo location object encountered: " + JSON.stringify(geoDogObj));
  }
}
872862
def geocode(self, string, bounds=None, region=None,
                language=None, sensor=False):
        '''
        '''
        if isinstance(string, unicode):
            string = string.encode('utf-8')

        params = {
            'address': self.format_string % string,
            'sensor': str(sensor).lower()
        }

        
        if bounds:
            params['bounds'] = bounds
            
        if region:
            params['region'] = region
            
        if language:
            params['language'] = language
            

        if not self.premier:
            url = self.get_url(params)
        else:
            url = self.get_signed_url(params)

        return self.GetService_url(url)
562636
function parse_lat_lon(obj, lat_field, lon_field) {
  if ([lat_field, lon_field].every(_.has.bind(null, obj))) {
    return { latitude: obj[lat_field], longitude: obj[lon_field] };
  }
}
600509
def from_coords(cls, coords, sort=True):
        
        coords = list(coords)
        if sort:
            coords.sort()
        if len(coords[0]) == 2:  # 2D coordinates
            lons, lats = zip(*coords)
            depths = None
        else:  # 3D coordinates
            lons, lats, depths = zip(*coords)
            depths = numpy.array(depths)
        return cls(numpy.array(lons), numpy.array(lats), depths)