Example #1
0
        public static Geojson Parse(string text)
        {
            var node   = JSON.Parse(text);
            var result = new Geojson();

            result.type     = node["type"].Value;
            result.features = ParseFeatures(node["features"].AsArray);
            return(result);
        }
Example #2
0
        public LatLngRect FindCoveringLatLngRect(Geojson json)
        {
            var lines = json.features
                        .Where(it => it.geometry.IsLineString())
                        .Select(it => it.geometry.AsLineString());
            var latitudes = lines
                            .SelectMany(line => line.coordinates.Select(it => it.latitude));
            var longitudes = lines
                             .SelectMany(line => line.coordinates.Select(it => it.longitude));

            return(new LatLngRect
            {
                minLatitude = latitudes.Min(),
                maxLatitude = latitudes.Max(),
                minLongitude = longitudes.Min(),
                maxLongitude = longitudes.Max(),
            });
        }
        void Render(Geojson json)
        {
            var latLngRect   = mapUseCase.FindCoveringLatLngRect(json);
            var latLngCenter = latLngRect.getCenter();

            var lines = json.features
                        .Where(it => it.geometry.IsLineString())
                        .Select(it => it.geometry.AsLineString());

            foreach (var line in lines)
            {
                var from   = line.coordinates[0];
                var to     = line.coordinates[1];
                var xyFrom = CoordinateConverter.LatLng2World(latLngCenter, from) * 10;
                var xyTo   = CoordinateConverter.LatLng2World(latLngCenter, to) * 10;
                CreateLine(new[]
                {
                    xyFrom, xyTo
                });
            }
        }
        protected override async Task <Geojson> Process(SalvarGeoJsonCommand request, CancellationToken cancellationToken)
        {
            var repository = _unitOfWork.GetRepository <Geojson>();

            var geojson = new Geojson {
                FileName = request.FileName, Size = request.Size
            };

            var geometrias = request
                             .FeatureCollection
                             .CleanerFeatureCollection()
                             .Select(s => FeatureToGeoJson(s));

            geojson.AddGeometrias(geometrias.ToList());

            await repository.InsertAsync(geojson);

            await _unitOfWork.SaveChangesAsync();

            return(geojson);
        }
Example #5
0
        private async void Map_OnTap(object sender, TapEventArgs e)
        {
            Position _position = new Position();

            _position = e.Position;
            var pin = new Pin
            {
                Type     = PinType.Place,
                Position = e.Position,
                Label    = " Cliked ",
                Address  = e.Position.Latitude + " X " + e.Position.Latitude,
            };

            //  Get Coordinates Polygon as json string then Deserialize it
            var jsonCoordinates = new Geojson().ReadGeoJson(pin);

            Polygons = JsonConvert.DeserializeObject <FeatureCollection>(jsonCoordinates);
            if (Polygons == null)
            {
                DependencyService.Get <SnackBar>().ShowSnackBar("There is no detected area");
                return;
            }
            map.Pins.Add(pin);
            DrawPolygon();
            string result = await DisplayPromptAsync("Info", "if you want to save this area ? enter name it",
                                                     "OK", "CANCEL", keyboard : Keyboard.Text);

            if (result != null)
            {
                Models.Polygon polygon = new Models.Polygon();
                polygon.PolygonName = result;
                polygon.Coordinates = jsonCoordinates;
                polygon.Latitude    = _position.Latitude;
                polygon.Longitude   = _position.Longitude;
                polygonViewModel.AddPolygon(polygon);
                listPolygon.ItemsSource = null;
                listPolygon.ItemsSource = polygonViewModel.Polygons;
            }
        }