private static Esri.ArcGISRuntime.Geometry.Geometry ReadGeographyMultiPoint(Microsoft.SqlServer.Types.SqlGeography mpoint, Esri.ArcGISRuntime.Geometry.SpatialReference sr) { return(new Esri.ArcGISRuntime.Geometry.Multipoint( Utilities.CountEnumerator(mpoint.STNumPoints().Value).Select(i => mpoint.STPointN(i)) .Select(p => ReadGeographyPoint(p, sr)) )); }
private static Esri.ArcGISRuntime.Geometry.Polyline ReadGeographyLineString(Microsoft.SqlServer.Types.SqlGeography line, Esri.ArcGISRuntime.Geometry.SpatialReference sr) { return(new Esri.ArcGISRuntime.Geometry.Polyline( Utilities.CountEnumerator(line.STNumPoints().Value) .Select(i => line.STPointN(i)) .Select(p => ReadGeographyPoint(p, sr)) )); }
private static Esri.ArcGISRuntime.Geometry.Geometry ReadGeographyPolygon(Microsoft.SqlServer.Types.SqlGeography poly, Esri.ArcGISRuntime.Geometry.SpatialReference sr) { var rings = Utilities.CountEnumerator(poly.NumRings().Value) .Select(i => poly.RingN(i)) .Select(t => Utilities.CountEnumerator(t.STNumPoints().Value) .Select(r => t.STPointN(r)) .Select(p => ReadGeographyPoint(p, sr))); return(new Esri.ArcGISRuntime.Geometry.Polygon(rings)); }
private List <LocalizationPointDto> GetPointsDynamicScoreUsingBuffer(List <LocalizationPointDto> points, double additionalDistance, double additionalTime, bool countScore = true, int?stepSize = null) { var result = new List <LocalizationPointDto>(); double halfOfAdditionalDistance = additionalDistance / 2; Microsoft.SqlServer.Types.SqlGeography routeSqlGeography = this.resultRoute.MultiPointGeoJsonNet.ToSqlGeography(); int bufferSize = (int)halfOfAdditionalDistance; int step = stepSize ?? (int)halfOfAdditionalDistance / 10; bool isFirstRun = true; while (bufferSize > 0) { if (isFirstRun) { if (points.Any(i => i.DynamicScore > 0)) { if (!countScore) { return(points); } } Microsoft.SqlServer.Types.SqlGeography bufferSqlGeography = routeSqlGeography.STBuffer(bufferSize); result = points.Where(i => (bool)bufferSqlGeography.STContains(i.Point.ToSqlGeography())).ToList(); // may not work because reference type - seems to work this.lastDynamicScoreCalculatedRoute = this.resultRoute; result.ForEach(i => i.DynamicScore = (i.StaticScore ?? 0) + 1); isFirstRun = false; if (!countScore) { break; } } else { Microsoft.SqlServer.Types.SqlGeography bufferSqlGeography = routeSqlGeography.STBuffer(bufferSize); points.Where(i => (bool)bufferSqlGeography.STContains(i.Point.ToSqlGeography())).ToList().ForEach(i => ++ i.DynamicScore); } bufferSize -= step; } return(result); }
private static Esri.ArcGISRuntime.Geometry.MapPoint ReadGeographyPoint(Microsoft.SqlServer.Types.SqlGeography p, Esri.ArcGISRuntime.Geometry.SpatialReference sr) { if (!p.M.IsNull) { if (!p.Z.IsNull) { return(Esri.ArcGISRuntime.Geometry.MapPoint.CreateWithM(p.Long.Value, p.Lat.Value, p.Z.Value, p.M.Value, sr)); } else { return(Esri.ArcGISRuntime.Geometry.MapPoint.CreateWithM(p.Long.Value, p.Lat.Value, p.M.Value, sr)); } } if (!p.Z.IsNull) { return(new Esri.ArcGISRuntime.Geometry.MapPoint(p.Long.Value, p.Lat.Value, p.Z.Value, sr)); } else { return(new Esri.ArcGISRuntime.Geometry.MapPoint(p.Long.Value, p.Lat.Value, sr)); } }
internal static Esri.ArcGISRuntime.Geometry.Geometry ReadGeography(Microsoft.SqlServer.Types.SqlGeography geography) { if (geography == null) { throw new ArgumentNullException("geography"); } Esri.ArcGISRuntime.Geometry.SpatialReference sr = null; if (!geography.STSrid.IsNull && geography.STSrid.Value > 0) { sr = Esri.ArcGISRuntime.Geometry.SpatialReference.Create(geography.STSrid.Value); } switch (geography.STGeometryType().Value) { case "Point": return(ReadGeographyPoint(geography, sr)); case "MultiPoint": return(ReadGeographyMultiPoint(geography, sr)); case "LineString": return(ReadGeographyLineString(geography, sr)); case "MultiLineString": return(ReadGeographyMultiLineString(geography, sr)); case "Polygon": return(ReadGeographyPolygon(geography, sr)); case "MultiPolygon": return(ReadGeographyMultiPolygon(geography, sr)); default: throw new NotSupportedException(geography.STGeometryType().Value); } }
private static Esri.ArcGISRuntime.Geometry.Geometry ReadGeographyMultiPolygon(Microsoft.SqlServer.Types.SqlGeography mpoly, Esri.ArcGISRuntime.Geometry.SpatialReference sr) { var rings = new List <IEnumerable <Esri.ArcGISRuntime.Geometry.MapPoint> >(); for (int j = 0; j < mpoly.STNumGeometries().Value; j++) { var poly = mpoly.STGeometryN(j); var innerRings = Utilities.CountEnumerator(poly.NumRings().Value) .Select(i => poly.RingN(i)) .Select(t => Utilities.CountEnumerator(t.STNumPoints().Value) .Select(r => t.STPointN(r)) .Select(p => ReadGeographyPoint(p, sr))); rings.AddRange(innerRings); } return(new Esri.ArcGISRuntime.Geometry.Polygon(rings)); }
partial void OnSpatialLocationChanging(Microsoft.SqlServer.Types.SqlGeography value);
public static Geometry FromSqlSpatialGeography(this Microsoft.SqlServer.Types.SqlGeography geography) { return(SqlServerConverter.ReadGeography(geography)); }