Beispiel #1
0
        //private static System.Windows.Shapes.Polyline GetPolyline()
        //{
        //	string text = File.ReadAllText(@"C:\OSM\route.geojson");
        //	GeoJsonModel parsed = JsonConvert.DeserializeObject<GeoJsonModel>(text);
        //	var polyline = new System.Windows.Shapes.Polyline();
        //	foreach (Feature feature in parsed.features)
        //	{
        //		var startingCoordinates = feature.geometry.coordinates[0] as Newtonsoft.Json.Linq.JArray;
        //		//
        //		var startingPoint = new Point((float)startingCoordinates.Last(), (float)startingCoordinates.First());

        //		var endingCoordinates = feature.geometry.coordinates[1] as Newtonsoft.Json.Linq.JArray;
        //		//
        //		var endingPoint = new Point((float)endingCoordinates.Last(), (float)endingCoordinates.First());

        //		polyline.Points.Add(startingPoint);
        //		polyline.Points.Add(endingPoint);
        //	}

        //	return polyline;
        //}

        private static ViewModel.Polyline GetMapControlPolyLine()
        {
            string       text     = File.ReadAllText(@"C:\OSM\route.geojson");
            GeoJsonModel parsed   = JsonConvert.DeserializeObject <GeoJsonModel>(text);
            var          polyline = new ViewModel.Polyline();

            polyline.Locations = new MapControl.LocationCollection();
            foreach (Feature feature in parsed.features)
            {
                if (feature.geometry.coordinates[0] is Newtonsoft.Json.Linq.JArray startingCoordinates)
                {
                    polyline.Locations.Add(new MapControl.Location((float)startingCoordinates.Last(), (float)startingCoordinates.First()));
                }

                if (feature.geometry.coordinates[1] is Newtonsoft.Json.Linq.JArray endingCoordinates)
                {
                    polyline.Locations.Add(new MapControl.Location((float)endingCoordinates.Last(), (float)endingCoordinates.First()));
                }

                //if (feature.geometry.coordinates[0] is double longitude && feature.geometry.coordinates[1] is double latitude)
                //{
                //	polyline.Locations.Add(new MapControl.Location(latitude, longitude));
                //}
            }

            return(polyline);
        }
        public IActionResult GetData()
        {
            var conn = DbService.GetOpenConnection();

            var data = conn.Query("select pinLat, pinLon, theircall from contacts where pinlat is not null and pinlon is not null and theircall not in (select call from badcall);")
                       .Select(d => new LatLonPair(GP, new LatLon((double)d.pinLat, (double)d.pinLon)))
                       .ToArray();

            return(new JsonResult(GeoJsonModel.FromLatLons(
                                      data
                                      )));
        }
Beispiel #3
0
        public ActionResult GetAtmSupermarketInRadius(int radius)
        {
            var atmList = new List <GeoJsonModel>();

            using (var conn = new NpgsqlConnection())
            {
                conn.ConnectionString = "PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;DATABASE=pdtgis;HOST=localhost;USER ID=postgres;PASSWORD=mato777bleskino";
                conn.Open();

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = string.Format("SELECT x.operator,y.name,ST_AsGeoJson(x.way), ST_AsGeoJson(y.way), ST_Distance(Geography(x.way),Geography(y.way)) from planet_osm_point x, planet_osm_point y where(x.amenity = \'atm\' AND x.operator IS NOT NULL) AND(y.shop = \'supermarket\') AND ST_DWithin(Geography(x.way), Geography(y.way), {0})", radius);
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var atm  = new GeoJsonModel();
                            var shop = new GeoJsonModel();
                            atm.type                    = "Feature";
                            atm.properties              = new GeoJsonProperties();
                            atm.properties.name         = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;
                            atm.properties.title        = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;
                            atm.properties.description  = !reader.IsDBNull(4) ? reader.GetDouble(4).ToString() : String.Empty;
                            atm.properties.MarkerSymbol = "bank";
                            atm.properties.MarkerColor  = "#FF0000";
                            atm.geometry                = JsonConvert.DeserializeObject <GeoJsonGeometry>(reader.GetString(2));
                            atmList.Add(atm);

                            shop.type                    = "Feature";
                            shop.properties              = new GeoJsonProperties();
                            shop.properties.name         = !reader.IsDBNull(1) ? reader.GetString(1) : String.Empty;
                            shop.properties.title        = !reader.IsDBNull(1) ? reader.GetString(1) : String.Empty;
                            shop.properties.description  = !reader.IsDBNull(4) ? reader.GetDouble(4).ToString() : String.Empty;
                            shop.properties.MarkerSymbol = "shop";
                            shop.properties.MarkerColor  = "#00FF00";
                            shop.geometry                = JsonConvert.DeserializeObject <GeoJsonGeometry>(reader.GetString(3));
                            atmList.Add(shop);
                        }
                    }
                }
            }

            var geoJsonFeatures = new GeoJsonFeatureCollection();

            geoJsonFeatures.type     = "FeatureCollection";
            geoJsonFeatures.features = atmList;

            return(new JsonDotNetResult(geoJsonFeatures));
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("geojson parser: invalid parameter. Syntax: dotnet run file.json [number-of-samples]");
                return;
            }

            // Parse the panda object
            var jsonInput  = File.ReadAllText(args[0]);
            var modelInput = JsonConvert.DeserializeObject <double[][]>(jsonInput);

            // Calculate the number of elements to skip to meet the sample requirement
            var skip = args.Length > 1 ? modelInput.Length / int.Parse(args[1]) : 1;

            // Create the geo json
            var modelOutput = new GeoJsonModel {
                Type = "FeatureCollection", Features = new List <FeatureModel>(modelInput.Length)
            };

            for (var i = 0; i < modelInput.Length; i++)
            {
                // Skip to obtain the number of samples if specified
                if (i % skip != 0)
                {
                    continue;
                }

                modelOutput.Features.Add(new FeatureModel
                {
                    Type     = "Feature",
                    Geometry = new GeometryModel
                    {
                        Type        = "Point",
                        Coordinates = new[]
                        { modelInput[i][1], modelInput[i][0] }
                    }
                });
            }

            // Create the json and output the result in stdout
            var jsonOutput = JsonConvert.SerializeObject(modelOutput);

            Console.Write(jsonOutput);
        }
Beispiel #5
0
    IEnumerator AddGeoJsonGeometry()
    {
        // 1) get serialised textual geometry data (e.g. read from file)
        var seralised_geometry = InputModel.GetSerialisedGeometry();

        // 2) read serialised geometry (e.g. GeoJson) into list/collection of Vector2[]
        var polygon_dataset = GeoJsonModel.GetPolygonDatasetFromSerialised(seralised_geometry, BOX_RADIUS);

        yield return(null);

        // 3) create GameObjects with meshes from each polygon
        //TODO single gameobject/mesh here...??
        shapes = new List <GameObject>(polygon_dataset.Count);
        var       yield_counter   = 0;
        const int UNITS_PER_YIELD = 64;

        foreach (var polygon_data in polygon_dataset)
        {
            var shape = new GameObject();

            // set shape properties
            var shape_properties = shape.AddComponent <ShapeProperties>();
            shape_properties.PropertiesDict = polygon_data.Item2;
            // can get the name ONLY after dictionary is set
            shape.name = shape_properties.Name;

            // create gameobject including the mesh
            MeshModel.createMeshFromPolygonData(shape, polygon_data.Item1, enable_lighting);

            shape.transform.parent = transform;
            shapes.Add(shape);

            ++yield_counter;
            if (yield_counter >= UNITS_PER_YIELD)
            {
                yield_counter = 0;
                yield return(null);
            }
        }


        yield return(UpdateShapeState(cam_controller.PixToWorld));
    }
Beispiel #6
0
        public ActionResult GetShopsAll()
        {
            var shopList = new List <GeoJsonModel>();

            using (var conn = new NpgsqlConnection())
            {
                conn.ConnectionString = "PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;DATABASE=pdtgis;HOST=localhost;USER ID=postgres;PASSWORD=mato777bleskino";
                conn.Open();

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText =
                        "SELECT name, ST_AsGeoJson(way) FROM planet_osm_point WHERE shop = \'supermarket\' AND name IS NOT NULL";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var shop = new GeoJsonModel();
                            shop.type                    = "Feature";
                            shop.properties              = new GeoJsonProperties();
                            shop.properties.name         = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;
                            shop.properties.title        = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;;
                            shop.properties.MarkerSymbol = "shop";
                            shop.properties.MarkerColor  = "#EB42DF";
                            shop.properties.MarkerSize   = "small";
                            shop.geometry                = JsonConvert.DeserializeObject <GeoJsonGeometry>(reader.GetString(1));
                            shopList.Add(shop);
                        }
                    }
                }
            }

            var geoJsonFeatures = new GeoJsonFeatureCollection();

            geoJsonFeatures.type     = "FeatureCollection";
            geoJsonFeatures.features = shopList;

            return(new JsonDotNetResult(geoJsonFeatures));
        }
Beispiel #7
0
        public ActionResult GetSporAll()
        {
            var sporList = new List <GeoJsonModel>();

            using (var conn = new NpgsqlConnection())
            {
                conn.ConnectionString = "PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;DATABASE=pdtgis;HOST=localhost;USER ID=postgres;PASSWORD=mato777bleskino";
                conn.Open();

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText =
                        "SELECT operator, ST_AsGeoJson(way) FROM planet_osm_point WHERE amenity='atm' AND lower(operator)LIKE '%sporite%'";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var spor = new GeoJsonModel();
                            spor.type                    = "Feature";
                            spor.properties              = new GeoJsonProperties();
                            spor.properties.name         = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;
                            spor.properties.title        = !reader.IsDBNull(0) ? reader.GetString(0) : String.Empty;;
                            spor.properties.MarkerSymbol = "bank";
                            spor.properties.MarkerColor  = "#47ED87";
                            spor.properties.MarkerSize   = "small";
                            spor.geometry                = JsonConvert.DeserializeObject <GeoJsonGeometry>(reader.GetString(1));
                            sporList.Add(spor);
                        }
                    }
                }
            }

            var geoJsonFeatures = new GeoJsonFeatureCollection();

            geoJsonFeatures.type     = "FeatureCollection";
            geoJsonFeatures.features = sporList;

            return(new JsonDotNetResult(geoJsonFeatures));
        }