public override void WriteMultiPoint(Microsoft.SqlServer.Types.SqlGeometry geom)
 {
     for (int i = 1; i <= geom.STNumPoints().Value; i++)
     {
         this.WritePoint(geom.STPointN(i));
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 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;
     }
 }
Beispiel #6
0
        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;
            }
        }