コード例 #1
1
        public void FeatureCollectionSerialization()
        {
            var model = new FeatureCollection();
            for (var i = 10; i-- > 0;)
            {
                var geom = new LineString(new[]
                {
                    new GeographicPosition(51.010, -1.034), 
                    new GeographicPosition(51.010, -0.034)
                });

                var props = new Dictionary<string, object>
                {
                    { "test1", "1" }, 
                    { "test2", 2 }
                };

                var feature = new Net.Feature.Feature(geom, props);
                model.Features.Add(feature);
            }

            var actualJson = JsonConvert.SerializeObject(model);

            Assert.IsNotNull(actualJson);

            Assert.IsFalse(string.IsNullOrEmpty(actualJson));
        }
コード例 #2
0
        public void Can_Serialize_LineString_Feature()
        {
            var coordinates = new[]
            {
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.889259338378906),
                    new GeographicPosition(52.3711451105601, 4.895267486572266),
                    new GeographicPosition(52.36931095278263, 4.892091751098633),
                    new GeographicPosition(52.370725881211314, 4.889259338378906)
                },
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.989259338378906),
                    new GeographicPosition(52.3711451105601, 4.995267486572266),
                    new GeographicPosition(52.36931095278263, 4.992091751098633),
                    new GeographicPosition(52.370725881211314, 4.989259338378906)
                }
            };

            var geometry = new LineString(coordinates[0]);

            
            var actualJson = JsonConvert.SerializeObject(new Net.Feature.Feature(geometry));

            Console.WriteLine(actualJson);

            var expectedJson = GetExpectedJson();

            JsonAssert.AreEqual(expectedJson, actualJson);
        }
コード例 #3
0
ファイル: RoutingController.cs プロジェクト: nonZero/Site
 //GET /api/routing?from=31.8239,35.0375&to=31.8213,35.0965&type=f
 public async Task<IHttpActionResult> GetRouting(string from, string to, string type)
 {
     LineString lineString;
     var profile = ConvertProfile(type);
     if (profile == ProfileType.None)
     {
         var pointFrom = GetGeographicPosition(from);
         var pointTo = GetGeographicPosition(to);
         if (ModelState.IsValid == false)
         {
             return BadRequest(ModelState);
         }
         lineString = new LineString(new[] { pointFrom, pointTo });
     }
     else
     {
         lineString = await _routingGateway.GetRouting(new RoutingGatewayRequest
         {
             From = from,
             To = to,
             Profile = profile,
         });
     }
     var feature = new Feature(lineString, new FeatureProperties { Name = "Routing from " + from + " to " + to + " profile type: " + profile.ToString(), Creator = "IsraelHiking" });
     return Ok(new FeatureCollection(new List<Feature>() { feature }));
 }
コード例 #4
0
        public void FeatureSerialization()
        {
            var coordinates = new[]
            {
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.889259338378906),
                    new GeographicPosition(52.3711451105601, 4.895267486572266),
                    new GeographicPosition(52.36931095278263, 4.892091751098633),
                    new GeographicPosition(52.370725881211314, 4.889259338378906)
                },
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.989259338378906),
                    new GeographicPosition(52.3711451105601, 4.995267486572266),
                    new GeographicPosition(52.36931095278263, 4.992091751098633),
                    new GeographicPosition(52.370725881211314, 4.989259338378906)
                },
            };

            var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
            IGeometryObject geometry;

            geometry = new LineString(coordinates[0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 1, coordinates[0]);

            geometry = new Point(coordinates[0][0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 0, coordinates[0].Take(1).ToArray());

            geometry = new MultiLineString(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);

            geometry = new Polygon(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);
        }
コード例 #5
0
        private static JGeometry.LineString Points2LineString(List <PointD> points)
        {
            List <JGeometry.IPosition> ipositions = new List <JGeometry.IPosition>();
            var positions = (from point in points select new JGeometry.GeographicPosition(point.Y, point.X)).ToList();

            ipositions.AddRange(positions);
            JGeometry.LineString lineString = new JGeometry.LineString(ipositions);
            return(lineString);
        }
コード例 #6
0
 private LineString GetLineString(double offset = 0.0)
 {
     var coordinates = new List<IPosition>
     {
         new GeographicPosition(52.379790828551016 + offset, 5.3173828125 + offset),
         new GeographicPosition(52.36721467920585 + offset, 5.456085205078125 + offset),
         new GeographicPosition(52.303440474272755 + offset, 5.386047363281249 + offset, 4.23 + offset)
     };
     var lineString = new LineString(coordinates);
     return lineString;
 }
コード例 #7
0
        public static PointF[] ToGdi(LineString lineString)
        {
            var result = new List<PointF>();

            foreach (var coordinate in lineString.Coordinates)
            {
                var position = (GeographicPosition) coordinate;
                result.Add(SphericalMercator.FromLonLat(position.Longitude, position.Latitude));
            }
            return result.ToArray();
        }
コード例 #8
0
ファイル: MiscTest.cs プロジェクト: Cobster/GeoJSON.Net
        public void LineStringIsClosed() 
        {
            var coordinates = new List<GeographicPosition> 
            { 
                new GeographicPosition(52.370725881211314, 4.889259338378906), 
                new GeographicPosition(52.3711451105601, 4.895267486572266), 
                new GeographicPosition(52.36931095278263, 4.892091751098633), 
                new GeographicPosition(52.370725881211314, 4.889259338378906) 
            }.ToList<IPosition>();

            var lineString = new LineString(coordinates);
        }
コード例 #9
0
        private static LineString ToCoords(IBasicGeometry ls)
        {
            List <GeographicPosition> p = new List <GeographicPosition>();

            foreach (Coordinate point in ls.Coordinates)
            {
                p.Add(new GeographicPosition(point.Y, point.X));
            }
            var points = new LineString(p);

            return(points);
        }
コード例 #10
0
        public void Is_Not_Closed()
        {
            var coordinates = new List<GeographicPosition>
            {
                new GeographicPosition(52.370725881211314, 4.889259338378906),
                new GeographicPosition(52.3711451105601, 4.895267486572266),
                new GeographicPosition(52.36931095278263, 4.892091751098633),
                new GeographicPosition(52.370725881211592, 4.889259338378955)
            };

            var lineString = new LineString(coordinates);

            Assert.IsFalse(lineString.IsClosed());
        }
コード例 #11
0
        public static GeoJSON.Net.Geometry.LineString MakeClosedLinearRing(GeoJSON.Net.Geometry.LineString lineString)
        {
            if (!lineString.IsClosed())
            {
                var positions = new List <Position>();
                foreach (var coordinate in lineString.Coordinates)
                {
                    positions.Add((Position)coordinate);
                }
                // Add first position also as last position
                positions.Add((Position)lineString.Coordinates[0]);
                lineString = new GeoJSON.Net.Geometry.LineString(positions);
            }

            return(lineString);
        }
コード例 #12
0
        public void Can_Serialize()
        {
            var coordinates = new List<GeographicPosition>
            {
                new GeographicPosition(52.370725881211314, 4.889259338378906),
                new GeographicPosition(52.3711451105601, 4.895267486572266),
                new GeographicPosition(52.36931095278263, 4.892091751098633),
                new GeographicPosition(52.370725881211314, 4.889259338378906)
            };

            var lineString = new LineString(coordinates);

            var actualJson = JsonConvert.SerializeObject(lineString);

            JsonAssert.AreEqual(GetExpectedJson(), actualJson);
        }
コード例 #13
0
ファイル: ImporterController.cs プロジェクト: jjasloot/OVDB
        private FeatureCollection CoordsToGeoJson(List <IPosition> coordinates)
        {
            if (!coordinates.Any())
            {
                return(null);
            }
            var coords = coordinates.Select(r => new Position(r.Latitude, r.Longitude)).ToList();
            var geo    = new GeoJSON.Net.Geometry.LineString(coords);

            var feature           = new GeoJSON.Net.Feature.Feature(geo);
            var featureCollection = new FeatureCollection(new List <Feature> {
                feature
            });

            return(featureCollection);
        }
コード例 #14
0
        /// <summary>
        /// closes any rings
        /// </summary>
        /// <param name="points"></param>
        public PolygonBuilder(List<IPosition> outerRingPoints)
        {
            if (outerRingPoints.Count <= 3)
                throw new ArgumentException("Must have more than 2 points for a polygon", "points");

            LineString ring = new LineString(outerRingPoints);

            if (!ring.IsClosed())
                ring.Coordinates.Add(ring.Coordinates[0]);

            List<LineString> lines = new List<LineString>();

            lines.Add(ring);
            
            _polygon = new Polygon(lines);

        }
コード例 #15
0
        private FeatureCollection GetFeatureCollection()
        {
            var model = new FeatureCollection();
            for (var i = 10; i-- > 0;)
            {
                var geom = new LineString(new[]
                {
                    new GeographicPosition(51.010, -1.034),
                    new GeographicPosition(51.010, -0.034)
                });

                var props = FeatureTests.GetPropertiesInRandomOrder();

                var feature = new Net.Feature.Feature(geom, props);
                model.Features.Add(feature);
            }
            return model;
        }
コード例 #16
0
        private async Task GetLineStringData()
        {
            var road = await _dbContext.Roads.FirstOrDefaultAsync();

            //Geometry to geoJSON
            var coordinates = new List <IPosition>();

            foreach (var item in road.Line.Coordinates)
            {
                coordinates.Add(new Position(item.X, item.Y, item.Z));
            }
            GeoJSON.Net.Geometry.LineString line = new GeoJSON.Net.Geometry.LineString(coordinates);
            var s = JsonConvert.SerializeObject(line);
            //Geometry to wkt
            var s2 = NetTopologySuite.IO.WKTWriter.ToLineString(road.Line.CoordinateSequence);

            Console.WriteLine($"GeoJSON结果:{s},WKT结果:{s2}");
        }
コード例 #17
0
        public static Feature Parse(Tile.Feature feature, List<string> keys, List<Tile.Value> values, int x, int y, int z, uint extent, bool convertToGeographicPosition)
        {
            Feature result = null;
            var geom = GeometryParser.ParseGeometry(feature.Geometry, feature.Type);
            var id = feature.Id;

            var positions= convertToGeographicPosition?
                geom.Select(p => p.ToGeographicPosition(x,y,z,extent)).ToList():
                geom.Select(p => new GeographicPosition(p.Latitude, p.Longitude)).ToList();

            var coordinates = positions.ToList<IPosition>();
            if (feature.Type == Tile.GeomType.Polygon)
            {
                if (coordinates.Count > 3)
                {
                    var polygon = new Polygon(new List<LineString> {new LineString(coordinates)});
                    result = new Feature(polygon);
                }
            }
            else if (feature.Type == Tile.GeomType.LineString)
            {
                var ls = new LineString(coordinates);
                result = new Feature(ls);
            }
            else if (feature.Type == Tile.GeomType.Point)
            {
                var pt = new Point(coordinates[0]);
                result = new Feature(pt);

            }

            if (result != null)
            {
                result.Id = id.ToString(CultureInfo.InvariantCulture);
                var attributes = AttributesParser.Parse(keys, values, feature.Tags);
                foreach (var item in attributes)
                {
                    result.Properties.Add(item.Key, item.Value);
                }

            }
            return result;
        }
コード例 #18
0
        public IActionResult GetRoad(int roadId)
        {
            var road = _dbContext.Roads.FirstOrDefault(x => x.RoadID == roadId);

            if (road == null)
            {
                return(Json($"查询不到id为{roadId}的道路"));
            }

            //Geometry to GeoJSON
            var coordinates = new List <IPosition>();

            foreach (var item in road.Line.Coordinates)
            {
                coordinates.Add(new Position(item.X, item.Y, item.Z));
            }
            GeoJSON.Net.Geometry.LineString line = new GeoJSON.Net.Geometry.LineString(coordinates);
            var s = JsonConvert.SerializeObject(line);
            //Geometry to wkt
            var s2 = NetTopologySuite.IO.WKTWriter.ToLineString(road.Line.CoordinateSequence);

            return(Json($"GeoJSON结果:{s},WKT结果:{s2}"));
        }
コード例 #19
0
        public static AgGateway.ADAPT.ApplicationDataModel.Shapes.LinearRing MapLineString(GeoJSON.Net.Geometry.LineString lineString, AffineTransformation affineTransformation = null)
        {
            // ToDo: [Check] if the LineString is actually a LinearRing
            var linearRing = new AgGateway.ADAPT.ApplicationDataModel.Shapes.LinearRing();

            foreach (var position in lineString.Coordinates)
            {
                linearRing.Points.Add(PointMapper.MapPosition(position, affineTransformation));
            }

            return(linearRing);
        }
コード例 #20
0
        public void FeatureCollection_Test_IndexOf()
        {
            var model = new FeatureCollection();
            var expectedIds = new List<string>();
            var expectedIndexes = new List<int>();

            for (var i = 0; i < 10; i++)
            {
                var id = "id" + i.ToString();

                expectedIds.Add(id);
                expectedIndexes.Add(i);

                var geom = new LineString(new[]
                {
                    new GeographicPosition(51.010, -1.034),
                    new GeographicPosition(51.010, -0.034)
                });

                var props = FeatureTests.GetPropertiesInRandomOrder();

                var feature = new Net.Feature.Feature(geom, props, id);
                model.Features.Add(feature);
            }

            for (var i = 0; i < 10; i++)
            {
                var actualFeature = model.Features[i];
                var actualId = actualFeature.Id;
                var actualIndex = model.Features.IndexOf(actualFeature);

                var expectedId = expectedIds[i];
                var expectedIndex = expectedIndexes[i];

                Assert.AreEqual(expectedId, actualId);
                Assert.AreEqual(expectedIndex, actualIndex);
            }
        }
コード例 #21
0
 protected bool Equals(LineString other)
 {
     return(base.Equals(other) && Coordinates.SequenceEqual(other.Coordinates));
 }
コード例 #22
0
 private LineString GetLineString(double offset = 0.0)
 {
     var coordinates = new List<GeographicPosition>
     {
         new GeographicPosition(52.370725881211314 + offset, 4.889259338378906 + offset),
         new GeographicPosition(52.3711451105601 + offset, 4.895267486572266 + offset),
         new GeographicPosition(52.36931095278263 + offset, 4.892091751098633 + offset),
         new GeographicPosition(52.370725881211314 + offset, 4.889259338378906 + offset)
     };
     var lineString = new LineString(coordinates);
     return lineString;
 }
コード例 #23
0
 private static Polygon GetPolygon(List<List<GeographicPosition>> lines)
 {
     var res = new List<LineString>();
     foreach (var innerring in lines)
     {
         var line = new LineString(innerring);
         if (line.IsLinearRing() && line.IsClosed())
         {
             res.Add(line);
         }
     }
     var geom = new Polygon(res);
     return geom;
 }
コード例 #24
0
ファイル: GeoJSONController.cs プロジェクト: jjasloot/OVDB
        public void Test()
        {
            var route      = new Route();
            var collection = new FeatureCollection();
            var multi      = route.Coordinates.Split("###").ToList();
            var lines      = new List <GeoJSON.Net.Geometry.LineString>();

            multi.ForEach(block =>
            {
                var coordinates = block.Split('\n').Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                var coords      = coordinates.Select(r => new Position(double.Parse(r.Split(',')[1], CultureInfo.InvariantCulture), double.Parse(r.Split(',')[0], CultureInfo.InvariantCulture))).ToList();
                if (coords.Count >= 2)
                {
                    var geo = new GeoJSON.Net.Geometry.LineString(coords);
                    lines.Add(geo);
                }
            });
            GeoJSON.Net.Feature.Feature feature;
            if (lines.Count == 1)
            {
                feature = new GeoJSON.Net.Feature.Feature(lines.Single());
            }
            else
            {
                var multiLineString = new MultiLineString(lines);
                feature = new GeoJSON.Net.Feature.Feature(multiLineString);
            }
            if (!string.IsNullOrWhiteSpace(route.Name))
            {
                feature.Properties.Add("name", route.Name);
            }
            if (!string.IsNullOrWhiteSpace(route.NameNL))
            {
                feature.Properties.Add("nameNL", route.NameNL);
            }
            if (!string.IsNullOrWhiteSpace(route.Description))
            {
                feature.Properties.Add("description", route.Description);
            }
            if (!string.IsNullOrWhiteSpace(route.DescriptionNL))
            {
                feature.Properties.Add("descriptionNL", route.DescriptionNL);
            }
            if (route.FirstDateTime.HasValue)
            {
                feature.Properties.Add("firstDateTime", route.FirstDateTime.Value.ToString("o"));
            }
            if (!string.IsNullOrWhiteSpace(route.LineNumber))
            {
                feature.Properties.Add("lineNumber", route.LineNumber);
            }
            if (!string.IsNullOrWhiteSpace(route.OperatingCompany))
            {
                feature.Properties.Add("operatingCompany", route.OperatingCompany);
            }
            if (!string.IsNullOrWhiteSpace(route.OverrideColour))
            {
                feature.Properties.Add("name", route.OverrideColour);
            }
            if (route.RouteCountries.Any())
            {
                feature.Properties.Add("countries", string.Join(',', route.RouteCountries.Select(c => c.Country.Name)));
            }
            if (route.RouteMaps.Any())
            {
                feature.Properties.Add("maps", string.Join(',', route.RouteMaps.Select(c => c.Map.Name)));
            }
            if (route.RouteTypeId.HasValue)
            {
                feature.Properties.Add("type", route.RouteType.Name);
            }
            collection.Features.Add(feature);
        }
コード例 #25
0
        private static IGeometryObject GetLineGeometry(List<List<GeographicPosition>> pointList)
        {
            IGeometryObject geom;

            if (pointList.Count == 1)
            {
                geom = new LineString(pointList[0]);
            }
            else
            {
                geom = new MultiLineString(GetLineStringList(pointList));
            }
            return geom;
        }
コード例 #26
0
        public async Task <ActionResult <FeatureCollection> > GetSingleRouteGeoJsonAsync(int id, Guid guid, [FromQuery] string language)
        {
            var route = await _context.Routes.Include(r => r.RouteType).Include(r => r.RouteCountries).SingleOrDefaultAsync(r =>
                                                                                                                            r.RouteId == id &&
                                                                                                                            r.Share == guid);

            if (route == null)
            {
                return(NotFound());
            }


            var collection = new FeatureCollection();

            var multi = route.Coordinates.Split("###").ToList();
            var lines = new List <GeoJSON.Net.Geometry.LineString>();

            multi.ForEach(block =>
            {
                var coordinates = block.Split('\n').Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                var coords      = coordinates.Select(r => new Position(double.Parse(r.Split(',')[1], CultureInfo.InvariantCulture), double.Parse(r.Split(',')[0], CultureInfo.InvariantCulture))).ToList();
                if (coords.Count >= 2)
                {
                    var geo = new GeoJSON.Net.Geometry.LineString(coords);
                    lines.Add(geo);
                }
            });
            GeoJSON.Net.Feature.Feature feature;
            if (lines.Count == 1)
            {
                feature = new GeoJSON.Net.Feature.Feature(lines.Single());
            }
            else
            {
                var multiLineString = new MultiLineString(lines);
                feature = new GeoJSON.Net.Feature.Feature(multiLineString);
            }
            if (language == "nl" && !string.IsNullOrWhiteSpace(route.NameNL))
            {
                feature.Properties.Add("name", route.NameNL);
            }
            else
            {
                feature.Properties.Add("name", route.Name);
            }
            if (language == "nl" && !string.IsNullOrWhiteSpace(route.RouteType.NameNL))
            {
                feature.Properties.Add("type", route.RouteType?.NameNL);
            }
            else
            {
                feature.Properties.Add("type", route.RouteType?.Name);
            }
            if (language == "nl" && !string.IsNullOrWhiteSpace(route.DescriptionNL))
            {
                feature.Properties.Add("description", route.DescriptionNL);
            }
            else
            {
                feature.Properties.Add("description", route.Description ?? "Unknown");
            }
            feature.Properties.Add("lineNumber", route.LineNumber);
            feature.Properties.Add("operatingCompany", route.OperatingCompany);;
            if (!string.IsNullOrWhiteSpace(route.OverrideColour))
            {
                feature.Properties.Add("stroke", route.OverrideColour);
            }
            else
            {
                feature.Properties.Add("stroke", route.RouteType?.Colour ?? "#000");
            }

            collection.Features.Add(feature);

            return(collection);
        }
コード例 #27
0
        public async Task <ActionResult <FeatureCollection> > GetGeoJsonAsync(string id, ODataQueryOptions <RouteInstance> q, [FromQuery] string language)
        {
            var userClaim   = User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
            var userIdClaim = int.Parse(userClaim != null ? userClaim.Value : "-1");

            var guid = Guid.Parse(id);
            var map  = await _context.Maps.SingleOrDefaultAsync(m => m.MapGuid == guid);

            if (map == null)
            {
                return(NotFound());
            }
            if (string.IsNullOrWhiteSpace(map.SharingLinkName))
            {
                if (!User.Claims.Any())
                {
                    return(Forbid());
                }
                var adminClaim = (User.Claims.SingleOrDefault(c => c.Type == "admin").Value ?? "false");

                if ((userIdClaim < 0 || map.UserId != userIdClaim) && !string.Equals(adminClaim, "true", StringComparison.OrdinalIgnoreCase))
                {
                    return(Forbid());
                }
            }

            var routes = _context.RouteInstances
                         .Include(ri => ri.Route)
                         .ThenInclude(r => r.RouteType)
                         .AsQueryable();

            var types = await _context.RouteTypes.ToListAsync();

            var colours = new Dictionary <int, LineStyle>();

            types.ForEach(t =>
            {
                colours.Add(t.TypeId, new LineStyle {
                    Color = Color32.Parse(t.Colour)
                });
            });

            if (q.Filter != null)
            {
                var                  model  = Startup.GetEdmModel();
                IEdmType             type   = model.FindDeclaredType("OVDB_database.Models.RouteInstance");
                IEdmNavigationSource source = model.FindDeclaredEntitySet("Products");
                var                  parser = new ODataQueryOptionParser(model, type, source, new Dictionary <string, string> {
                    { "$filter", q.Filter.RawValue }
                });
                var context = new ODataQueryContext(model, typeof(RouteInstance), q.Context.Path);
                var filter  = new FilterQueryOption(q.Filter.RawValue, context, parser);
                routes = q.Filter.ApplyTo(routes, new ODataQuerySettings()) as IQueryable <RouteInstance>;
            }
            routes = routes.Where(r => r.RouteInstanceMaps.Any(rim => rim.MapId == map.MapId) || r.Route.RouteMaps.Any(rm => rm.MapId == map.MapId));
            var collection     = new FeatureCollection();
            var routesList     = new List <Route>();
            var routesToReturn = new Dictionary <int, int>();
            await routes.ForEachAsync(r =>
            {
                if (!routesToReturn.ContainsKey(r.RouteId))
                {
                    routesToReturn.Add(r.RouteId, 0);
                    routesList.Add(r.Route);
                }
                routesToReturn[r.RouteId] += 1;
            });


            routesList.ForEach(r =>
            {
                try
                {
                    var multi = r.Coordinates.Split("###").ToList();
                    var lines = new List <GeoJSON.Net.Geometry.LineString>();
                    multi.ForEach(block =>
                    {
                        var coordinates = block.Split('\n').Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                        var coords      = coordinates.Select(r => new Position(double.Parse(r.Split(',')[1], CultureInfo.InvariantCulture), double.Parse(r.Split(',')[0], CultureInfo.InvariantCulture))).ToList();
                        if (coords.Count >= 2)
                        {
                            var geo = new GeoJSON.Net.Geometry.LineString(coords);
                            lines.Add(geo);
                        }
                    });
                    GeoJSON.Net.Feature.Feature feature;
                    if (lines.Count == 1)
                    {
                        feature = new GeoJSON.Net.Feature.Feature(lines.Single());
                    }
                    else
                    {
                        var multiLineString = new MultiLineString(lines);
                        feature             = new GeoJSON.Net.Feature.Feature(multiLineString);
                    }
                    feature.Properties.Add("id", r.RouteId);
                    feature.Properties.Add("totalInstances", routesToReturn[r.RouteId]);

                    if (map.ShowRouteOutline)
                    {
                        feature.Properties.Add("o", 1);
                    }
                    if (map.ShowRouteInfo)
                    {
                        if (language == "nl" && !string.IsNullOrWhiteSpace(r.NameNL))
                        {
                            feature.Properties.Add("name", r.NameNL);
                        }
                        else
                        {
                            feature.Properties.Add("name", r.Name);
                        }
                        if (language == "nl" && !string.IsNullOrWhiteSpace(r.RouteType.NameNL))
                        {
                            feature.Properties.Add("type", r.RouteType.NameNL);
                        }
                        else
                        {
                            feature.Properties.Add("type", r.RouteType.Name);
                        }
                        if (language == "nl" && !string.IsNullOrWhiteSpace(r.DescriptionNL))
                        {
                            feature.Properties.Add("description", r.DescriptionNL);
                        }
                        else
                        {
                            feature.Properties.Add("description", r.Description);
                        }
                        feature.Properties.Add("lineNumber", r.LineNumber);
                        feature.Properties.Add("operatingCompany", r.OperatingCompany);
                        if (r.OverrideDistance.HasValue)
                        {
                            feature.Properties.Add("distance", r.OverrideDistance);
                        }
                        else
                        {
                            feature.Properties.Add("distance", r.CalculatedDistance);
                        }
                    }
                    if (map.UserId == userIdClaim)
                    {
                        feature.Properties.Add("owner", true);
                    }
                    if (!string.IsNullOrWhiteSpace(r.OverrideColour))
                    {
                        feature.Properties.Add("stroke", r.OverrideColour);
                    }
                    else
                    {
                        feature.Properties.Add("stroke", r.RouteType.Colour);
                    }
                    collection.Features.Add(feature);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
            });

            return(collection);
        }
コード例 #28
0
        private void RenderPolygon(LineString lineString)
        {
            float lineWidth = 0;

            float[] points = ToOpenTK(lineString);

            GL.LineWidth(lineWidth);
            GL.Color4(0, 0, 0, 255);
            GL.EnableClientState(All.VertexArray);
            GL.VertexPointer(2, All.Float, 0, points);
            GL.DrawArrays(All.LineLoop, 0, points.Length / 2);
            GL.DisableClientState(All.VertexArray);
        }
コード例 #29
0
        private static float[] ToOpenTK(LineString lineString)
        {
            const int dimensions = 2; // x and y are both in one array
            var points = new float[lineString.Coordinates.Count * dimensions];

            var counter = 0;
            foreach (var coordinate in lineString.Coordinates)
            {
                var position = (GeographicPosition)coordinate;
                var point = SphericalMercator.FromLonLat(position.Longitude, position.Latitude);
                points[counter * 2 + 0] = point.X;
                points[counter * 2 + 1] = point.Y;
                counter++;
            }

            return points;
        }
コード例 #30
0
        public IGeometryObject GetGeometry(IGeometry esriGeometry)
        {
            IGeometryObject geoJsonGeom = null;

            string error = string.Format("A Geometry of type {0} cannot be created", Enum.GetName(typeof(esriGeometryType), esriGeometry.GeometryType));

            switch (esriGeometry.GeometryType)
            {
                case esriGeometryType.esriGeometryAny:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryBag:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryBezier3Curve:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryCircularArc:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryEllipticArc:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryEnvelope:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryLine:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryMultiPatch:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryMultipoint:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryNull:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryPath:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryPoint:
                    //cast to esri obj
                    IPoint point = esriGeometry as IPoint;

                    List<double> coords = new List<double> { point.X, point.Y };

                    //create geojson obj
                    GeoJSON.Net.Geometry.Point pnt = new GeoJSON.Net.Geometry.Point(coords);
                    geoJsonGeom = pnt;
                    break;
                case esriGeometryType.esriGeometryPolygon:
                    IGeometryCollection polygons = esriGeometry as IGeometryCollection;

                    List<LineString> linearRings = new List<LineString>();

                    var rings = new List<List<List<double>>>();
                    var ring = new List<List<double>>();

                    //todo - how does esri handle polygons with holes
                    for (int i = 0; i < polygons.GeometryCount; i++)
                    {
                        //for each geometry in the polygon create a point collection
                        var pGeom = polygons.Geometry[i];
                        var pntCollection = (IPointCollection)pGeom;

                        //GeoJSON.Net.Geometry.LineString line = new LineString();
                        for (var a = 0; a < pntCollection.PointCount; a++)
                        {
                            //create a list of coordinates for each line
                            List<double> linePointCoords = new List<double> { pntCollection.Point[a].X, pntCollection.Point[a].Y };

                            //..and add them to the poly
                            ring.Add(linePointCoords);
                        }

                        rings.Add(ring);
                    }

                    //initialise a poly
                    GeoJSON.Net.Geometry.Polygon poly = new GeoJSON.Net.Geometry.Polygon(rings);

                    geoJsonGeom = poly;
                    break;
                case esriGeometryType.esriGeometryPolyline:

                    //cast to esri obj
                    IGeometryCollection polylines = esriGeometry as IGeometryCollection;

                    //create geojson obj
                    GeoJSON.Net.Geometry.LineString polyLine = new LineString();

                    for (int i = 0; i < polylines.GeometryCount; i++)
                    {
                        //for each geometry in the polyline create a point collection
                        var pGeom = polylines.Geometry[i];
                        var pntCollection = (IPointCollection)pGeom;

                        for (var a = 0; a < pntCollection.PointCount; a++)
                        {
                            //create a list of coordinates for each line
                            List<double> linePointCoords = new List<double> { pntCollection.Point[a].X, pntCollection.Point[a].Y };

                            //..and add them to the line
                            polyLine.Coordinates.Add(linePointCoords);
                        }
                    }

                    geoJsonGeom = polyLine;

                    break;
                case esriGeometryType.esriGeometryRay:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryRing:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometrySphere:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryTriangleFan:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryTriangleStrip:
                    throw new ArgumentOutOfRangeException(error);
                case esriGeometryType.esriGeometryTriangles:
                    throw new ArgumentOutOfRangeException(error);
                default:
                    throw new ArgumentOutOfRangeException(error);
            }

            return geoJsonGeom;
        }
コード例 #31
0
		private static void Internal_FillGeometryBuilder(SqlGeometryBuilder gb, LineString lineString)
		{
			gb.BeginGeometry(OpenGisGeometryType.LineString);
			bool beginFigureCalled = false;
			foreach (var ipos in lineString.Coordinates)
			{
				GeographicPosition pos = ipos as GeographicPosition;
				if (!beginFigureCalled)
				{
					gb.BeginFigure(pos.Longitude, pos.Latitude);
					beginFigureCalled = true;

				}
				else
				{
					gb.AddLine(pos.Longitude, pos.Latitude);
				}

			}
			gb.EndFigure();
			gb.EndGeometry();
		}
コード例 #32
0
		public ToSqlGeometryTests()
		{
			point = new Point(new GeographicPosition(53.2455662, 90.65464646));

			multiPoint = new MultiPoint(new List<Point>
                {
                    new Point(new GeographicPosition(52.379790828551016, 5.3173828125)),
                    new Point(new GeographicPosition(52.36721467920585, 5.456085205078125)),
                    new Point(new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23))
                });
			lineString = new LineString(new List<IPosition>
                {
                    new GeographicPosition(52.379790828551016, 5.3173828125),
                    new GeographicPosition(52.36721467920585, 5.456085205078125),
                    new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23)
                });
			multiLineString = new MultiLineString(new List<LineString>
                {
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3173828125),
                        new GeographicPosition(52.36721467920585, 5.456085205078125),
                        new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23)
                    }),
                    new LineString(new List<IPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3273828125),
                        new GeographicPosition(52.36721467920585, 5.486085205078125),
                        new GeographicPosition(52.303440474272755, 5.426047363281249, 4.23)
                    })
                });

			polygonWithHole = new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
											new GeographicPosition(0.516357421875, 47.6415668949958),
											new GeographicPosition(0.516357421875, 47.34463879017405),
											new GeographicPosition(0.977783203125, 47.22539733216678),
											new GeographicPosition(1.175537109375, 47.463611506072866),
											new GeographicPosition(0.516357421875, 47.6415668949958)
                    }),
										 new LineString(new List<GeographicPosition>
											{
												new GeographicPosition(0.630340576171875, 47.54944962456812),
												new GeographicPosition(0.630340576171875, 47.49380564962583),
												new GeographicPosition(0.729217529296875, 47.482669772098674),
												new GeographicPosition(0.731964111328125, 47.53276262898896),
												new GeographicPosition(0.630340576171875, 47.54944962456812)
											})
								});
			polygon = new Polygon(new List<LineString>
                {
                    new LineString(new List<GeographicPosition>
                    {
                        new GeographicPosition(52.379790828551016, 5.3173828125),
                        new GeographicPosition(52.36721467920585, 5.456085205078125),
                        new GeographicPosition(52.303440474272755, 5.386047363281249, 4.23),
                        new GeographicPosition(52.379790828551016, 5.3173828125)
                    })
                });

			multiPolygon = new MultiPolygon(new List<Polygon>
                {
                    new Polygon(new List<LineString>
                    {
                        new LineString(new List<IPosition>
                        {
                            new GeographicPosition(52.959676831105995, -2.6797102391514338),
                            new GeographicPosition(52.9608756693609, -2.6769029474483279),
                            new GeographicPosition(52.908449372833715, -2.6079763270327119),
                            new GeographicPosition(52.891287242948195, -2.5815104708998668),
                            new GeographicPosition(52.875476700983896, -2.5851645010668989),
                            new GeographicPosition(52.882954723868622, -2.6050779098387191),
                            new GeographicPosition(52.875255907042678, -2.6373482332006359),
                            new GeographicPosition(52.878791122091066, -2.6932445076063951),
                            new GeographicPosition(52.89564268523565, -2.6931334629377890),
                            new GeographicPosition(52.930592009390175, -2.6548779332193022),
                            new GeographicPosition(52.959676831105995, -2.6797102391514338)
                        })
                    }),
                    new Polygon(new List<LineString>
                    {
                        new LineString(new List<IPosition>
                        {
                            new GeographicPosition(52.89610842810761, -2.69628632041613),
                            new GeographicPosition(52.8894641454077, -2.75901233808515),
                            new GeographicPosition(52.89938894657412, -2.7663172788742449),
                            new GeographicPosition(52.90253773227807, -2.804554822840895),
                            new GeographicPosition(52.929801009654575, -2.83848602260174),
                            new GeographicPosition(52.94013913205788, -2.838979264607087),
                            new GeographicPosition(52.937353122653533, -2.7978187468478741),
                            new GeographicPosition(52.920394929466184, -2.772273870352612),
                            new GeographicPosition(52.926572918779222, -2.6996509024137052),
                            new GeographicPosition(52.89610842810761, -2.69628632041613)
                        })
                    })
                });

			geomCollection = new GeometryCollection(new List<IGeometryObject>
                {
                    point,
                    multiPoint,
                    lineString,
                    multiLineString,
                    polygon,
                    multiPolygon
                });

			feature = new Feature.Feature(polygon, new Dictionary<string, object>() { { "Key", "Value" } }, "Id");

			featureCollection = new FeatureCollection(new List<Feature.Feature> {
					feature, new Feature.Feature(multiPolygon, null)
			});

		}
コード例 #33
0
ファイル: LineString.cs プロジェクト: tobiashoeft/GeoJSON.Net
 protected bool Equals(LineString other)
 {
     return base.Equals(other) && Coordinates.SequenceEqual(other.Coordinates);
 }
コード例 #34
0
ファイル: Engine.cs プロジェクト: kwilson/TrafficMapScotland
        /// <summary>
        /// Calculates the route.
        /// </summary>
        /// <param name="transportMode">The transport mode.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns>
        /// A new <see cref="RouteModel" /> with the route details.
        /// </returns>
        public RouteModel CalculatePointToPoint(VehicleEnum transportMode, GeoCoordinate start, GeoCoordinate end)
        {
            // calculate route.
            var startPoint = router.Resolve(transportMode, start);
            var endPoint = router.Resolve(transportMode, end);
            var route = router.Calculate(transportMode, startPoint, endPoint);

            if (route == null)
            {
                throw new RoutingException("No matching route found.");
            }

            var coordinates = route.Entries
                .Select(x => new GeographicPosition(x.Latitude, x.Longitude))
                .ToList();

            var lineString = new LineString(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", "Test route result." },
                        { "distance", route.TotalDistance },
                        { "journeytime", route.TotalTime },
                    });

            var generator = new InstructionGenerator();
            var instructions = generator.Generate(route, interpreter, new SimpleEnglishLanguageGenerator());

            return new RouteModel
                       {
                           Results = new ResultSet(feature)
                       };
        }
コード例 #35
0
		private IGeometryObject ConstructGeometryPart(SinkGeometry<OpenGisGeographyType> geomPart)
		{

			IGeometryObject geometry = null;

			switch (geomPart.GeometryType)
			{
				case OpenGisGeographyType.Point:
					geometry = new Point(geomPart[0][0]);
					break;
				case OpenGisGeographyType.MultiPoint:
					MultiPoint mp = new MultiPoint(geomPart.Select(g => new Point(g[0])).ToList());
					geometry = mp;
					break;
				case OpenGisGeographyType.LineString:
					geometry = new LineString(geomPart[0]);
					break;
				case OpenGisGeographyType.MultiLineString:
					geometry = new MultiLineString(geomPart.Select(line => new LineString(line))
																																		.ToList()
																															);
					break;
				case OpenGisGeographyType.Polygon:
					geometry = new Polygon(geomPart.Select(line => new LineString(line))
																																		.ToList()
																															);
					break;

				default:
					throw new NotSupportedException("Geometry type " + geomPart.GeometryType.ToString() + " is not supported yet.");
			}

			return geometry;
		}
コード例 #36
0
        public void FeatureCollectionSerialization()
        {
            var model = new FeatureCollection(null);
            for (var i = 10; i-- > 0;)
            {
                var geom = new LineString(new[]
                {
                    new GeographicPosition(51.010, -1.034),
                    new GeographicPosition(51.010, -0.034),
                });

                var props = new Dictionary<string, object>();
                props.Add("test1", "1");
                props.Add("test2", 2);

                var feature = new Feature.Feature(geom, props);
                model.Features.Add(feature);
            }

            var serialized = JsonConvert.SerializeObject(model, Formatting.Indented,
                new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });

            Assert.IsNotNull(serialized);
            Assert.IsFalse(string.IsNullOrEmpty(serialized));
        }