示例#1
0
        public void ConvertMultiPointTest()
        {
            var multipoint = SqlGeometry.STGeomFromText(new SqlChars("MULTIPOINT((10 40), (40 30), (20 20), (30 10))"), 25832);
            var geom       = GeoJsonGeometry.FromSqlGeometry(multipoint);

            Assert.True(geom.Type == GeoJSONObjectType.MultiPoint);
        }
示例#2
0
        public void ConvertMultiLineStringTest()
        {
            var multilinestring = SqlGeometry.STGeomFromText(new SqlChars("MULTILINESTRING((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))"), 25832);
            var geom            = GeoJsonGeometry.FromSqlGeometry(multilinestring);

            Assert.True(geom.Type == GeoJSONObjectType.MultiLineString);
        }
示例#3
0
        public void ConvertLineStringTest()
        {
            var linestring = SqlGeometry.STGeomFromText(new SqlChars("LINESTRING(30 10, 31 11, 32 12)"), 25832);
            var geom       = GeoJsonGeometry.FromSqlGeometry(linestring);

            Assert.True(geom.Type == GeoJSONObjectType.LineString);
        }
示例#4
0
        public void ConvertPolygonTest()
        {
            var polygon = SqlGeometry.STGeomFromText(new SqlChars("POLYGON((150 -10, 150 110, 250 110, 250 -10, 150 -10))"), 25832);
            var geom    = GeoJsonGeometry.FromSqlGeometry(polygon);

            Assert.True(geom.Type == GeoJSONObjectType.Polygon);
        }
示例#5
0
        public void ConvertGeometryCollectionTest()
        {
            var geometrycollection = SqlGeometry.STGeomFromText(new SqlChars("GEOMETRYCOLLECTION(POINT(4 6), LINESTRING(4 6, 7 10))"), 25832);
            var geom = GeoJsonGeometry.FromSqlGeometry(geometrycollection);

            Assert.True(geom.Type == GeoJSONObjectType.GeometryCollection);
        }
示例#6
0
        public void ConvertMultiPolygonTest()
        {
            var multipolygon = SqlGeometry.STGeomFromText(new SqlChars("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))"), 25832);
            var geom         = GeoJsonGeometry.FromSqlGeometry(multipolygon);

            Assert.True(geom.Type == GeoJSONObjectType.MultiPolygon);
        }
示例#7
0
        public void ConvertPointTest()
        {
            var point = SqlGeometry.STGeomFromText(new SqlChars("POINT(150.555 -10.666)"), 25832);
            var geom  = GeoJsonGeometry.FromSqlGeometry(point);

            Assert.True(geom.Type == GeoJSONObjectType.Point);
        }
示例#8
0
    public static string GeometryFromWKT()
    {
        string WKT = "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))";

        GeoJsonGeometry geometry = GeoJsonGeometry.FromWKTGeometry(WKT);

        return(geometry.Serialize(prettyPrint: true));
    }
示例#9
0
        public static string ToGeoJson(this GeoJsonGeometry <GeoJson2DGeographicCoordinates> geometry)
        {
            var geoJson = new OutputModels.CallToActionMatch.GeoJsonGeometry {
                Type        = "Polygon",
                Coordinates = geometry.ToPolygonArray()
            };

            return(JsonConvert.SerializeObject(geoJson));
        }
示例#10
0
    public static string GeometryFromDB()
    {
        if (!TestDBConnection())
        {
            return(null);
        }


        using (Entities db = new Entities())
        {
            DbGeometry data = (from row in db.SampleTables select row.SpatialData).FirstOrDefault();

            GeoJsonGeometry geometry = GeoJsonGeometry.FromDbGeometry(data);
            return(geometry.Serialize(prettyPrint: true));
        }
    }
示例#11
0
        public static double[][] ToRingArray(this GeoJsonGeometry <GeoJson2DGeographicCoordinates> geometry)
        {
            if (!(geometry is GeoJsonPolygon <GeoJson2DGeographicCoordinates>))
            {
                throw new ArgumentException();
            }
            var polygon = (GeoJsonPolygon <GeoJson2DGeographicCoordinates>)geometry;

            var extRing   = polygon.Coordinates.Exterior;
            var positions = from coord in extRing.Positions
                            select new double[] {
                coord.Longitude, coord.Latitude
            };

            return(positions.ToArray());
        }
示例#12
0
        public void Save(string key, VectorQuadTile tile)
        {
            var ro  = new FeatureCollection();
            var crs = new NamedCRS("EPSG:" + Config.Settings.Map.SpatialReferenceSystemIdentifier);

            ro.CRS = crs;

            foreach (var omg in tile.Områder)
            {
                var             område   = omg.Område;
                IGeometryObject geometry = GeoJsonGeometry.FromDotSpatial(omg.Geometry);
                var             props    = new Dictionary <string, object>
                {
                    { "category", område.Category },
                    { "name", område.Name },
                    { "number", område.Number },
                    { "value", område.Value },
                    { "type", område.Type.ToString() },
                    { "kind", område.kind }
                };
                var feature = new Feature(geometry, props)
                {
                    Id = område.AreaId.ToString()
                };
                var fp = new FeatureProperties {
                    nin = område.kind
                };
                if (område.Number == 0)
                {
                    throw new Exception("Område mangler nummer.");
                }
                ro.Features.Add(feature);
            }

            var fullPath          = GetFullPath(key);
            var fullPathSingleDir = GetFullPath(key.Replace("/", "_"));

            var settings = GetJsonSerializerSettings();

            File.WriteAllText(fullPath, JsonConvert.SerializeObject(ro, settings));
            //File.WriteAllText(fullPathSingleDir, JsonConvert.SerializeObject(ro, settings));

            //var serializer = new DataContractJsonSerializer(typeof(VectorQuadTile), CreateDataContractJsonSerializerSettings());
            //using (Stream stream = File.Create(fullPath + ".adf"))
            //    serializer.WriteObject(stream, tile);
        }
示例#13
0
        public static GeoJson <GeoJsonGeometry> DecodeStandardGeoJson(string geoJson)
        {
            GeoJson <GeoJsonGeometryStandard> geoJsonCodedModel = JsonConvert.DeserializeObject <GeoJson <GeoJsonGeometryStandard> >(geoJson);

            GeoJson <GeoJsonGeometry> geoJsonModel = new GeoJson <GeoJsonGeometry>();

            geoJsonModel.Type     = geoJsonCodedModel.Type;
            geoJsonModel.Features = new List <GeoJsonFeature <GeoJsonGeometry> >();

            List <GeoJsonFeature <GeoJsonGeometryStandard> > features = geoJsonCodedModel.Features;

            foreach (GeoJsonFeature <GeoJsonGeometryStandard> feature in features)
            {
                List <List <List <double> > > coordinates = feature.Geometry.Coordinates;

                List <List <Point> > geometryPointsList = new List <List <Point> >();
                for (int k = 0; k < coordinates.Count; k++)
                {
                    List <Point> pointList = new List <Point>();
                    geometryPointsList.Add(pointList);

                    for (int i = 0; i < coordinates[0].Count; i++)
                    {
                        Point point = new Point();
                        point.X = coordinates[k][i][0];
                        point.Y = coordinates[k][i][1];

                        pointList.Add(point);
                    }
                }

                GeoJsonGeometry geoJsonGeometry = new GeoJsonGeometry();
                geoJsonGeometry.PointList = geometryPointsList;

                GeoJsonFeature <GeoJsonGeometry> geoJsonFeature = new GeoJsonFeature <GeoJsonGeometry>();
                geoJsonFeature.Geometry = geoJsonGeometry;

                geoJsonModel.Features.Add(geoJsonFeature);
            }
            return(geoJsonModel);
        }
        // protected methods
        /// <summary>
        /// Deserializes a value.
        /// </summary>
        /// <param name="context">The deserialization context.</param>
        /// <param name="args">The deserialization args.</param>
        /// <returns>The value.</returns>
        protected override GeoJsonFeature <TCoordinates> DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var geoJsonFeatureArgs = new GeoJsonFeatureArgs <TCoordinates>();
            GeoJsonGeometry <TCoordinates> geometry = null;

            _helper.DeserializeMembers(context, (elementName, flag) =>
            {
                switch (flag)
                {
                case Flags.Geometry: geometry = DeserializeGeometry(context); break;

                case Flags.Id: geoJsonFeatureArgs.Id = DeserializeId(context); break;

                case Flags.Properties: geoJsonFeatureArgs.Properties = DeserializeProperties(context); break;

                default: _helper.DeserializeBaseMember(context, elementName, flag, geoJsonFeatureArgs); break;
                }
            });

            return(new GeoJsonFeature <TCoordinates>(geoJsonFeatureArgs, geometry));
        }
示例#15
0
        public async Task UpdateChannelSetGeoLocation()
        {
            await WithUpdateableChannel(client, async channel =>
            {
                var longitude     = 13.37774;
                var latitude      = 52.51627;
                var geoLocation   = new GeoJsonGeometry(longitude, latitude);
                var updateActions = new List <UpdateAction <Channel> >();
                var action        = new SetGeoLocationUpdateAction
                {
                    GeoLocation = geoLocation
                };
                updateActions.Add(action);

                var updatedChannel = await client
                                     .ExecuteAsync(new UpdateByIdCommand <Channel>(channel, updateActions));

                Assert.Equal(longitude, updatedChannel.GeoLocation.Coordinates[0]);
                Assert.Equal(latitude, updatedChannel.GeoLocation.Coordinates[1]);
                return(updatedChannel);
            });
        }
        /// <summary>
        /// Returns the specified <strong>GeoJSON</strong> <paramref name="geometry"/> as a list of polygons.
        /// </summary>
        /// <param name="geometry">The geometry to be converted.</param>
        /// <returns>A list of <see cref="IPolygon"/>.</returns>
        public static List <IPolygon> GetAsMultiPolygons(GeoJsonGeometry geometry)
        {
            List <IPolygon> polygons = new List <IPolygon>();

            switch (geometry)
            {
            case null:
                return(polygons);

            case GeoJsonPolygon polygon:
                polygons.Add(polygon.ToPolygon());
                break;

            case GeoJsonMultiPolygon m:
                polygons.AddRange(m.ToMultiPolygon().Polygons);
                break;

            default:
                throw new GeoJsonException($"Unsupported geometry {geometry.GetType()}");
            }

            return(polygons);
        }
 public static IQueryable <TEntity> SearchGeoIntersecting <TEntity, TCoordinates>(this IQueryable <TEntity> queryable, Expression <Func <TEntity, object> > field, GeoJsonGeometry <TCoordinates> geometry) where TCoordinates : GeoJsonCoordinates
 {
     return(queryable.WhereFilter(b => b.GeoIntersects(field, geometry)));
 }
 private void SerializeGeometry(BsonSerializationContext context, GeoJsonGeometry <TCoordinates> geometry)
 {
     context.Writer.WriteName("geometry");
     _geometrySerializer.Serialize(context, geometry);
 }
 private void SerializeGeometry(BsonWriter bsonWriter, GeoJsonGeometry <TCoordinates> geometry)
 {
     bsonWriter.WriteName("geometry");
     _geometrySerializer.Serialize(bsonWriter, typeof(GeoJsonGeometry <TCoordinates>), geometry, null);
 }
示例#20
0
        static public IGeometry ToGeometry <T>(this GeoJsonGeometry <T> geoJsonGeometry) where T : GeoJsonCoordinates
        {
            if (geoJsonGeometry is GeoJsonPoint <T> )
            {
                var geoJsonPoint = (GeoJsonPoint <T>)geoJsonGeometry;

                if (geoJsonPoint.Coordinates != null)
                {
                    var values = geoJsonPoint.Coordinates.Values;
                    return(new Point(values[0], values[1]));
                }
            }
            if (geoJsonGeometry is GeoJsonLineString <T> )
            {
                var polyline          = new Polyline();
                var geoJsonLineString = (GeoJsonLineString <T>)geoJsonGeometry;

                var lineStringCoordinates = geoJsonLineString.Coordinates;
                if (lineStringCoordinates != null)
                {
                    polyline.AddPath(lineStringCoordinates.ToPath <T>());
                }

                return(polyline);
            }
            if (geoJsonGeometry is GeoJsonMultiLineString <T> )
            {
                var polyline = new Polyline();
                var geoJsonMultiLineString = (GeoJsonMultiLineString <T>)geoJsonGeometry;
                if (geoJsonMultiLineString.Coordinates?.LineStrings != null)
                {
                    foreach (var lineString in geoJsonMultiLineString.Coordinates.LineStrings)
                    {
                        polyline.AddPath(lineString.ToPath <T>());
                    }
                }

                return(polyline);
            }
            if (geoJsonGeometry is GeoJsonPolygon <T> )
            {
                var polygon        = new Polygon();
                var geoJsonPolygon = (GeoJsonPolygon <T>)geoJsonGeometry;

                var polygonCoordinates = geoJsonPolygon.Coordinates;
                if (polygonCoordinates.Exterior != null)
                {
                    polygon.AddRing(polygonCoordinates.Exterior.ToRing <T>());
                }
                if (polygonCoordinates.Holes != null)
                {
                    foreach (var hole in polygonCoordinates.Holes)
                    {
                        polygon.AddRing(hole.ToRing <T>());
                    }
                }

                return(polygon);
            }
            if (geoJsonGeometry is GeoJsonMultiPolygon <T> )
            {
                var polygon             = new Polygon();
                var geoJsonMultiPolygon = (GeoJsonMultiPolygon <T>)geoJsonGeometry;

                if (geoJsonMultiPolygon.Coordinates?.Polygons != null)
                {
                    foreach (var geoJsonPolygon in geoJsonMultiPolygon.Coordinates.Polygons)
                    {
                        if (geoJsonPolygon.Exterior != null)
                        {
                            polygon.AddRing(geoJsonPolygon.Exterior.ToRing <T>());
                        }
                        if (geoJsonPolygon.Holes != null)
                        {
                            foreach (var hole in geoJsonPolygon.Holes)
                            {
                                polygon.AddRing(hole.ToRing <T>());
                            }
                        }
                    }
                }

                return(polygon);
            }

            return(null);
        }
 public static bool WithinCircle(this GeoJsonGeometry source, params double[] values)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Initializes a new instance with the specified <paramref name="geometry"/>.
 /// </summary>
 /// <param name="geometry">The geometry of the feature.</param>
 public GeoJsonFeature(GeoJsonGeometry geometry) : base(GeoJsonType.Feature)
 {
     Geometry   = geometry;
     Properties = new GeoJsonProperties();
 }
 /// <summary>
 /// Initializes a new instance with the specified <paramref name="geometry"/>.
 /// </summary>
 /// <param name="geometry">The geometry of the feature.</param>
 /// <param name="properties">The properties of the feature.</param>
 public GeoJsonFeature(GeoJsonGeometry geometry, GeoJsonProperties properties) : base(GeoJsonType.Feature)
 {
     Geometry   = geometry;
     Properties = properties ?? new GeoJsonProperties();
 }
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="json"/> object.
 /// </summary>
 /// <param name="json">An instance of <see cref="JObject"/> representing the feature.</param>
 protected GeoJsonFeature(JObject json) : base(GeoJsonType.Feature)
 {
     Properties = json.GetObject("properties", GeoJsonProperties.Parse);
     Geometry   = json.GetObject <GeoJsonGeometry>("geometry");
 }