///<summary> /// Returns the angle of the vector from p0 to p1, /// relative to the positive X-axis. /// The angle is normalized to be in the range [ -Pi, Pi ]. ///</summary> ///<param name="p0"></param> ///<param name="p1"></param> ///<returns>the normalized angle (in radians) that p0-p1 makes with the positive x-axis.</returns> public static double CalculateAngle(Microsoft.SqlServer.Types.SqlGeometry p0, Microsoft.SqlServer.Types.SqlGeometry p1) { Double dx = p1.STX.Value - p0.STX.Value; Double dy = p1.STY.Value - p0.STY.Value; return(Math.Atan2(dy, dx)); }
public override void WriteMultiPolygon(Microsoft.SqlServer.Types.SqlGeometry geom) { try { List <double[][][]> polygons = new List <double[][][]>(geom.STNumGeometries().Value); for (int i = 1; i <= geom.STNumGeometries().Value; i++) { SqlGeometry curPoly = geom.STGeometryN(i); List <SqlGeometry> interiorRings = null; int numIntRings = curPoly.STNumInteriorRing().Value; if (numIntRings > 0) { interiorRings = new List <SqlGeometry>(numIntRings); for (int j = 1; j <= numIntRings; j++) { interiorRings.Add(curPoly.STInteriorRingN(j)); } } polygons.Add(this.GeoJsonPolygonFromSqlGeometry(geom.STExteriorRing(), interiorRings).coordinates); } GeoJson.MultiPolygon multiPoly = new GeoJson.MultiPolygon(); multiPoly.coordinates = polygons.ToArray(); _features.Add(new GeoJson.Feature() { geometry = multiPoly }); } catch (Exception) { throw; } }
public override void WritePoint(Microsoft.SqlServer.Types.SqlGeometry geom) { double x, y; _coordConverter.TransformPoint(geom.STX.Value, geom.STY.Value, out x, out y); this.WritePoint_Internal(x, y); }
public override void WriteMultiPoint(Microsoft.SqlServer.Types.SqlGeometry geom) { for (int i = 1; i <= geom.STNumPoints().Value; i++) { this.WritePoint(geom.STPointN(i)); } }
public override void WriteMultiLineString(Microsoft.SqlServer.Types.SqlGeometry geom) { for (int i = 1; i <= geom.STNumGeometries().Value; i++) { this.WriteLineString(geom.STGeometryN(i)); } }
internal SqlGeometry(SqlTypes.SqlGeometry sg, ICoordinateSystem coordinateSystem) { Debug.Assert(sg != null); if (sg == null) { throw new ArgumentNullException("sg"); } _Geometry = sg; _CoordinateSystem = coordinateSystem; }
public static Dictionary <string, object> PointToJson(Microsoft.SqlServer.Types.SqlGeometry point) { Dictionary <string, object> geometry = new Dictionary <string, object>(); geometry.Add("type", "Point"); List <object> coordinates = new List <object>(); coordinates.Add(Convert.ToDouble(point.STX.Value)); coordinates.Add(Convert.ToDouble(point.STY.Value)); geometry.Add("coordinates", coordinates); return(geometry); }
public override void WriteMultiPolygon(Microsoft.SqlServer.Types.SqlGeometry geom) { try { for (int i = 1; i <= geom.STNumGeometries().Value; i++) { this.WritePolygon(geom.STGeometryN(i)); } } catch (Exception) { throw; } }
private ViewModel.Polyline GetFromSqlGeometry(Microsoft.SqlServer.Types.SqlGeometry multiPoint) { var result = new ViewModel.Polyline() { Locations = new LocationCollection() }; for (int i = 1; i <= multiPoint.STNumPoints(); i++) { Microsoft.SqlServer.Types.SqlGeometry point = multiPoint.STPointN(i); result.Locations.Add(new Location((double)point.STY, (double)point.STX)); } return(result); }
public override void WritePolygon(Microsoft.SqlServer.Types.SqlGeometry polygon) { try { GeoJson.Polygon poly = this.GeoJsonPolygonFromSqlGeometry(polygon.STExteriorRing(), base.GetPolygonInteriorRings(polygon)); GeoJson.Feature feature = new GeoJson.Feature(); feature.geometry = poly; _features.Add(feature); } catch (Exception v_ex) { throw; } }
public override void WritePoint(Microsoft.SqlServer.Types.SqlGeometry geom) { try { double[] ptCoords = this.ConvertPoint(geom.STPointN(1)); GeoJson.Point pt = new GeoJson.Point(ptCoords[0], ptCoords[1]); _features.Add(new GeoJson.Feature() { geometry = pt }); } catch (Exception) { throw; } }
private static Dictionary <string, object> GeometryToJson(Microsoft.SqlServer.Types.SqlGeometry geometry) { if ((string)geometry.STGeometryType() == "Point") { return(PointToJson(geometry)); } if ((string)geometry.STGeometryType() == "LineString") { return(LineStringToJson(geometry)); } if ((string)geometry.STGeometryType() == "Polygon") { return(PolygonToJson(geometry)); } return(null); }
public static Dictionary <string, object> MultiPolygonToJson(Microsoft.SqlServer.Types.SqlGeometry multipolygon) { Dictionary <string, object> geometry = new Dictionary <string, object>(); geometry.Add("type", "MultiPolygon"); List <object> polygons = new List <object>(); int geometries = (int)multipolygon.MakeValid().STNumGeometries(); for (int k = 1; k <= geometries; k++) { Microsoft.SqlServer.Types.SqlGeometry polygon = multipolygon.MakeValid().STGeometryN(k); List <object> coordinates = new List <object>(); // exterior ring int expoints = (int)polygon.STExteriorRing().STNumPoints(); List <object> ring = new List <object>(); for (int j = 1; j <= expoints; j++) { List <object> coordinate = new List <object>(); coordinate.Add(Convert.ToDouble(polygon.STPointN(j).STX.Value)); coordinate.Add(Convert.ToDouble(polygon.STPointN(j).STY.Value)); ring.Add(coordinate); } coordinates.Add(ring); // interior rings ring = new List <object>(); int rings = (int)polygon.STNumInteriorRing(); for (int i = 1; i <= rings; i++) { int inpoints = (int)polygon.STInteriorRingN(i).STNumPoints(); List <object> inring = new List <object>(); for (int j = 1; j <= inpoints; j++) { List <object> coordinate = new List <object>(); coordinate.Add(Convert.ToDouble(polygon.STInteriorRingN(i).STPointN(j).STX.Value)); coordinate.Add(Convert.ToDouble(polygon.STInteriorRingN(i).STPointN(j).STY.Value)); ring.Add(coordinate); } coordinates.Add(ring); } polygons.Add(coordinates); } geometry.Add("coordinates", polygons); return(geometry); }
public static Dictionary <string, object> LineStringToJson(Microsoft.SqlServer.Types.SqlGeometry lineString) { Dictionary <string, object> geometry = new Dictionary <string, object>(); geometry.Add("type", "LineString"); List <object> coordinates = new List <object>(); int points = (int)lineString.STNumPoints(); for (int i = 1; i <= points; i++) { List <object> coordinate = new List <object>(); coordinate.Add(Convert.ToDouble(lineString.STPointN(i).STX.Value)); coordinate.Add(Convert.ToDouble(lineString.STPointN(i).STY.Value)); coordinates.Add(coordinate); } geometry.Add("coordinates", coordinates); return(geometry); }
public override void WriteLineString(Microsoft.SqlServer.Types.SqlGeometry geom) { try { List <double[]> coords = this.ConvertAndAccumulateDistinctPoints(geom); if (coords.Count > 0) { GeoJson.LineString linestring = new GeoJson.LineString() { coordinates = coords.ToArray() }; _features.Add(new GeoJson.Feature() { geometry = linestring }); } } catch (Exception) { throw; } }
public override void WriteMultiLineString(Microsoft.SqlServer.Types.SqlGeometry geom) { List <double[][]> lineStrings = new List <double[][]>(); try { for (int i = 1; i <= geom.STNumGeometries().Value; i++) { lineStrings.Add(this.GeoJsonLineStringFromSqlGeometry(geom.STGeometryN(i)).coordinates); } } catch (Exception) { throw; } _features.Add(new GeoJson.Feature() { geometry = new GeoJson.MultiLineString() { coordinates = lineStrings.ToArray() } }); }
public override void WriteMultiPoint(Microsoft.SqlServer.Types.SqlGeometry geom) { try { List <double[]> ptCoords = new List <double[]>(); for (int i = 1; i < geom.STNumPoints().Value; i++) { ptCoords.Add(this.ConvertPoint(geom.STPointN(i))); } GeoJson.MultiPoint multiPt = new GeoJson.MultiPoint(); multiPt.coordinates = ptCoords.ToArray(); _features.Add(new GeoJson.Feature() { geometry = multiPt }); } catch (Exception) { throw; } }
public static string DataSetToJSON(DataSet ds) { if (ds.Tables[0].Rows.Count == 0) { return(""); } string geometryColumn = DiscoverGeometryColumn(ds.Tables[0].Rows[0]); List <object> featureObjects = new List <object>(); foreach (System.Data.DataRow fdr in ds.Tables[0].Rows) { Dictionary <string, object> featureObject = new Dictionary <string, object>(); featureObject.Add("type", "Feature"); Dictionary <string, object> geometry = null; if (geometryColumn != null) { Microsoft.SqlServer.Types.SqlGeometry sqlGeometry = (Microsoft.SqlServer.Types.SqlGeometry)fdr[geometryColumn]; geometry = GeometryToJson(sqlGeometry); Dictionary <string, object> crs = GetCrs((int)sqlGeometry.STSrid); featureObject.Add("crs", crs); } Dictionary <string, object> properties = GetProperties(fdr); featureObject.Add("geometry", geometry); featureObject.Add("properties", properties); featureObjects.Add(featureObject); } Dictionary <string, object> featureCollection = new Dictionary <string, object>(); featureCollection.Add("type", "FeatureCollection"); featureCollection.Add("features", featureObjects); string json = JSON.JsonEncode(featureCollection); return(json); }
partial void OnSP_GEOMETRYChanging(Microsoft.SqlServer.Types.SqlGeometry value);
public override double[] ConvertPoint(Microsoft.SqlServer.Types.SqlGeometry point) { double[] coords = new double[2]; _coordConverter.TransformPoint(point.STX.Value, point.STY.Value, out coords[0], out coords[1]); return(coords); }
public override void WriteLineString(Microsoft.SqlServer.Types.SqlGeometry geom) { _gpStroke.StartFigure(); DrawLineString(this.ConvertAndAccumulateDistinctPoints(geom)); }
private GeoJson.Polygon GeoJsonPolygonFromSqlGeometry(Microsoft.SqlServer.Types.SqlGeometry exteriorRing, List <SqlGeometry> interiorRings) { List <double[][]> ringList = new List <double[][]>(); try { List <double[]> extRingPoints = this.ConvertAndAccumulateDistinctPoints(exteriorRing); switch (extRingPoints.Count) { case 0: break; case 1: Trace.WriteLine("Warning: 1 point for polygon"); //this.WritePoint_Internal(extRingPoints[0].X, extRingPoints[0].Y); break; case 2: Trace.WriteLine("Warning: 2 points for polygon"); //_gpStroke.AddLines(extRingPoints.ToArray()); break; default: ringList.Add(extRingPoints.ToArray()); break; } // Polygones intérieurs if (interiorRings != null) { foreach (SqlGeometry interiorRing in interiorRings) { List <double[]> intRingPoints = this.ConvertAndAccumulateDistinctPoints(interiorRing); switch (intRingPoints.Count) { case 0: break; case 1: //bmp.SetPixel(extRingPointArray[0].X, extRingPointArray[0].Y, strokeColor.Color); //graphicsPath.AddLine(v_polyInterieurPoints[0], v_polyInterieurPoints[0]); break; case 2: Trace.WriteLine("Warning: 2 points for polygon interior ring"); //_gpStroke.AddLine(intRingPoints[0], intRingPoints[1]); break; default: double[][] coords = intRingPoints.ToArray(); ringList.Add(coords); break; } } } } catch (Exception v_ex) { throw; } return(new GeoJson.Polygon() { coordinates = ringList.ToArray() }); }
/// <summary>Creates a new instance of the <see cref="SqlGeometry" /> class.</summary> public SqlGeometry(SqlTypes.SqlGeometry sg) : this(sg, null) { }