public static GeoJSON.Net.Geometry.Point Point2JG(PointD point) { JGeometry.GeographicPosition position = new JGeometry.GeographicPosition(point.Y, point.X); JGeometry.IPosition ip = position; JGeometry.Point jPoint = new JGeometry.Point(position); return(jPoint); }
/// <summary> /// Prints GEOJson dump of Sites /// </summary> /// <param name="requiredProperties">list of properties to include (if not found in siteproperties an empty string will be inserted)</param> public void Execute(string[] requiredProperties, string siteType) { Console.Write("Content-Type: application/json\n\n"); var features = new List<Feature>(); FeatureCollection fc = new FeatureCollection(features); var filter = ""; if( siteType != "") filter = "type = '"+siteType+"'"; var sites = db.GetSiteCatalog(filter:filter); var siteProp = new TimeSeriesDatabaseDataSet.sitepropertiesDataTable(db); int id = 0; foreach (var s in sites) { try { var pos = new GeographicPosition(s.latitude, s.longitude); var pt = new GeoJSON.Net.Geometry.Point(pos); var props = siteProp.GetDictionary(s.siteid); for (int i = 0; i < requiredProperties.Length; i++) { if (requiredProperties[i].Trim() == "") continue; if (!props.ContainsKey(requiredProperties[i])) props.Add(requiredProperties[i], ""); } props.Add("siteid", s.siteid); props.Add("title", s.description); props.Add("state", s.state); props.Add("type", s.type); props.Add("region", s.responsibility.Trim()); props.Add("install", s.install); id++; var feature = new Feature(pt, props, id.ToString()); fc.Features.Add(feature); } catch (Exception error) { Console.WriteLine("Error at site:"+s); Console.WriteLine(error.Message); } } var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; var json = Newtonsoft.Json.JsonConvert.SerializeObject(fc, Newtonsoft.Json.Formatting.Indented,settings); Console.WriteLine(json); //File.WriteAllText(@"c:\temp\test.json", json); }
public void GeographicPositionSerialization() { var model = new GeographicPosition(112.12, 10); var serialized = JsonConvert.SerializeObject(model, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var matches = Regex.Matches(serialized, @"(\d+.\d+)"); Assert.IsTrue(matches.Count == 2); double lng; Assert.IsTrue(double.TryParse(matches[0].Value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out lng)); Assert.AreEqual(lng, 112.12); }
public GeographicPosition ToGeographicPosition(int x, int y, int z, uint extent) { var size = extent*Math.Pow(2, z); var x0 = extent*x; var y0 = extent*y; var y2 = 180 - (Latitude + y0)*360/size; var lon = (Longitude + x0)*360/size - 180; var lat = 360/Math.PI*Math.Atan(Math.Exp(y2*Math.PI/180)) - 90; var g = new GeographicPosition(lat,lon); return g; }
public void GeographicPositionSerialization() { var model = new GeoJSON.Net.Geometry.GeographicPosition(112.12, 10); var serialized = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var matches = Regex.Matches(serialized, @"(\d+.\d+)"); Assert.IsTrue(matches.Count == 2); double lng = 0; double.TryParse(matches[0].Value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out lng); Assert.AreEqual(lng, 112.12); }
public static void AssertCoordinate(GeographicPosition expectedCoord, JArray array) { Assert.AreEqual(expectedCoord.Latitude, (double)array[1], 1e-6); Assert.AreEqual(expectedCoord.Longitude, (double)array[0], 1e-6); }
public void Feature_Equals_GetHashCode_Contract_Dictionary() { var leftDictionary = GetPropertiesInRandomOrder(); var rightDictionary = GetPropertiesInRandomOrder(); var geometry_10 = new GeographicPosition(10, 10); var geometry_20 = new GeographicPosition(20, 20); var left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); var right = new Net.Feature.Feature(new Point( geometry_20), rightDictionary, "abc"); Assert_Are_Not_Equal(left, right); // different geometries left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_20), rightDictionary, "xyz"); // different geometries and ids Assert_Are_Not_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // identical except properties are in random order Assert_Are_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "xyz"); // different ids Assert_Are_Not_Equal(left, right); leftDictionary.Add("Guid", Guid.NewGuid().ToString()); left = new Net.Feature.Feature(new Point( geometry_10), leftDictionary, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // different properties Assert_Are_Not_Equal(left, right); left = new Net.Feature.Feature(new Point( geometry_10), null, "abc"); right = new Net.Feature.Feature(new Point( geometry_10), rightDictionary, "abc"); // different properties Assert_Are_Not_Equal(left, right); }
/// <summary> /// Determines whether the specified <see cref="GeographicPosition" />, is equal to this instance. /// </summary> /// <param name="other">The <see cref="GeographicPosition" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="GeographicPosition" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> protected bool Equals(GeographicPosition other) { return Coordinates.SequenceEqual(other.Coordinates, DoubleComparer); }
private static IEnumerable<GeographicPosition> EnsureCorrectWinding(List<GeographicPosition> vertices, bool mustBeClockwise) { int clockWiseCount = 0; int counterClockWiseCount = 0; GeographicPosition p1 = vertices[0]; for (int i = 1; i < vertices.Count; i++) { GeographicPosition p2 = vertices[i]; GeographicPosition p3 = vertices[(i + 1) % vertices.Count]; GeographicPosition e1 = new GeographicPosition(p1.Longitude - p2.Longitude, p1.Latitude - p2.Latitude); GeographicPosition e2 = new GeographicPosition(p3.Longitude - p2.Longitude, p3.Latitude - p2.Latitude); if (e1.Longitude * e2.Latitude - e1.Latitude * e2.Longitude >= 0) clockWiseCount++; else counterClockWiseCount++; p1 = p2; } bool isClockwize = clockWiseCount > counterClockWiseCount; if (isClockwize) { if (mustBeClockwise) return vertices; else return vertices.Reverse<GeographicPosition>(); } else { if (mustBeClockwise) return vertices.Reverse<GeographicPosition>(); else return vertices; } }