示例#1
0
        private static string CreatePolygon(MapFeature mapFeature, Kml2SqlConfig config, bool declareVariables)
        {
            var sb = new StringBuilder();

            if (declareVariables)
            {
                sb.Append("DECLARE @geom geometry;" + Environment.NewLine);
            }
            sb.Append("SET @geom = geometry::STPolyFromText('POLYGON((");
            sb.Append(GetOuterRingSql(mapFeature.Coordinates, config));
            foreach (Vector[] innerCoordinates in mapFeature.InnerCoordinates)
            {
                sb.Append(GetInnerRingSql(innerCoordinates, config));
            }
            sb.Append(@"))', " + config.Srid + @").MakeValid();" + Environment.NewLine);
            if (declareVariables)
            {
                sb.Append("DECLARE @validGeom geometry;" + Environment.NewLine);
            }
            sb.Append("SET @validGeom = @geom.MakeValid().STUnion(@geom.STStartPoint());");
            return(sb.ToString());
        }
示例#2
0
        private static string CreateLineString(MapFeature mapFeature, Kml2SqlConfig config, bool declareVariables)
        {
            var sb = new StringBuilder();

            if (declareVariables)
            {
                sb.Append("DECLARE @validGeom geometry;" + Environment.NewLine);
            }

            if (mapFeature.MultiCoordinates.Length == 0)
            {
                sb.Append("SET @validGeom = geometry::STLineFromText('LINESTRING (");
                foreach (Vector coordinate in mapFeature.Coordinates)
                {
                    sb.Append(coordinate.Longitude + " " + coordinate.Latitude + ", ");
                }
                sb.Remove(sb.Length - 2, 2).ToString();
            }
            else
            {
                sb.Append("SET @validGeom = geometry::STMLineFromText('MULTILINESTRING (");
                for (int i = 0; i < mapFeature.MultiCoordinates.Length; i++)
                {
                    sb.Append("(");
                    foreach (Vector coordinate in mapFeature.MultiCoordinates[i])
                    {
                        sb.Append(coordinate.Longitude.ToString("G20").Replace(',', '.') + " " + coordinate.Latitude.ToString("G20").Replace(',', '.') + ",");
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.Append("),");
                }
                sb.Remove(sb.Length - 1, 1).ToString();
            }

            sb.Append(@")', " + config.Srid + @");");
            return(sb.ToString());
        }
示例#3
0
        private static string ParseCoordinates(MapFeature mapFeature, Kml2SqlConfig config, bool declareVariables)
        {
            StringBuilder commandString = new StringBuilder();

            if (config.GeoType == PolygonType.Geography)
            {
                commandString.Append(ParseCoordinatesGeography(mapFeature, config, declareVariables));
                if (declareVariables)
                {
                    commandString.Append("DECLARE @placemark geography;" + Environment.NewLine);
                }
                commandString.Append("SET @placemark = @validGeo;" + Environment.NewLine);
            }
            else
            {
                commandString.Append(ParseCoordinatesGeometry(mapFeature, config, declareVariables));
                if (declareVariables)
                {
                    commandString.Append("DECLARE @placemark geometry;" + Environment.NewLine);
                }
                commandString.Append("SET @placemark = @validGeom;" + Environment.NewLine);
            }
            return(commandString.ToString());
        }
示例#4
0
        private static string GetParameters(MapFeature mapFeature, bool useParameters, string[] columnNames)
        {
            string parameters;

            if (useParameters)
            {
                var joined = string.Join(", ", columnNames.Select(x => "@" + x));
                parameters = $"@Id, @Name, {joined}";
                if (columnNames.Length > 0)
                {
                    parameters += ", ";
                }
            }
            else
            {
                var joinedData = string.Join(", ", mapFeature.Data.Values);
                parameters = $"{mapFeature.Id}, {joinedData}";
                if (mapFeature.Data.Values.Count > 0)
                {
                    parameters += ", ";
                }
            }
            return(parameters);
        }