public static SqlGeography CreateGeography(this string points, out OpenGisGeographyType geographyType, int srid = 4326) { geographyType = OpenGisGeographyType.Point; SqlGeography firstPoint = null; var pts = points.Trim().Split(new string[] { "\n" }, StringSplitOptions.None).ToList(); pts.Add(null); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.GeometryCollection); var coordinates = new List <Tuple <double, double> >(); for (int i = 0; i < pts.Count; i++) { if (string.IsNullOrWhiteSpace(pts[i])) { if (coordinates.Count == 1) { if (firstPoint == null) { firstPoint = coordinates[0].CreatePoint(); } b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(coordinates[0].Item2, coordinates[0].Item1); b.EndFigure(); b.EndGeography(); } else if (coordinates.Count > 1) { geographyType = OpenGisGeographyType.GeometryCollection; var list = coordinates.Distinct().ToList(); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Item2, list[0].Item1); for (var j = 1; j < list.Count; j++) { b.AddLine(list[j].Item2, list[j].Item1); } b.AddLine(list[0].Item2, list[0].Item1); b.EndFigure(); b.EndGeography(); } coordinates = new List <Tuple <double, double> >(); continue; } var pt = pts[i].Trim().Split(new string[] { " ", ",", ";", "\t", ":", "\r" }, StringSplitOptions.RemoveEmptyEntries); coordinates.Add(new Tuple <double, double>(double.Parse(pt[0]), double.Parse(pt[1]))); } b.EndGeography(); if (geographyType == OpenGisGeographyType.GeometryCollection) { return(b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography); } else { return(firstPoint); } }
//TOP LEFT LONGITUDE=item1, LATITUDE=item2, //BOTTOM RIGHT LONGITUDE=item3, LATITUDE=item4 public static SqlGeography CreateMultiRectangle(this List <Tuple <double, double, double, double> > coordinates, int srid = 4326) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.MultiPolygon); for (var i = 0; i < list.Count; i++) { b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[i].Item1, list[i].Item2); b.AddLine(list[i].Item1, list[i].Item4); b.AddLine(list[i].Item3, list[i].Item4); b.AddLine(list[i].Item3, list[i].Item2); b.AddLine(list[i].Item1, list[i].Item2); b.EndFigure(); b.EndGeography(); } b.EndGeography(); return(b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography); }
private void btnCheckIntersection_Click(object sender, EventArgs e) { lat = Convert.ToDouble(txtLat.Text); lon = Convert.ToDouble(txtLon.Text); SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(lat, lon); builder.EndFigure(); builder.EndGeography(); DrawData(cboBeatSegs.Text, lat, lon); //bool tf = GeoClass.checkSegIntersection(cboBeatSegs.Text, builder.ConstructedGeography); bool tf = GeoClass.checkEsriIntersect(lat, lon, cboBeatSegs.Text); //bool tf = GeoClass.checkIntersects(builder.ConstructedGeography); if (tf == true) { lblInside.Text = "Point is inside figure"; } else { lblInside.Text = "Point is outside figure"; } }
private void AddCoordinates(Coordinate[] coordinates) { int points = 0; Array.ForEach <Coordinate>(coordinates, delegate(Coordinate coordinate) { double?z = null; if (!double.IsNaN(coordinate.Z) && !double.IsInfinity(coordinate.Z)) { z = coordinate.Z; } if (points == 0) { builder.BeginFigure(coordinate.Y, coordinate.X, z, null); } else { builder.AddLine(coordinate.Y, coordinate.X, z, null); } points++; }); if (points != 0) { builder.EndFigure(); } }
/// <summary> /// Makes Geography with default ellipsoid WGS84: 4326 /// </summary> /// <param name="points"></param> /// <param name="isClosed"></param> /// <returns></returns> public static SqlGeography MakeGeography <T>(List <T> points, bool isClosed, int srid = SridHelper.GeodeticWGS84) where T : IPoint, new() { if (points == null || points.Count < 1) { return(null); } SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(srid); builder.BeginGeography(isClosed ? OpenGisGeographyType.Polygon : OpenGisGeographyType.LineString); builder.BeginFigure(points[0].Y, points[0].X); for (int i = 1; i < points.Count; i++) { builder.AddLine(points[i].Y, points[i].X); } if (isClosed) { builder.AddLine(points[0].Y, points[0].X); } builder.EndFigure(); builder.EndGeography(); var resultGeography = builder.ConstructedGeography.STIsValid().Value ? builder.ConstructedGeography : builder.ConstructedGeography.MakeValid(); return(resultGeography.EnvelopeAngle().Value == 180 ? resultGeography.ReorientObject() : resultGeography); }
public static SqlGeography CreatePolygon(Coordinates[] coordinates, int srid) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Latitude, list[0].Longitude); for (var i = 1; i < list.Count; i++) { b.AddLine(list[i].Latitude, list[i].Longitude); } b.AddLine(list[0].Latitude, list[0].Longitude); b.EndFigure(); b.EndGeography(); //Fix left-hand rule. We always want left-hand. var g = b.ConstructedGeography; if (!g.STIsValid()) { throw new SisoDbException(ExceptionMessages.NotAValidPolygon.Inject(g.IsValidDetailed())); } if (g.EnvelopeAngle() > 90) { g = g.ReorientObject(); } return(g); }
public static SqlGeography CreatePolygon(IEnumerable <Coordinates> coordinates, int srid = 4326) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Latitude, list[0].Longitude); for (var i = 1; i < list.Count; i++) { b.AddLine(list[i].Latitude, list[i].Longitude); } b.AddLine(list[0].Latitude, list[0].Longitude); b.EndFigure(); b.EndGeography(); if (b.ConstructedGeography.EnvelopeAngle() > 90) { return(b.ConstructedGeography.ReorientObject()); } return(b.ConstructedGeography); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Polygon polygon) { gb.BeginGeography(OpenGisGeographyType.Polygon); bool isExteriorRing = true; foreach (var lineString in polygon.Coordinates) { List <Position> listGeoCoords = lineString.Coordinates.Select(p => p as Position).ToList(); IEnumerable <Position> orderedPositions = EnsureCorrectWinding(listGeoCoords, isExteriorRing); // exterior ring must be anti clockwise for SqlGeography isExteriorRing = false; bool beginFigureCalled = false; foreach (var pos in orderedPositions) { if (!beginFigureCalled) { gb.BeginFigure(pos.Latitude, pos.Longitude); beginFigureCalled = true; } else { gb.AddLine(pos.Latitude, pos.Longitude); } } gb.EndFigure(); } gb.EndGeography(); }
public void BeginFigureBeforeBeginGeography() { SqlGeographyBuilder b = new SqlGeographyBuilder(); b.SetSrid(4326); AssertEx.ThrowsException(() => { b.BeginFigure(1, 2); }, typeof(FormatException), "24300: Expected a call to BeginGeography, but BeginFigure was called."); }
public static SqlGeography GetBounds(SqlDouble xOrLon, SqlDouble yOrLat, SqlDouble xOrLon2, SqlDouble yOrLat2) { if (xOrLon.IsNull || yOrLat.IsNull) { return(SqlGeography.Null); } var builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Polygon); double x = xOrLon.Value; double x2 = xOrLon2.Value; double y = yOrLat.Value; double y2 = yOrLat2.Value; if (Math.Abs(x) > 180 && Math.Abs(y) > 180) { x = GetLon(xOrLon).Value; x2 = GetLon(xOrLon2).Value; y = GetLat(yOrLat).Value; y2 = GetLat(yOrLat2).Value; } builder.BeginFigure(y, x); builder.AddLine(y, x2); builder.AddLine(y2, x2); builder.AddLine(y2, x); builder.AddLine(y, x); builder.EndFigure(); builder.EndGeography(); return(builder.ConstructedGeography); }
/// <summary> /// Converts the given value from original representation to alternative one. /// </summary> /// <param name="value">Value in its original representation.</param> /// <returns>Value in its alternative representation.</returns> public override object Convert(object value) { object ret = null; Models.Location l = null; SqlGeographyBuilder builder = null; if (value != null && value is Models.Location) { l = value as Models.Location; builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(l.Latitude, l.Longitude); builder.EndFigure(); builder.EndGeography(); ret = builder.ConstructedGeography; } return ret; }
public static SqlGeography CreatePolygon(Coordinates[] coordinates, int srid) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Latitude, list[0].Longitude); for (var i = 1; i < list.Count; i++) b.AddLine(list[i].Latitude, list[i].Longitude); b.AddLine(list[0].Latitude, list[0].Longitude); b.EndFigure(); b.EndGeography(); //Fix left-hand rule. We always want left-hand. var g = b.ConstructedGeography; if (!g.STIsValid()) throw new SisoDbException(ExceptionMessages.NotAValidPolygon.Inject(g.IsValidDetailed())); if (g.EnvelopeAngle() > 90) g = g.ReorientObject(); return g; }
private static void SharpMapPointToSqlGeography(SqlGeographyBuilder geogBuilder, SMPoint point) { geogBuilder.BeginGeography(OpenGisGeographyType.Point); geogBuilder.BeginFigure(point.Y, point.X); geogBuilder.EndFigure(); geogBuilder.EndGeography(); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiLineString multiLineString) { gb.BeginGeography(OpenGisGeographyType.MultiLineString); foreach (var lineString in multiLineString.Coordinates) { gb.BeginGeography(OpenGisGeographyType.LineString); bool beginFigureCalled = false; foreach (var ipos in lineString.Coordinates) { Position pos = ipos as Position; if (!beginFigureCalled) { gb.BeginFigure(pos.Latitude, pos.Longitude); beginFigureCalled = true; } else { gb.AddLine(pos.Latitude, pos.Longitude); } } gb.EndFigure(); gb.EndGeography(); } gb.EndGeography(); }
private void AddLongitudeLine(SqlGeographyBuilder sb, double lon, double latmin, double latmax) { sb.BeginGeography(OpenGisGeographyType.LineString); sb.BeginFigure(latmin, lon); sb.AddLine(latmax, lon); sb.EndFigure(); sb.EndGeography(); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Point point) { gb.BeginGeography(OpenGisGeographyType.Point); GeographicPosition pos = point.Coordinates as GeographicPosition; gb.BeginFigure(pos.Latitude, pos.Longitude); gb.EndFigure(); gb.EndGeography(); }
public void AddLineOnPoint() { SqlGeographyBuilder b = new SqlGeographyBuilder(); b.SetSrid(4326); b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(1, 2); AssertEx.ThrowsException(() => { b.AddLine(1, 2); }, typeof(FormatException), "24300: Expected a call to EndFigure, but AddLine was called."); }
//Not supporting Z and M values public static void ProjectPoint(SqlGeographyBuilder builder, SqlGeometry point, Func <IPoint, IPoint> mapFunction) { //Point thePoint = mapFunction(new Point(point.Long.Value, point.Lat.Value)); var thePoint = mapFunction(point.AsPoint()); builder.BeginFigure(thePoint.Y, thePoint.X); builder.EndFigure(); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Point point) { gb.BeginGeography(OpenGisGeographyType.Point); Position pos = point.Coordinates as Position; gb.BeginFigure(pos.Latitude, pos.Longitude); gb.EndFigure(); gb.EndGeography(); }
private static void AddPoint <T>(SqlGeographyBuilder builder, Geometry <T> point) where T : IPoint, new() { builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(longitude: point.Points[0].X, latitude: point.Points[0].Y); builder.EndFigure(); builder.EndGeography(); }
//LONGITUDE=item1, LATITUDE=item2 public static SqlGeography CreatePoint(this Tuple<double, double> coordinates, int srid = 4326) { var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(coordinates.Item2, coordinates.Item1); b.EndFigure(); b.EndGeography(); return b.ConstructedGeography; }
////----------------------------------------------------------------------------------------------------------- public SqlGeography BuildGeography(List <LatLong> points, OpenGisGeographyType type) { SqlGeography geog = null; SqlGeographyBuilder geogBuilder = new SqlGeographyBuilder(); geogBuilder.SetSrid(4326); geogBuilder.BeginGeography(type); LatLong firstLatLong = null; bool firstLatLongStored = false; foreach (LatLong latLong in points) { if (!firstLatLongStored) { firstLatLong = latLong; geogBuilder.BeginFigure(firstLatLong.Latitude, firstLatLong.Longitude); firstLatLongStored = true; } else { geogBuilder.AddLine(latLong.Latitude, latLong.Longitude); } } if (type == OpenGisGeographyType.Polygon) { if (firstLatLong.Latitude != points[points.Count - 1].Latitude && firstLatLong.Longitude != points[points.Count - 1].Longitude) { geogBuilder.AddLine(firstLatLong.Latitude, firstLatLong.Longitude); } } geogBuilder.EndFigure(); geogBuilder.EndGeography(); try { geog = geogBuilder.ConstructedGeography; } catch (Exception ex) { throw; } var invertedGeogrpahy = geog.ReorientObject(); if (geog.STArea() > invertedGeogrpahy.STArea()) { geog = invertedGeogrpahy; } return(geog); }
public override SqlGeography AsSqlGeography() { SqlGeographyBuilder b = new SqlGeographyBuilder(); b.SetSrid(4326); b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(this.Lat, this.Long, this.Z, this.Time.HasValue ? this.Time.Value.ToOADate() : (double?)null); b.EndFigure(); b.EndGeography(); return(b.ConstructedGeography); }
public SqlGeography asSqlGeography() { SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(latitude, longitude); builder.EndFigure(); builder.EndGeography(); return builder.ConstructedGeography; }
//LONGITUDE=item1, LATITUDE=item2 public static SqlGeography CreatePoint(this Tuple <double, double> coordinates, int srid = 4326) { var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(coordinates.Item2, coordinates.Item1); b.EndFigure(); b.EndGeography(); return(b.ConstructedGeography); }
private SqlGeography CreateSinglePoint() { var builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(_points[0].Latitude, _points[0].Longitude); builder.EndFigure(); builder.EndGeography(); return(builder.ConstructedGeography); }
public void MakeWay(MongoCollection <Node> nodes) { var builder = new SqlGeographyBuilder(); builder.SetSrid(base.Srid); if (this.NodeIds.Count == 1) { this.Shape = OpenGisGeographyType.Point; builder.BeginGeography(OpenGisGeographyType.Point); } else if (this.NodeIds.First().Equals(this.NodeIds.Last())) { if (this.NodeIds.Count == 2) { builder.BeginGeography(OpenGisGeographyType.Point); this.Shape = OpenGisGeographyType.Point; } if (this.NodeIds.Count == 3) { builder.BeginGeography(OpenGisGeographyType.LineString); this.Shape = OpenGisGeographyType.LineString; var index = this.NodeIds.Count - 1; this.NodeIds.RemoveAt(index); } else { this.Shape = OpenGisGeographyType.Polygon; builder.BeginGeography(OpenGisGeographyType.Polygon); } } else { this.Shape = OpenGisGeographyType.LineString; builder.BeginGeography(OpenGisGeographyType.LineString); } var one = nodes.FindOneById(this.NodeIds[0]); builder.BeginFigure(one.Latitude, one.Longtitude); for (var index = 1; index < this.NodeIds.Count; index++) { var nodeId = this.NodeIds[index]; var node = nodes.FindOneById(nodeId); builder.AddLine(node.Latitude, node.Longtitude); } builder.EndFigure(); builder.EndGeography(); this.Lines = builder.ConstructedGeography; }
private static void AddPoint(SqlGeographyBuilder builder, GeoJsonPoint point, bool isLongitudeFirst) { builder.BeginGeography(OpenGisGeographyType.Point); var temporaryPoint = IRI.Msh.Common.Primitives.Point.Parse(point.Coordinates, isLongitudeFirst); builder.BeginFigure(temporaryPoint.Y, temporaryPoint.X); builder.EndFigure(); builder.EndGeography(); }
/// <summary> /// Przykład stworzenia obiektu zawierającego punkt. /// </summary> /// <param name="latitude">Szerokość geograficzna punktu.</param> /// <param name="longitude">Długość geograficzna punktu.</param> /// <returns></returns> private static SqlGeography BuildPoint(double latitude, double longitude) { SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.Point); builder.BeginFigure(latitude, longitude); builder.EndFigure(); builder.EndGeography(); return(builder.ConstructedGeography); }
/// <summary> /// Build an SqlGeography Point from a GeoJson Point. /// </summary> /// <param name="point">GeoJson Point</param> /// <returns>SqlGeography Point</returns> public static SqlGeography GeographyFromGeoJsonPoint(Models.GeoJson.Point point, int SRID) { var geob = new SqlGeographyBuilder(); geob.SetSrid(SRID); geob.BeginGeography(OpenGisGeographyType.Point); geob.BeginFigure(point.coordinates[0], point.coordinates[1]); geob.EndFigure(); geob.EndGeography(); var geog = geob.ConstructedGeography; return(geog); }
/// <summary> /// Przykład stworzenia obiektu zawierającego linię. /// </summary> /// <param name="latitude1">Szerokość geograficzna pierwszego punktu.</param> /// <param name="longitude1">Długość geograficzna pierwszego punktu.</param> /// <param name="latitude2">Szerokość geograficzna drugiego punktu.</param> /// <param name="longitude2">Długość geograficzna drugiego punktu.</param> /// <returns></returns> private static SqlGeography BuildLine(double latitude1, double longitude1, double latitude2, double longitude2) { SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.LineString); builder.BeginFigure(latitude1, longitude1); builder.AddLine(latitude2, longitude2); builder.EndFigure(); builder.EndGeography(); return(builder.ConstructedGeography); }
/// <summary> /// Build an SqlGeography Point from a GeoJson Point. /// </summary> /// <param name="point">GeoJson Point</param> /// <returns>SqlGeography Point</returns> public static SqlGeography GeographyFromGeoJsonPoint(DurMap.Site.Models.GeoJson.Point point) { var geob = new SqlGeographyBuilder(); geob.SetSrid(SRID); geob.BeginGeography(OpenGisGeographyType.Point); geob.BeginFigure(point.coordinates[1], point.coordinates[0]); geob.EndFigure(); geob.EndGeography(); var geog = geob.ConstructedGeography; //Trace.WriteLine(geog.AsGml().Value); return(geog); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, MultiPoint multiPoint) { gb.BeginGeography(OpenGisGeographyType.MultiPoint); List<Point> coords = multiPoint.Coordinates as List<Point>; foreach (var coord in coords) { GeographicPosition pos = coord.Coordinates as GeographicPosition; gb.BeginGeography(OpenGisGeographyType.Point); gb.BeginFigure(pos.Latitude, pos.Longitude); gb.EndFigure(); gb.EndGeography(); } gb.EndGeography(); }
private SqlGeography Sample_PolygonGeography() { SqlGeographyBuilder geoBuilder = new SqlGeographyBuilder(); geoBuilder.SetSrid(4326); geoBuilder.BeginGeography(OpenGisGeographyType.Polygon); geoBuilder.BeginFigure(40, -10); geoBuilder.AddLine(40, 10); geoBuilder.AddLine(50, 0); geoBuilder.AddLine(40, -10); geoBuilder.EndFigure(); geoBuilder.EndGeography(); return(geoBuilder.ConstructedGeography); }
private static void SharpMapLineStringToSqlGeography(SqlGeographyBuilder geomBuilder, SMLineString lineString) { geomBuilder.BeginGeography(OpenGisGeographyType.LineString); var coords = lineString.Coordinates; geomBuilder.BeginFigure(coords[0].Y, coords[0].X); for (int i = 1; i < lineString.NumPoints; i++) { var point = coords[i]; geomBuilder.AddLine(point.Y, point.X); } geomBuilder.EndFigure(); geomBuilder.EndGeography(); }
/// <summary> /// Build a Point geography /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns>constructed geography</returns> public static SqlGeography GeographyFromPoint(double latitude, double longitude) { var geob = new SqlGeographyBuilder(); geob.SetSrid(SRID); geob.BeginGeography(OpenGisGeographyType.Point); geob.BeginFigure(latitude, longitude); geob.EndFigure(); geob.EndGeography(); var geog = geob.ConstructedGeography; //Trace.WriteLine(geog.AsGml().Value); return(geog); }
public static SqlGeography CreateGeography(this string points, out OpenGisGeographyType geographyType, int srid = 4326) { geographyType = OpenGisGeographyType.Point; SqlGeography firstPoint = null; var pts = points.Trim().Split(new string[] { "\n" }, StringSplitOptions.None).ToList(); pts.Add(null); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.GeometryCollection); var coordinates = new List<Tuple<double, double>>(); for (int i = 0; i < pts.Count; i++) { if (string.IsNullOrWhiteSpace(pts[i])) { if (coordinates.Count == 1) { if (firstPoint == null) firstPoint = coordinates[0].CreatePoint(); b.BeginGeography(OpenGisGeographyType.Point); b.BeginFigure(coordinates[0].Item2, coordinates[0].Item1); b.EndFigure(); b.EndGeography(); } else if (coordinates.Count > 1) { geographyType = OpenGisGeographyType.GeometryCollection; var list = coordinates.Distinct().ToList(); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Item2, list[0].Item1); for (var j = 1; j < list.Count; j++) b.AddLine(list[j].Item2, list[j].Item1); b.AddLine(list[0].Item2, list[0].Item1); b.EndFigure(); b.EndGeography(); } coordinates = new List<Tuple<double, double>>(); continue; } var pt = pts[i].Trim().Split(new string[] { " ", ",", ";", "\t", ":", "\r" }, StringSplitOptions.RemoveEmptyEntries); coordinates.Add(new Tuple<double, double>(double.Parse(pt[0]), double.Parse(pt[1]))); } b.EndGeography(); if (geographyType == OpenGisGeographyType.GeometryCollection) return b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography; else return firstPoint; }
//LONGITUDE=item1, LATITUDE=item2 public static SqlGeography CreatePolygon(this List<Tuple<double, double>> coordinates, int srid = 4326) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Item2, list[0].Item1); for (var i = 1; i < list.Count; i++) b.AddLine(list[i].Item2, list[i].Item1); b.AddLine(list[0].Item2, list[0].Item1); b.EndFigure(); b.EndGeography(); return b.ConstructedGeography.EnvelopeAngle() > 90 ? b.ConstructedGeography.ReorientObject() : b.ConstructedGeography; }
public static SqlGeography CreatePolygon(IEnumerable<Coordinates> coordinates, int srid = 4326) { var list = coordinates.Distinct().ToList(); var b = new SqlGeographyBuilder(); b.SetSrid(srid); b.BeginGeography(OpenGisGeographyType.Polygon); b.BeginFigure(list[0].Latitude, list[0].Longitude); for (var i = 1; i < list.Count; i++) b.AddLine(list[i].Latitude, list[i].Longitude); b.AddLine(list[0].Latitude, list[0].Longitude); b.EndFigure(); b.EndGeography(); if(b.ConstructedGeography.EnvelopeAngle() > 90) return b.ConstructedGeography.ReorientObject(); return b.ConstructedGeography; }
public SqlGeography generateLineString(IList<RoutePointModel> points) { SqlGeographyBuilder builder = new SqlGeographyBuilder(); builder.SetSrid(4326); builder.BeginGeography(OpenGisGeographyType.LineString); for (int i = 0; i < points.Count; i++) { if (i == 0) { // First element, create figure builder.BeginFigure(points.ElementAt(0).latitude, points.ElementAt(0).longitude); } else { builder.AddLine(points.ElementAt(i).latitude, points.ElementAt(i).longitude); } } builder.EndFigure(); builder.EndGeography(); return builder.ConstructedGeography; }
/// <summary> /// Create a SqlGeography instance for the point specified by the LatLong object /// </summary> /// <param name="point">LatLong object representing the point</param> /// <returns>SqlGeography point</returns> private SqlGeography CreatePoint(LatLong point) { SqlGeographyBuilder geoPoint = new SqlGeographyBuilder(); //set the SRID and build the sql geography point for the centroid geoPoint.SetSrid(4326); geoPoint.BeginGeography(OpenGisGeographyType.Point); geoPoint.BeginFigure(point.Latitude, point.Longitude); geoPoint.EndFigure(); geoPoint.EndGeography(); return geoPoint.ConstructedGeography; }
/// <summary> /// Builds the route geography. /// </summary> /// <param name="route">The route.</param> /// <returns> /// New route geography /// </returns> private Route BuildRouteGeography(Route route) { var routeBuilder = new SqlGeographyBuilder(); routeBuilder.SetSrid(4326); routeBuilder.BeginGeography(OpenGisGeographyType.LineString); SqlGeography beginPoint = route.StartStop.StopGeography; routeBuilder.BeginFigure((double)beginPoint.Lat, (double)beginPoint.Long); for (var j = route.StartRouteIndex; j <= route.EndRouteIndex; j++) { var point = route.RouteGeography.STPointN(j); routeBuilder.AddLine((double)point.Lat, (double)point.Long); } SqlGeography endPoint = route.EndStop.StopGeography; routeBuilder.AddLine((double)endPoint.Lat, (double)endPoint.Long); routeBuilder.EndFigure(); routeBuilder.EndGeography(); route.CurrentPath = routeBuilder.ConstructedGeography; return route; }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, Polygon polygon) { gb.BeginGeography(OpenGisGeographyType.Polygon); bool isExteriorRing = true; foreach (var lineString in polygon.Coordinates) { List<GeographicPosition> listGeoCoords = lineString.Coordinates.Select(p => p as GeographicPosition).ToList(); IEnumerable<GeographicPosition> orderedPositions = EnsureCorrectWinding(listGeoCoords, isExteriorRing); // exterior ring must be anti clockwise for SqlGeography isExteriorRing = false; bool beginFigureCalled = false; foreach (var pos in orderedPositions) { if (!beginFigureCalled) { gb.BeginFigure(pos.Latitude, pos.Longitude); beginFigureCalled = true; } else { gb.AddLine(pos.Latitude, pos.Longitude); } } gb.EndFigure(); } gb.EndGeography(); }
private static void Internal_FillGeographyBuilder(SqlGeographyBuilder gb, LineString lineString) { gb.BeginGeography(OpenGisGeographyType.LineString); bool beginFigureCalled = false; foreach (var ipos in lineString.Coordinates) { GeographicPosition pos = ipos as GeographicPosition; if (!beginFigureCalled) { gb.BeginFigure(pos.Latitude, pos.Longitude); beginFigureCalled = true; } else { gb.AddLine(pos.Latitude, pos.Longitude); } } gb.EndFigure(); gb.EndGeography(); }
private SqlGeography Sample_PolygonGeography() { SqlGeographyBuilder geoBuilder = new SqlGeographyBuilder(); geoBuilder.SetSrid(4326); geoBuilder.BeginGeography(OpenGisGeographyType.Polygon); geoBuilder.BeginFigure(40, -10); geoBuilder.AddLine(40, 10); geoBuilder.AddLine(50, 0); geoBuilder.AddLine(40, -10); geoBuilder.EndFigure(); geoBuilder.EndGeography(); return geoBuilder.ConstructedGeography; }
/// <summary> /// Create a SqlGeography builder for the polygon specified by the points /// </summary> /// <param name="points">Latitude longitude points for the polygon</param> /// <returns>SqlGeographyBuilder for the polygon</returns> private SqlGeography CreatePolygonFromPoints(List<LatLong> points) { SqlGeographyBuilder polygon = new SqlGeographyBuilder(); polygon.SetSrid(4326); polygon.BeginGeography(OpenGisGeographyType.Polygon); //set the initial point to skip, and use that to begin the figure LatLong initialPoint = points.First(); polygon.BeginFigure(initialPoint.Latitude, initialPoint.Longitude); foreach (var point in points) { if (point != initialPoint) { //add each point to the geography poly polygon.AddLine(point.Latitude, point.Longitude); } } //end the configuration of the geography polygon.EndFigure(); polygon.EndGeography(); return polygon.ConstructedGeography; }
/// <summary> /// Create the SqlGeography line string from the points given /// </summary> /// <param name="linePoints">List of LatLong that represents the start and end of the line</param> /// <returns>SqlGeography line string</returns> private SqlGeography CreateLineFromPoints(List<LatLong> linePoints) { SqlGeographyBuilder geoLine = new SqlGeographyBuilder(); //build the sql geography representation of the linestring geoLine.SetSrid(4326); geoLine.BeginGeography(OpenGisGeographyType.LineString); geoLine.BeginFigure(linePoints.First().Latitude, linePoints.First().Longitude); geoLine.AddLine(linePoints.Last().Latitude, linePoints.Last().Longitude); geoLine.EndFigure(); geoLine.EndGeography(); return geoLine.ConstructedGeography; }
/// <summary> /// Builds the route geography. /// </summary> /// <param name="startIndex">The start index.</param> /// <param name="endIndex">The end index.</param> /// <param name="nearestStop">The nearest stop.</param> /// <param name="furtherStop">The further stop.</param> /// <param name="route">The route.</param> /// <returns>Geography of appropriate route</returns> private static Route BuildRouteGeography(int startIndex,int endIndex,Stop nearestStop, Stop furtherStop,Route route) { var geographyBuilder = new SqlGeographyBuilder(); geographyBuilder.SetSrid(4326); geographyBuilder.BeginGeography(OpenGisGeographyType.LineString); SqlGeography beginGb = nearestStop.StopGeography; geographyBuilder.BeginFigure((double) beginGb.Lat, (double) beginGb.Long); for (var j = startIndex; j <= endIndex; j++) { var point = route.RouteGeography.STPointN(j); geographyBuilder.AddLine((double) point.Lat, (double) point.Long); } SqlGeography endFigure = furtherStop.StopGeography; geographyBuilder.AddLine((double) endFigure.Lat, (double) endFigure.Long); geographyBuilder.EndFigure(); geographyBuilder.EndGeography(); route.RouteGeography = geographyBuilder.ConstructedGeography; return route; }