static internal void Encode(BinaryWriter p_bw, IGeometryObject p_Geometry) { switch (p_Geometry.Type) { case GeoJSONObjectType.Point: Point(p_bw, p_Geometry); break; case GeoJSONObjectType.MultiPoint: MultiPoint(p_bw, p_Geometry); break; case GeoJSONObjectType.Polygon: Polygon(p_bw, p_Geometry); break; case GeoJSONObjectType.MultiPolygon: MultiPolygon(p_bw, p_Geometry); break; case GeoJSONObjectType.LineString: Polyline(p_bw, p_Geometry); break; case GeoJSONObjectType.MultiLineString: MultiPolyline(p_bw, p_Geometry); break; case GeoJSONObjectType.GeometryCollection: GeometryCollection(p_bw, p_Geometry); break; } }
public void Parse_GeometryCollectionString_SuccessfulParse() { string strGeometry = "{ \"type\": \"GeometryCollection\", \"geometries\": [{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0]}, { \"type\": \"LineString\", \"coordinates\": [ [101.0, 0.0], [102.0, 1.0] ]}]}"; IGeometryObject geometry = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter()); Assert.AreEqual(GeoJSONObjectType.GeometryCollection, geometry.Type); GeometryCollection geometryCollection = (GeometryCollection)geometry; Assert.AreEqual(2, geometryCollection.Geometries.Count); // Geometry1 - Point Point point = (Point)geometryCollection.Geometries[0]; GeoJsonAssert.CoordinateAreEqual(100, 0, point.Coordinates); // Geometry2 - LineString LineString lineString = (LineString)geometryCollection.Geometries[1]; GeoJsonAssert.CoordinateAreEqual(101, 0, lineString.Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(102, 1, lineString.Coordinates[1]); // Deserialization without specifying Converter GeometryCollection geometryCollection2 = JsonConvert.DeserializeObject <GeometryCollection>(strGeometry); Assert.AreEqual(geometryCollection, geometryCollection2); }
/// <summary> /// Initializes a new instance of the <see cref="Feature" /> class. /// </summary> /// <param name="geometry">The Geometry Object.</param> /// <param name="properties"> /// Class used to fill feature properties. Any public member will be added to feature /// properties /// </param> /// <param name="id">The (optional) identifier.</param> public Feature(IGeometryObject geometry, object properties, string id = null) { Geometry = geometry; Id = id; if (properties == null) { Properties = new Dictionary <string, object>(); } else { #if (NET35 || NET40) Properties = properties.GetType().GetProperties() .Where(propertyInfo => propertyInfo.GetGetMethod().IsPublic) .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(properties, null)); #else Properties = properties.GetType().GetTypeInfo().DeclaredProperties .Where(propertyInfo => propertyInfo.GetMethod.IsPublic) .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(properties, null)); #endif } Type = GeoJSONObjectType.Feature; }
public static GeoRss10Where ToGeoRss10Where(this IGeometryObject geom) { if (geom is Point) { return(((Point)geom).ToGeoRss10Where()); } if (geom is LineString) { return(((LineString)geom).ToGeoRss10Where()); } if (geom is Polygon) { return(((Polygon)geom).ToGeoRss10Where()); } if (geom is MultiPolygon) { return(((MultiPolygon)geom).ToGeoRss10Where()); } if (geom is MultiPoint) { return(((MultiPoint)geom).ToGeoRss10Where()); } throw new NotImplementedException(); }
public static IGeoRSS ToGeoRss10(this IGeometryObject geom) { if (geom is Point) { return(((Point)geom).ToGeoRss10Point()); } if (geom is LineString) { return(((LineString)geom).ToGeoRss10Line()); } if (geom is Polygon && ((Polygon)geom).Coordinates.Count == 1) { return(((Polygon)geom).ToGeoRss10Polygon()); } if (geom is Polygon && ((Polygon)geom).Coordinates.Count > 1) { return(((Polygon)geom).ToGeoRss10Where()); } if (geom is MultiPolygon) { return(((MultiPolygon)geom).ToGeoRss10Where()); } if (geom is MultiPoint) { return(((MultiPoint)geom).ToGeoRss10Where()); } throw new NotImplementedException(); }
public void Parse_PolygonStringWithOneHole_SuccessfulParse() { const string strGeometry = "{ \"type\": \"Polygon\", \"coordinates\": [[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]]]}"; IGeometryObject geometry = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter()); Assert.AreEqual(GeoJSONObjectType.Polygon, geometry.Type); Polygon polygon = (Polygon)geometry; Assert.AreEqual(2, polygon.Coordinates.Count); // Outer polygon Assert.AreEqual(5, polygon.Coordinates[0].Coordinates.Count); GeoJsonAssert.CoordinateAreEqual(35, 10, polygon.Coordinates[0].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(45, 45, polygon.Coordinates[0].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(15, 40, polygon.Coordinates[0].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(10, 20, polygon.Coordinates[0].Coordinates[3]); GeoJsonAssert.CoordinateAreEqual(35, 10, polygon.Coordinates[0].Coordinates[4]); // Hole one Assert.AreEqual(4, polygon.Coordinates[1].Coordinates.Count); GeoJsonAssert.CoordinateAreEqual(20, 30, polygon.Coordinates[1].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(35, 35, polygon.Coordinates[1].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(30, 20, polygon.Coordinates[1].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(20, 30, polygon.Coordinates[1].Coordinates[3]); // Deserialization without specifying Converter Polygon polygon2 = JsonConvert.DeserializeObject <Polygon>(strGeometry); Assert.AreEqual(polygon, polygon2); }
public static AbstractGeometryType ToGml(this IGeometryObject geometry) { if (geometry is Point) { return(ToGmlPoint((Point)geometry)); } if (geometry is MultiPoint) { return(ToGmlMultiPoint((MultiPoint)geometry)); } if (geometry is LineString) { return(ToGmlLineString((LineString)geometry)); } if (geometry is MultiLineString) { return(ToGmlMultiCurve((MultiLineString)geometry)); } if (geometry is Polygon) { return(ToGmlPolygon((Polygon)geometry)); } if (geometry is MultiPolygon) { return(ToGmlMultiSurface((MultiPolygon)geometry)); } return(null); }
public void ValidGeometryCollectionTest() { IGeometryObject geoJSON = MsSqlSpatialConvert.ToGeoJSONGeometry(geomCol); var geoJSONobj = MsSqlSpatialConvert.ToGeoJSONObject <GeometryCollection>(geomCol); Assert.IsNotNull(geoJSON); Assert.IsNotNull(geoJSONobj); Assert.AreEqual(geoJSON.Type, GeoJSONObjectType.GeometryCollection); Assert.AreEqual(geoJSONobj.Type, GeoJSONObjectType.GeometryCollection); Assert.IsTrue(geoJSONobj.BoundingBoxes.Length == 4); CollectionAssert.AreEqual(geoJSONobj.BoundingBoxes, geomCol.BoundingBox()); Assert.AreEqual(geoJSONobj.Geometries.Count, 6); Assert.AreEqual(geoJSONobj.Geometries[0].Type, GeoJSONObjectType.Polygon); Assert.AreEqual(geoJSONobj.Geometries[1].Type, GeoJSONObjectType.MultiPolygon); Assert.AreEqual(geoJSONobj.Geometries[2].Type, GeoJSONObjectType.LineString); Assert.AreEqual(geoJSONobj.Geometries[3].Type, GeoJSONObjectType.Point); Assert.AreEqual(geoJSONobj.Geometries[4].Type, GeoJSONObjectType.MultiLineString); Assert.AreEqual(geoJSONobj.Geometries[5].Type, GeoJSONObjectType.MultiLineString); Assert.AreEqual(((Polygon)geoJSONobj.Geometries[0]).Coordinates[0].Coordinates.Count, 5); Assert.AreEqual(((Polygon)geoJSONobj.Geometries[0]).Coordinates[1].Coordinates.Count, 5); Assert.AreEqual(((MultiPolygon)geoJSONobj.Geometries[1]).Coordinates[0].Coordinates[0].Coordinates.Count, 4); Assert.AreEqual(((MultiPolygon)geoJSONobj.Geometries[1]).Coordinates[1].Coordinates[0].Coordinates.Count, 6); Assert.AreEqual(((MultiPolygon)geoJSONobj.Geometries[1]).Coordinates[1].Coordinates[1].Coordinates.Count, 4); Assert.AreEqual(((MultiPolygon)geoJSONobj.Geometries[1]).Coordinates[2].Coordinates[0].Coordinates.Count, 5); Assert.AreEqual(((MultiPolygon)geoJSONobj.Geometries[1]).Coordinates[2].Coordinates[1].Coordinates.Count, 5); Assert.AreEqual(((LineString)geoJSONobj.Geometries[2]).Coordinates.Count, 5); Assert.AreEqual(((MultiLineString)geoJSONobj.Geometries[4]).Coordinates.Count, 0); Assert.AreEqual(((MultiLineString)geoJSONobj.Geometries[5]).Coordinates.Count, 2); Assert.AreEqual(((MultiLineString)geoJSONobj.Geometries[5]).Coordinates[0].Coordinates.Count, 5); Assert.AreEqual(((MultiLineString)geoJSONobj.Geometries[5]).Coordinates[1].Coordinates.Count, 5); }
private static void Encode(BinaryWriter binaryWriter, IGeometryObject geometryObject) { switch (geometryObject.Type) { case GeoJSONObjectType.Point: Point(binaryWriter, geometryObject); break; case GeoJSONObjectType.MultiPoint: MultiPoint(binaryWriter, geometryObject); break; case GeoJSONObjectType.Polygon: Polygon(binaryWriter, geometryObject); break; case GeoJSONObjectType.MultiPolygon: MultiPolygon(binaryWriter, geometryObject); break; case GeoJSONObjectType.LineString: Polyline(binaryWriter, geometryObject); break; case GeoJSONObjectType.MultiLineString: MultiPolyline(binaryWriter, geometryObject); break; case GeoJSONObjectType.GeometryCollection: GeometryCollection(binaryWriter, geometryObject); break; } }
public void Serialization_Observes_No_Indenting_Setting_Of_Serializer(IGeometryObject geometry) { var json = JsonConvert.SerializeObject(geometry, Formatting.None); Assert.IsFalse(json.Contains("\r\n")); Assert.IsFalse(json.Contains(" ")); }
public static Feature ToGeoJSON(this VectorTileFeature vectortileFeature, int x, int y, int z) { IGeometryObject geom = null; switch (vectortileFeature.GeometryType) { case Tile.GeomType.Point: var projectedPoints = ProjectPoints(vectortileFeature.Geometry, x, y, z, vectortileFeature.Extent); geom = GetPointGeometry(projectedPoints); break; case Tile.GeomType.LineString: var projectedLines = ProjectLines(vectortileFeature.Geometry, x, y, z, vectortileFeature.Extent); geom = GetLineGeometry(projectedLines); break; case Tile.GeomType.Polygon: var rings = ClassifyRings.Classify(vectortileFeature.Geometry); var projectedPolygons = ProjectPolygons(rings, x, y, z, vectortileFeature.Extent); geom = GetPolygonGeometry(projectedPolygons); break; } var result = new Feature(geom, id: vectortileFeature.Id); // add attributes foreach (var item in vectortileFeature.Attributes) { result.Properties.Add(item.Key, item.Value); } return(result); }
public void Parse_MultiLineString_SuccessfulParse() { string strGeometry = "{ \"type\": \"MultiLineString\", \"coordinates\": [[[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]]]}"; IGeometryObject geometry = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter()); Assert.AreEqual(GeoJSONObjectType.MultiLineString, geometry.Type); MultiLineString multiLineString = (MultiLineString)geometry; Assert.AreEqual(2, multiLineString.Coordinates.Count); // LineString 1 GeoJsonAssert.CoordinateAreEqual(10, 10, multiLineString.Coordinates[0].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(20, 20, multiLineString.Coordinates[0].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(10, 40, multiLineString.Coordinates[0].Coordinates[2]); // LineString 2 GeoJsonAssert.CoordinateAreEqual(40, 40, multiLineString.Coordinates[1].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(30, 30, multiLineString.Coordinates[1].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(40, 20, multiLineString.Coordinates[1].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(30, 10, multiLineString.Coordinates[1].Coordinates[3]); // Deserialization without specifying Converter MultiLineString multiLineString2 = JsonConvert.DeserializeObject <MultiLineString>(strGeometry); Assert.AreEqual(multiLineString, multiLineString2); }
/// <summary> /// Initializes a new instance of the <see cref="Feature"/> class. /// </summary> /// <param name="geometry">The Geometry Object.</param> /// <param name="properties">The properties.</param> public Feature(IGeometryObject geometry, Dictionary <string, object> properties = null) { this.Geometry = geometry; this.Properties = properties; this.Type = GeoJSONObjectType.Feature; }
public void Parse_MultiPolygonStringWithOnePolygonContainingHole_SuccessfulParse() { string strGeometry = "{ \"type\": \"MultiPolygon\", \"coordinates\": [[[[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]]]]}"; IGeometryObject geometry = JsonConvert.DeserializeObject <IGeometryObject>(strGeometry, new GeometryConverter()); Assert.AreEqual(GeoJSONObjectType.MultiPolygon, geometry.Type); MultiPolygon multiPolygon = (MultiPolygon)geometry; Assert.AreEqual(2, multiPolygon.Coordinates.Count); // Polygon1 GeoJsonAssert.CoordinateAreEqual(40, 40, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(20, 45, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(45, 30, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(40, 40, multiPolygon.Coordinates[0].Coordinates[0].Coordinates[3]); // Polygon2 GeoJsonAssert.CoordinateAreEqual(20, 35, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(10, 30, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(10, 10, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(30, 5, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[3]); GeoJsonAssert.CoordinateAreEqual(45, 20, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[4]); GeoJsonAssert.CoordinateAreEqual(20, 35, multiPolygon.Coordinates[1].Coordinates[0].Coordinates[5]); // Polygon2 - Hole1 GeoJsonAssert.CoordinateAreEqual(30, 20, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[0]); GeoJsonAssert.CoordinateAreEqual(20, 15, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[1]); GeoJsonAssert.CoordinateAreEqual(20, 25, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[2]); GeoJsonAssert.CoordinateAreEqual(30, 20, multiPolygon.Coordinates[1].Coordinates[1].Coordinates[3]); // Deserialization without specifying Converter MultiPolygon multiPolygon2 = JsonConvert.DeserializeObject <MultiPolygon>(strGeometry); Assert.AreEqual(multiPolygon, multiPolygon2); }
private Feature createFeature(dynamic row) { dynamic geoJson = JsonConvert.DeserializeObject(row.json); string geometryType = geoJson.type; IGeometryObject geometry = null; switch (geometryType) { case "Polygon": geometry = JsonConvert.DeserializeObject <Polygon>(row.json); break; case "MultiPolygon": geometry = JsonConvert.DeserializeObject <MultiPolygon>(row.json); break; case "LineString": geometry = JsonConvert.DeserializeObject <LineString>(row.json); break; default: throw new Exception("Unexpected Geometry Type"); } Feature feature = new Feature(geometry); feature.Properties.Add("name", row.name); return(feature); }
/// <summary> /// Initializes a new instance of the <see cref="Feature"/> class. /// </summary> /// <param name="geometry">The Geometry Object.</param> /// <param name="properties">The properties.</param> public Feature(IGeometryObject geometry, Dictionary<string, object> properties = null) { this.Geometry = geometry; this.Properties = properties; this.Type = GeoJSONObjectType.Feature; }
public void IntersectionTest() { var source = new Point(new GeographicPosition(30.0, 110.0)); var targets = new IGeometryObject[] { new Point(new GeographicPosition(30.0, 110.0)) }; var url = String.Join("/", new string[] { urlPrefix, "analysis/intersection" }); var handler = new MockHttpHandler(url, "POST", (req, res, param) => { var result = new RestResult(); var form = req.GetFormData(); if (form.ContainsKey("source") && form.ContainsKey("targets")) { result.Success = true; } return(JsonConvert.SerializeObject(result)); }); mockServer.AddRequestHandler(handler); try { var topo = new TopoQuery(); topo.Intersection(source, targets); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void DifferenceTest() { var source = new Point(new GeographicPosition(30.0, 110.0)); var targets = new IGeometryObject[] { new Point(new GeographicPosition(30.0, 110.0)) }; var relation = SpatialFilter.RELATION_CONTAIN; var url = String.Join("/", new string[] { urlPrefix, "analysis/difference" }); var handler = new MockHttpHandler(url, "POST", (req, res, param) => { var result = new RestResult(); var form = req.GetFormData(); if (form.ContainsKey("source") && form.ContainsKey("targets")) { result.Data = JsonConvert.SerializeObject(targets); result.Success = true; } return(JsonConvert.SerializeObject(result)); }); mockServer.AddRequestHandler(handler); try { var topo = new TopoQuery(); var result = topo.Difference(source, targets); Assert.AreEqual(targets.Length, result.Length); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void ConvexHullTest() { var input = new IGeometryObject[] { new Point(new GeographicPosition(30.0, 110.0)) }; var url = String.Join("/", new string[] { urlPrefix, "analysis/convexhull" }); var handler = new MockHttpHandler(url, "POST", (req, res, param) => { var result = new RestResult(); var form = req.GetFormData(); if (form.ContainsKey("targets")) { result.Data = JsonConvert.SerializeObject(input); result.Success = true; } return(JsonConvert.SerializeObject(result)); }); mockServer.AddRequestHandler(handler); try { var topo = new TopoQuery(); var result = topo.ConvexHull(input); Assert.AreEqual(input.Length, result.Length); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private void OnCreateObject(object sender, RoutedEventArgs e) { try { count = Convert.ToInt32(countTextBox.Text.ToString()); for (int i = 0; i < count; i++) { switch (objectType) { case (int)ObjectType.Square: { currentObject = sfactory.CreateGeometryObject(); mainWindow.flat.Children.Add(CreateSquare()); break; } case (int)ObjectType.Circle: { currentObject = cfactory.CreateGeometryObject(); mainWindow.flat.Children.Add(CreateCircle()); break; } } mainWindow.factory.Items.Add(currentObject.Type); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Can_Serialize_And_Deserialize_Geometry(IGeometryObject geometry) { var json = JsonConvert.SerializeObject(geometry); var deserializedGeometry = JsonConvert.DeserializeObject <IGeometryObject>(json, new GeometryConverter()); Assert.AreEqual(geometry, deserializedGeometry); }
public Feature(IGeometryObject geometry, Dictionary <string, object> properties = null, string id = null) { Geometry = geometry; Properties = properties ?? new Dictionary <string, object>(); Id = id; Type = GeoJSONObjectType.Feature; }
public Feature(IGeometryObject geometry, Dictionary<string, object> properties = null, string id = null) { Geometry = geometry; Properties = properties ?? new Dictionary<string, object>(); Id = id; Type = GeoJSONObjectType.Feature; }
/// <summary> /// Restores the coordinates for a given Geometry Object. /// </summary> /// <param name="igo">The Geometry Object</param> private void restoreGeometryCoordinates(IGeometryObject igo) { // Go over all types. Point and MultiPoint can be left out here. switch (igo.Type) { // LineStrings case GeoJSONObjectType.LineString: TopoJSONLineString ls = igo as TopoJSONLineString; ls.Coordinates = this.getCoordinatesFromArcsIndex(ls.ArcIdx); break; // MultiLineStrings case GeoJSONObjectType.MultiLineString: TopoJSONMultiLineString mls = igo as TopoJSONMultiLineString; foreach (var idxArray in mls.ArcIdx) { List <GeographicPosition> lsCoords = this.getCoordinatesFromArcsIndex(idxArray); TopoJSONLineString l = new TopoJSONLineString(lsCoords); mls.Coordinates.Add(l); } break; // GeometryCollections case GeoJSONObjectType.GeometryCollection: GeometryCollection gc = igo as GeometryCollection; foreach (var geometry in gc.Geometries) { this.restoreGeometryCoordinates(geometry); } break; // Polygon case GeoJSONObjectType.Polygon: TopoJSONPolygon poly = igo as TopoJSONPolygon; List <GeographicPosition> coordinates = new List <GeographicPosition>(); foreach (var idxArray in poly.ArcIdx) { coordinates = this.getCoordinatesFromArcsIndex(idxArray); } poly.Coordinates = coordinates; break; // MultiPolygon case GeoJSONObjectType.MultiPolygon: TopoJSONMultiPolygon mpoly = igo as TopoJSONMultiPolygon; foreach (var idxArray in mpoly.ArcIdx) { foreach (var idx in idxArray) { List <GeographicPosition> polyCoords = new List <GeographicPosition>(); polyCoords = this.getCoordinatesFromArcsIndex(idx); TopoJSONPolygon tp = new TopoJSONPolygon(polyCoords); mpoly.Coordinates.Add(tp); } } break; } }
internal Feature Feature(IGeometryObject geometry) { var feature = new Feature(geometry, new Dictionary <string, object>() { { "a", 1 } }); return(feature); }
internal void OnDeserializedMethod(StreamingContext context) { // Iterate over all objects foreach (var wrapper in Objects) { IGeometryObject igo = wrapper.Geometry; this.restoreGeometryCoordinates(igo); } }
static void MultiPoint(BinaryWriter p_bw, IGeometryObject p_Geometry) { var v_MultiPoint = p_Geometry as MultiPoint; p_bw.Write(s_WKBNDR); p_bw.Write((Int32)WkbGeometryType.WkbMultiPoint); p_bw.Write((Int32)v_MultiPoint.Coordinates.Count); v_MultiPoint.Coordinates.ForEach(p_point => Point(p_bw, p_point)); }
static void MultiPolyline(BinaryWriter p_bw, IGeometryObject p_Geometry) { var v_MultiPolyLine = p_Geometry as MultiLineString; p_bw.Write(s_WKBNDR); p_bw.Write((Int32)WkbGeometryType.WkbMultiLineString); p_bw.Write((Int32)v_MultiPolyLine.Coordinates.Count); v_MultiPolyLine.Coordinates.ForEach(p_ls => Polyline(p_bw, p_ls)); }
static void MultiPolygon(BinaryWriter p_bw, IGeometryObject p_Geometry) { var v_MultiPolygon = p_Geometry as MultiPolygon; p_bw.Write(s_WKBNDR); p_bw.Write((Int32)WkbGeometryType.WkbMultiPolygon); p_bw.Write((Int32)v_MultiPolygon.Coordinates.Count); v_MultiPolygon.Coordinates.ForEach(v_g => Polygon(p_bw, v_g)); }
static void Polyline(BinaryWriter p_bw, IGeometryObject p_Geometry) { var v_Polyline = p_Geometry as LineString; p_bw.Write(s_WKBNDR); p_bw.Write((Int32)WkbGeometryType.WkbLineString); p_bw.Write((Int32)v_Polyline.Coordinates.Count); Points(p_bw, v_Polyline.Coordinates); }
public void Can_Serialize_And_Deserialize_Geometry_As_Object_Property(IGeometryObject geometry) { var classWithGeometry = new ClassWithGeometryProperty(geometry); var json = JsonConvert.SerializeObject(classWithGeometry); var deserializedClassWithGeometry = JsonConvert.DeserializeObject <ClassWithGeometryProperty>(json); Assert.AreEqual(classWithGeometry, deserializedClassWithGeometry); }
private static void Polyline(BinaryWriter binaryWriter, IGeometryObject geometryObject) { var v_Polyline = geometryObject as LineString; binaryWriter.Write(_wKBNDR); binaryWriter.Write((int)WkbGeometryType.LineString); binaryWriter.Write((int)v_Polyline.Coordinates.Count); Points(binaryWriter, v_Polyline.Coordinates.ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="Feature" /> class. /// </summary> /// <param name="geometry">The Geometry Object.</param> /// <param name="properties"> /// Class used to fill feature properties. Any public member will be added to feature /// properties /// </param> /// <param name="id">The (optional) identifier.</param> public Feature(IGeometryObject geometry, object properties, string id = null) { Geometry = geometry; Id = id; if (properties == null) { Properties = new Dictionary<string, object>(); } else { Properties = properties.GetType().GetTypeInfo().DeclaredProperties .Where(propertyInfo => propertyInfo.GetMethod.IsPublic) .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(properties, null)); } Type = GeoJSONObjectType.Feature; }
/// <summary> /// Initializes a new instance of the <see cref="Feature" /> class. /// </summary> /// <param name="geometry">The Geometry Object.</param> /// <param name="properties"> /// Class used to fill feature properties. Any public member will be added to feature /// properties /// </param> /// <param name="id">The (optional) identifier.</param> public Feature(IGeometryObject geometry, object properties, string id = null) { Geometry = geometry; Id = id; if (properties == null) { Properties = new Dictionary<string, object>(); } else { Properties = properties.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) .ToDictionary(prop => prop.Name, prop => prop.GetValue(properties, null)); } Type = GeoJSONObjectType.Feature; }
private Net.Feature.Feature GetFeature(IGeometryObject geometry, object properties = null, string id = null) { var feature = new Net.Feature.Feature(geometry, properties, id); return feature; }
public void Can_Serialize_And_Deserialize_Geometry(IGeometryObject geometry) { var json = JsonConvert.SerializeObject(geometry); var deserializedGeometry = JsonConvert.DeserializeObject<IGeometryObject>(json, new GeometryConverter()); Assert.AreEqual(geometry, deserializedGeometry); }
public void Can_Serialize_And_Deserialize_Geometry_As_Object_Property(IGeometryObject geometry) { var classWithGeometry = new ClassWithGeometryProperty(geometry); var json = JsonConvert.SerializeObject(classWithGeometry); var deserializedClassWithGeometry = JsonConvert.DeserializeObject<ClassWithGeometryProperty>(json); Assert.AreEqual(classWithGeometry, deserializedClassWithGeometry); }
public void Serialized_And_Deserialized_Equals_And_Share_HashCode(IGeometryObject geometry) { var classWithGeometry = new ClassWithGeometryProperty(geometry); var json = JsonConvert.SerializeObject(classWithGeometry); var deserializedClassWithGeometry = JsonConvert.DeserializeObject<ClassWithGeometryProperty>(json); var actual = classWithGeometry; var expected = deserializedClassWithGeometry; Assert.IsTrue(actual.Equals(expected)); Assert.IsTrue(actual.Equals(actual)); Assert.IsTrue(expected.Equals(actual)); Assert.IsTrue(expected.Equals(expected)); Assert.IsTrue(classWithGeometry == deserializedClassWithGeometry); Assert.IsTrue(deserializedClassWithGeometry == classWithGeometry); Assert.AreEqual(actual.GetHashCode(), expected.GetHashCode()); }
public ClassWithGeometryProperty(IGeometryObject geometry) { Geometry = geometry; }