Exemple #1
0
        private async Task <List <LineString> > GetLineStringsInArea(LineString gpxItmLine, double tolerance)
        {
            var northEast = _itmWgs84MathTransform.Transform(gpxItmLine.Coordinates.Max(c => c.X) + tolerance, gpxItmLine.Coordinates.Max(c => c.Y) + tolerance);
            var southWest = _itmWgs84MathTransform.Transform(gpxItmLine.Coordinates.Min(c => c.X) - tolerance, gpxItmLine.Coordinates.Min(c => c.Y) - tolerance);
            var highways  = await _elasticSearchGateway.GetHighways(new Coordinate(northEast.x, northEast.y), new Coordinate(southWest.x, southWest.y));

            return(highways.Select(highway => ToItmLineString(highway.Geometry.Coordinates, highway.GetOsmId())).ToList());
        }
        /// <summary>
        /// This is a static function to update the geolocation of a feature for search capabilities
        /// </summary>
        /// <param name="feature"></param>
        private void UpdateLocation(Feature feature)
        {
            Coordinate geoLocation;

            if ((feature.Geometry is LineString || feature.Geometry is MultiLineString) && feature.Geometry.Coordinate != null)
            {
                geoLocation = feature.Geometry.Coordinate;
            }
            else if (feature.Geometry.Centroid == null || feature.Geometry.Centroid.IsEmpty)
            {
                return;
            }
            else
            {
                geoLocation = feature.Geometry.Centroid.Coordinate;
            }
            feature.Attributes.Add(FeatureAttributes.POI_GEOLOCATION, new AttributesTable
            {
                { FeatureAttributes.LAT, geoLocation.Y },
                { FeatureAttributes.LON, geoLocation.X }
            });
            feature.Attributes.Add(FeatureAttributes.POI_ALT, _elevationDataStorage.GetElevation(geoLocation).Result);
            var northEast = _wgs84ItmConverter.Transform(geoLocation.X, geoLocation.Y);

            feature.Attributes.Add(FeatureAttributes.POI_ITM_EAST, northEast.x);
            feature.Attributes.Add(FeatureAttributes.POI_ITM_NORTH, northEast.y);
        }
        /// <inheritdoc/>
        protected override Coordinate GetCoordinates(Match itmMatch)
        {
            var easting  = int.Parse(itmMatch.Groups[1].Value);
            var northing = int.Parse(itmMatch.Groups[2].Value);

            if (northing >= 1350000)
            {
                return(null);
            }
            if (northing < 350000)
            {
                easting  = easting + 50000;
                northing = northing + 500000;
            }
            else if (northing > 850000)
            {
                easting  = easting + 50000;
                northing = northing - 500000;
            }
            if (easting >= 100000 && easting <= 300000)
            {
                var transformed = _itmWgs84MathTransform.Transform(easting, northing);
                return(new Coordinate(transformed.x, transformed.y));
            }
            return(null);
        }
        private async Task RebuildPointsOfInterest()
        {
            _logger.LogInformation("Starting rebuilding POIs database.");
            var osmSource       = _pointsOfInterestAdapterFactory.GetBySource(Sources.OSM);
            var osmFeaturesTask = osmSource.GetPointsForIndexing();
            var sources         = _pointsOfInterestAdapterFactory.GetAll().Where(s => s.Source != Sources.OSM).Select(s => s.Source);
            var otherTasks      = sources.Select(s => _elasticSearchGateway.GetExternalPoisBySource(s));
            await Task.WhenAll(new Task[] { osmFeaturesTask }.Concat(otherTasks));

            var features = _featuresMergeExecutor.Merge(osmFeaturesTask.Result.Concat(otherTasks.SelectMany(t => t.Result)).ToList());

            foreach (var feature in features)
            {
                var geoLocation = feature.Attributes[FeatureAttributes.POI_GEOLOCATION] as AttributesTable;
                feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, await _elevationDataStorage.GetElevation(
                                                   new Coordinate((double)geoLocation[FeatureAttributes.LON], (double)geoLocation[FeatureAttributes.LAT]))
                                               );
                var northEast = _mathTransform.Transform((double)geoLocation[FeatureAttributes.LON], (double)geoLocation[FeatureAttributes.LAT]);
                feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_EAST, (int)northEast.x);
                feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_NORTH, (int)northEast.y);
            }
            await _elasticSearchGateway.UpdatePointsOfInterestZeroDownTime(features);

            _logger.LogInformation("Finished rebuilding POIs database.");
        }
        private async Task <List <Feature> > GetHighwaysInArea(LineString line)
        {
            var northEast = _wgs84ItmMathTransform.Transform(line.Coordinates.Max(c => c.X), line.Coordinates.Max(c => c.Y));
            var southWest = _wgs84ItmMathTransform.Transform(line.Coordinates.Min(c => c.X), line.Coordinates.Min(c => c.Y));

            // adding tolerance perimiter to find ways.
            northEast.y += _options.MinimalDistanceToClosestPoint;
            northEast.x += _options.MinimalDistanceToClosestPoint;
            southWest.y -= _options.MinimalDistanceToClosestPoint;
            southWest.x -= _options.MinimalDistanceToClosestPoint;
            var northEastLatLon = _itmWgs84MathTransform.Transform(northEast.x, northEast.y);
            var southWestLatLon = _itmWgs84MathTransform.Transform(southWest.x, southWest.y);

            var highways = await _elasticSearchGateway.GetHighways(new Coordinate(northEastLatLon.x, northEastLatLon.y), new Coordinate(southWestLatLon.x, southWestLatLon.y));

            return(highways.ToList());
        }
        public NorthEast GetItmCoordinates(double lat, double lon)
        {
            var coordiante = _wgs84ItmMathTransform.Transform(lon, lat);

            return(new NorthEast {
                East = (int)coordiante.x, North = (int)coordiante.y
            });
        }
Exemple #7
0
        /// <summary>
        /// Getting a straight line between two points.
        /// Since the elevation resultion is 30 meters there's no need to sample distances that are
        /// less than 30 meters. Maximal total points is 30 to limit the response size.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private LineString GetDenseStraightLine(Coordinate from, Coordinate to)
        {
            var itmFrom = _wgs84ItmMathTransform.Transform(from.X, from.Y);
            var itmTo   = _wgs84ItmMathTransform.Transform(to.X, to.Y);
            var samples = (int)Math.Min(new Point(itmFrom.x, itmFrom.y).Distance(new Point(itmTo.x, itmTo.y)) / 30, 30);

            if (samples == 0)
            {
                return(_geometryFactory.CreateLineString(new[] { from, to }) as LineString);
            }
            var coordinates = Enumerable.Range(0, samples + 1).Select(s => new CoordinateZ(
                                                                          (to.X - from.X) * s / samples + from.X,
                                                                          (to.Y - from.Y) * s / samples + from.Y,
                                                                          0)
                                                                      );

            return(_geometryFactory.CreateLineString(coordinates.ToArray()) as LineString);
        }
Exemple #8
0
        private LineString ToItmLineString(IEnumerable <Coordinate> coordinates, long id)
        {
            var itmCoordinates = coordinates.Select(c => _wgs84ItmMathTransform.Transform(c.X, c.Y))
                                 .Select(c => new Coordinate(Math.Round(c.x, 1), Math.Round(c.y, 1)))
                                 .ToArray();
            var line = _geometryFactory.CreateLineString(itmCoordinates) as LineString;

            line.SetOsmId(id);
            return(line);
        }
Exemple #9
0
        public override Point LocationToPoint(Location location)
        {
            if (MathTransform == null)
            {
                throw new InvalidOperationException("The CoordinateSystem property is not set.");
            }

            var coordinate = MathTransform.Transform(new Coordinate(location.Longitude, location.Latitude));

            return(new Point(coordinate.X, coordinate.Y));
        }
        /// <summary>
        /// Adds extended data to point of interest object
        /// </summary>
        /// <param name="feature">The features to convert</param>
        /// <param name="language">the user interface language</param>
        /// <returns></returns>
        private async Task <PointOfInterestExtended> ConvertToPoiExtended(Feature feature, string language)
        {
            var poiItem = ConvertToPoiItem <PointOfInterestExtended>(feature, language);

            await SetDataContainerAndLength(poiItem, feature);

            poiItem.References = GetReferences(feature, language);
            poiItem.ImagesUrls = feature.Attributes.GetNames()
                                 .Where(n => n.StartsWith(FeatureAttributes.IMAGE_URL))
                                 .Select(n => feature.Attributes[n].ToString())
                                 .Where(n => !string.IsNullOrWhiteSpace(n))
                                 .ToArray();
            poiItem.Description  = feature.Attributes.GetByLanguage(FeatureAttributes.DESCRIPTION, language);
            poiItem.IsEditable   = false;
            poiItem.Contribution = GetContribution(feature.Attributes);
            var itmCoordinate = _wgs84ItmMathTransform.Transform(poiItem.Location.Lng, poiItem.Location.Lat);

            poiItem.ItmCoordinates = new NorthEast {
                East = (int)itmCoordinate.x, North = (int)itmCoordinate.y
            };
            return(poiItem);
        }
        private LineString ToWgs84LineString(IEnumerable <Coordinate> coordinates)
        {
            var wgs84Coordinates = coordinates.Select(c => _itmWgs84MathTransform.Transform(c.X, c.Y)).Select(c => new Coordinate(c.x, c.y));
            var nonDuplicates    = new List <Coordinate>();

            foreach (var coordinate in wgs84Coordinates)
            {
                if (nonDuplicates.Count <= 0 || !nonDuplicates.Last().Equals2D(coordinate))
                {
                    nonDuplicates.Add(coordinate);
                }
            }
            return(_geometryFactory.CreateLineString(nonDuplicates.ToArray()));
        }
 public void SoAOneByOne()
 {
     _xs.CopyTo(_xsCopy.AsSpan());
     _ys.CopyTo(_ysCopy.AsSpan());
     for (int i = 0; i < _cnt; i++)
     {
         WGS84ToWebMercator.Transform(ref _xsCopy[i], ref _ysCopy[i]);
     }
 }
Exemple #13
0
        public async Task <IActionResult> PostRebuildSource(string source)
        {
            if (!GetSources().Contains(source) && source != "all")
            {
                return(NotFound($"Source {source} does not exist"));
            }
            var sources = source == "all" ? GetSources() : new[] { source };

            foreach (var currentSource in sources)
            {
                _logger.LogInformation($"Starting rebuilding {currentSource}, getting points...");
                var adapter = _adaptersFactory.GetBySource(currentSource);
                var points  = await adapter.GetPointsForIndexing();

                _logger.LogInformation($"Got {points.Count} points for {currentSource}");
                var fullPoints = new ConcurrentBag <FeatureCollection>();
                await _elasticSearchGateway.DeleteExternalPoisBySource(currentSource);

                var counter = 0;
                Parallel.For(0, points.Count, new ParallelOptions {
                    MaxDegreeOfParallelism = 10
                }, (index) =>
                {
                    try
                    {
                        var feature               = adapter.GetRawPointOfInterestById(points[index].Attributes[FeatureAttributes.ID].ToString()).Result;
                        var geoLocation           = feature.Attributes[FeatureAttributes.POI_GEOLOCATION] as AttributesTable;
                        var geoLocationCoordinate = new Coordinate((double)geoLocation[FeatureAttributes.LON], (double)geoLocation[FeatureAttributes.LAT]);
                        feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ALT, _elevationDataStorage.GetElevation(geoLocationCoordinate).Result);
                        var northEast = _wgs84ItmTransform.Transform(geoLocationCoordinate.X, geoLocationCoordinate.Y);
                        feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_EAST, (int)northEast.x);
                        feature.Attributes.AddOrUpdate(FeatureAttributes.POI_ITM_NORTH, (int)northEast.y);
                        _elasticSearchGateway.AddExternalPoi(feature);
                        Interlocked.Increment(ref counter);
                        if (counter % 100 == 0)
                        {
                            _logger.LogInformation($"Indexed {counter} points of {points.Count} for {currentSource}");
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"failed to index point with title: {points[index].GetTitle(Languages.ALL)} for {currentSource} with exception: {ex.ToString()}");
                    }
                });
                _logger.LogInformation($"Finished rebuilding {currentSource}, indexed {points.Count} points.");
                // HM TODO: set rebuild date for source somehow...
            }
            return(Ok());
        }
        private LineString ToItmLineString(IEnumerable <GpxWaypoint> waypoints)
        {
            var coordinates = waypoints.Select(waypoint => _wgs84ItmMathTransform.Transform(waypoint.Longitude, waypoint.Latitude))
                              .Select(c => new Coordinate(Math.Round(c.x, 1), Math.Round(c.y, 1)));
            var nonDuplicates = new List <Coordinate>();

            foreach (var coordinate in coordinates)
            {
                if (nonDuplicates.Count <= 0 || !nonDuplicates.Last().Equals2D(coordinate))
                {
                    nonDuplicates.Add(coordinate);
                }
            }
            return(_geometryFactory.CreateLineString(nonDuplicates.ToArray()));
        }
Exemple #15
0
        public void ParseAffineTransformWkt()
        {
            //TODO MathTransformFactory fac = new MathTransformFactory ();
            MathTransform mt  = null;
            string        wkt = "PARAM_MT[\"Affine\"," +
                                "PARAMETER[\"num_row\",3]," +
                                "PARAMETER[\"num_col\",3]," +
                                "PARAMETER[\"elt_0_0\", 0.883485346527455]," +
                                "PARAMETER[\"elt_0_1\", -0.468458794848877]," +
                                "PARAMETER[\"elt_0_2\", 3455869.17937689]," +
                                "PARAMETER[\"elt_1_0\", 0.468458794848877]," +
                                "PARAMETER[\"elt_1_1\", 0.883485346527455]," +
                                "PARAMETER[\"elt_1_2\", 5478710.88035753]," +
                                "PARAMETER[\"elt_2_2\", 1]]";

            try
            {
                //TODO replace with MathTransformFactory implementation
                mt = MathTransformWktReader.Parse(wkt);
            }
            catch (Exception ex)
            {
                Assert.Fail("Could not create affine math transformation from:\r\n" + wkt + "\r\n" + ex.Message);
            }

            Assert.IsNotNull(mt);
            Assert.IsNotNull(mt as AffineTransform);

            Assert.AreEqual(2, mt.DimSource);
            Assert.AreEqual(2, mt.DimTarget);

            //test simple transform
            double[] outPt = mt.Transform(new double[] { 0.0, 0.0 });

            Assert.AreEqual(2, outPt.Length);
            Assert.AreEqual(3455869.17937689, outPt[0], 0.00000001);
            Assert.AreEqual(5478710.88035753, outPt[1], 0.00000001);
        }
Exemple #16
0
 private Coordinate[] ToWgs84Coordinates(IEnumerable <LatLng> latLngs)
 {
     return(latLngs.Select(latLng => _wgs84ItmMathTransform.Transform(latLng.Lng, latLng.Lat)).Select(c => new Coordinate(c.x, c.y)).ToArray());
 }
Exemple #17
0
 /// <summary>
 /// 根据XY坐标数组进行转换
 /// </summary>
 /// <param name="fromXy"></param>
 /// <returns></returns>
 public double[] Transform(double[] fromXy)
 {
     return(_mathTransform.Transform(fromXy));
 }