private async Task InsertData() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\school_list_wa.txt"); foreach (var line in File.ReadLines(path)) { var columns = line.Split('\t'); var schoolId = columns[0]; var schoolName = columns[1]; var latitude = double.Parse(columns[2], CultureInfo.InvariantCulture); var longitude = double.Parse(columns[3], CultureInfo.InvariantCulture); var point = new GeoPoint(latitude, longitude); var rangeKeyVal = new AttributeValue { S = schoolId }; var schoolNameVal = new AttributeValue { S = schoolName }; var req = new PutPointRequest(point, rangeKeyVal); req.PutItemRequest.Item["schoolName"] = schoolNameVal; await _geoDataManager.PutPointAsync(req); } Status = Status.Ready; }
private async Task InsertData(IGeoService dm) { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\point_list.txt"); foreach (var line in File.ReadLines(path)) { var columns = line.Split('\t'); var vendorid = columns[0]; var st = columns[1]; var et = columns[2]; var fromLatitude = double.Parse(columns[4], CultureInfo.InvariantCulture); var fromLongitude = double.Parse(columns[3], CultureInfo.InvariantCulture); var toLatitude = double.Parse(columns[6], CultureInfo.InvariantCulture); var toLongitude = double.Parse(columns[5], CultureInfo.InvariantCulture); var fromPoint = new GeoPoint(fromLatitude, fromLongitude); var toPoint = new GeoPoint(toLatitude, toLongitude); var rangeKeyVal = new AttributeValue { S = vendorid }; var req = new PutPointRequest(fromPoint, toPoint); req.PutItemRequest.Item["startTime"] = new AttributeValue { S = st }; req.PutItemRequest.Item["endTime"] = new AttributeValue { S = et }; await dm.PutPointAsync(req); } Status = Status.Ready; }
private async Task InsertData() { var guid = Guid.NewGuid(); var imgUrl = "https://s3.eu-central-1.amazonaws.com/tindergramphotosbacket/kreml_small.jpg"; var imgUrlLarge = "https://s3.eu-central-1.amazonaws.com/tindergramphotosbacket/kreml.jpg"; var latitude = 54.1896866; var longitude = 37.5893742; var point = new GeoPoint(latitude, longitude); var rangeKeyVal = new AttributeValue { S = guid.ToString() }; var imgUrlVal = new AttributeValue { S = imgUrl }; var imgUrlLargeVal = new AttributeValue { S = imgUrlLarge }; var req = new PutPointRequest(point, rangeKeyVal); req.PutItemRequest.Item["imgUrl"] = imgUrlVal; req.PutItemRequest.Item["imgUrlLarge"] = imgUrlLargeVal; await _geoDataManager.PutPointAsync(req); }
/// <summary> /// <p> /// Put a point into the Amazon DynamoDB table. Once put, you cannot update attributes specified in /// GeoDataManagerConfiguration: hash key, range key, geohash and geoJson. If you want to update these columns, you /// need to insert a new record and delete the old record. /// </p> /// <b>Sample usage:</b> /// <pre> /// GeoPoint geoPoint = new GeoPoint(47.5, -122.3); /// AttributeValue rangeKeyValue = new AttributeValue().withS("a6feb446-c7f2-4b48-9b3a-0f87744a5047"); /// AttributeValue titleValue = new AttributeValue().withS("Original title"); /// PutPointRequest putPointRequest = new PutPointRequest(geoPoint, rangeKeyValue); /// putPointRequest.getPutItemRequest().getItem().put("title", titleValue); /// PutPointResult putPointResult = geoDataManager.putPoint(putPointRequest); /// </pre> /// </summary> /// <param name="putPointRequest">Container for the necessary parameters to execute put point request.</param> /// <returns>Result of put point request.</returns> public Task <PutPointResult> PutPointAsync(PutPointRequest putPointRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (putPointRequest == null) { throw new ArgumentNullException("putPointRequest"); } return(_dynamoDBManager.PutPointAsync(putPointRequest, cancellationToken)); }
public async Task <string> FunctionHandler(ResponseSourse json, ILambdaContext context) { context.Logger.LogLine($"Beginning to process {context.FunctionName} records..."); var photoJsonData = json; //return ""; context.Logger.LogLine($"Create context {context.FunctionName}..."); var config = new GeoDataManagerConfiguration(new AmazonDynamoDBClient(), _tableName); var ddb = new AmazonDynamoDBClient(); _config = new GeoDataManagerConfiguration(ddb, _tableName); _geoDataManager = new GeoDataManager(_config); var items = photoJsonData.response.items.ToList(); for (int i = 0; i < items.Count; i++) { var item = items.ElementAt(i); var imgUrl = item.sizes.FirstOrDefault(x => x.type == "p")?.url; var imgUrlLarge = item.sizes.FirstOrDefault(x => x.type == "w")?.url; if (String.IsNullOrEmpty(imgUrl) || String.IsNullOrEmpty(imgUrlLarge)) { continue; } var guid = Guid.NewGuid(); var latitude = item.lat; var longitude = item.@long; var point = new GeoPoint(latitude, longitude); var rangeKeyVal = new AttributeValue { S = guid.ToString() }; var imgUrlVal = new AttributeValue { S = imgUrl }; var imgUrlLargeVal = new AttributeValue { S = imgUrlLarge }; var req = new PutPointRequest(point, rangeKeyVal); req.PutItemRequest.Item["imgUrl"] = imgUrlVal; req.PutItemRequest.Item["imgUrlLarge"] = imgUrlLargeVal; await _geoDataManager.PutPointAsync(req); } context.Logger.LogLine("Stream processing complete."); return(true.ToString()); }
public async Task <PutPointResult> PutPointAsync(PutPointRequest putPointRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (putPointRequest == null) { throw new ArgumentNullException("putPointRequest"); } var geohash = S2Manager.GenerateGeohash(putPointRequest.FromGeoPoint); var rangeHash = S2Manager.GenerateGeohash(putPointRequest.ToGeoPoint); var hashKey = S2Manager.GenerateHashKey(geohash, _config.HashKeyLength); var geoJson = GeoJsonMapper.StringFromGeoObject(putPointRequest.FromGeoPoint); var putItemRequest = putPointRequest.PutItemRequest; putItemRequest.TableName = _config.TableName; var hashKeyValue = new AttributeValue { N = hashKey.ToString(CultureInfo.InvariantCulture) }; putItemRequest.Item[_config.HashKeyAttributeName] = hashKeyValue; putItemRequest.Item[_config.RangeKeyAttributeName] = new AttributeValue { S = rangeHash.ToString(CultureInfo.InvariantCulture) }; var geohashValue = new AttributeValue { N = geohash.ToString(CultureInfo.InvariantCulture) }; putItemRequest.Item[_config.GeohashAttributeName] = geohashValue; var geoJsonValue = new AttributeValue { S = geoJson }; putItemRequest.Item[_config.GeoJsonAttributeName] = geoJsonValue; PutItemResponse putItemResult = await _config.DynamoDBClient.PutItemAsync(putItemRequest, cancellationToken).ConfigureAwait(false); var putPointResult = new PutPointResult(putItemResult); return(putPointResult); }