Exemple #1
0
        /// <summary>
        /// Reads GeoJson and returns the geometry.
        /// </summary>
        /// <param name="jsonReader"></param>
        /// <returns></returns>
        internal static Geometry ReadGeometry(JsonReader jsonReader)
        {
            var             geometryType = string.Empty;
            var             coordinates  = new List <object>();
            List <Geometry> geometries   = null;

            while (jsonReader.Read())
            {
                if (jsonReader.TokenType == JsonToken.EndObject)
                { // end of geometry.
                    break;
                }

                if (jsonReader.TokenType == JsonToken.PropertyName)
                {
                    if ((string)jsonReader.Value == "type")
                    { // the geometry type.
                        geometryType = jsonReader.ReadAsString();
                    }
                    else if ((string)jsonReader.Value == "geometries")
                    { // the geometries if a geometry collection.
                        geometries = GeoJsonConverter.ReadGeometryArray(jsonReader);
                    }
                    else if ((string)jsonReader.Value == "coordinates")
                    {                      // the coordinates.
                        jsonReader.Read(); // move to first array start.
                        coordinates = GeoJsonConverter.ReadCoordinateArrays(jsonReader);
                    }
                }
            }

            // data has been read, instantiate the actual object.
            switch (geometryType)
            {
            case "Point":
                return(GeoJsonConverter.BuildPoint(coordinates));

            case "LineString":
                return(GeoJsonConverter.BuildLineString(coordinates));

            case "Polygon":
                return(GeoJsonConverter.BuildPolygon(coordinates));

            case "MultiPoint":
                return(GeoJsonConverter.BuildMultiPoint(coordinates));

            case "MultiLineString":
                return(GeoJsonConverter.BuildMultiLineString(coordinates));

            case "MultiPolygon":
                return(GeoJsonConverter.BuildMultiPolygon(coordinates));

            case "GeometryCollection":
                return(GeoJsonConverter.BuildGeometryCollection(geometries));
            }
            throw new Exception(string.Format("Unknown geometry type: {0}", geometryType));
        }
Exemple #2
0
 /// <summary>
 /// Builds the geometry from the given coordinates.
 /// </summary>
 /// <param name="coordinates"></param>
 /// <returns></returns>
 internal static MultiPolygon BuildMultiPolygon(List <object> coordinates)
 {
     if (coordinates == null)
     {
         throw new ArgumentNullException();
     }
     if (coordinates.Count >= 1)
     {
         var polygons = new List <Polygon>();
         foreach (List <object> coordinates1 in coordinates)
         {
             polygons.Add(GeoJsonConverter.BuildPolygon(coordinates1));
         }
         return(new MultiPolygon(polygons));
     }
     throw new Exception("Invalid coordinate collection.");
 }
Exemple #3
0
        internal static MultiPolygon BuildMultiPolygon(List <object> coordinates)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException();
            }
            if (coordinates.Count < 1)
            {
                throw new Exception("Invalid coordinate collection.");
            }
            List <Polygon> polygonList = new List <Polygon>();

            foreach (List <object> coordinate in coordinates)
            {
                polygonList.Add(GeoJsonConverter.BuildPolygon(coordinate));
            }
            return(new MultiPolygon((IEnumerable <Polygon>)polygonList));
        }
Exemple #4
0
        internal static Geometry ReadGeometry(JsonReader jsonReader)
        {
            string          s           = string.Empty;
            List <object>   coordinates = new List <object>();
            List <Geometry> geometries  = (List <Geometry>)null;

            while (jsonReader.Read() && jsonReader.TokenType != JsonToken.EndObject)
            {
                if (jsonReader.TokenType == JsonToken.PropertyName)
                {
                    if ((string)jsonReader.Value == "type")
                    {
                        s = jsonReader.ReadAsString();
                    }
                    else if ((string)jsonReader.Value == "geometries")
                    {
                        geometries = GeoJsonConverter.ReadGeometryArray(jsonReader);
                    }
                    else if ((string)jsonReader.Value == "coordinates")
                    {
                        jsonReader.Read();
                        coordinates = GeoJsonConverter.ReadCoordinateArrays(jsonReader);
                    }
                }
            }
            // ISSUE: reference to a compiler-generated method
            long stringHash = s.GetHashCode();// \u003CPrivateImplementationDetails\u003E.ComputeStringHash(s);

            if (stringHash <= 2386032169U)
            {
                if ((int)stringHash != 1547714260)
                {
                    if ((int)stringHash != 2050635977)
                    {
                        if ((int)stringHash == -1908935127 && s == "Polygon")
                        {
                            return((Geometry)GeoJsonConverter.BuildPolygon(coordinates));
                        }
                    }
                    else if (s == "MultiLineString")
                    {
                        return((Geometry)GeoJsonConverter.BuildMultiLineString(coordinates));
                    }
                }
                else if (s == "MultiPolygon")
                {
                    return((Geometry)GeoJsonConverter.BuildMultiPolygon(coordinates));
                }
            }
            else if (stringHash <= 3786658501U)
            {
                if ((int)stringHash != -600749884)
                {
                    if ((int)stringHash == -508308795 && s == "GeometryCollection")
                    {
                        return((Geometry)GeoJsonConverter.BuildGeometryCollection(geometries));
                    }
                }
                else if (s == "MultiPoint")
                {
                    return((Geometry)GeoJsonConverter.BuildMultiPoint(coordinates));
                }
            }
            else if ((int)stringHash != -358027471)
            {
                if ((int)stringHash == -200799438 && s == "LineString")
                {
                    return((Geometry)GeoJsonConverter.BuildLineString(coordinates));
                }
            }
            else if (s == "Point")
            {
                return((Geometry)GeoJsonConverter.BuildPoint(coordinates));
            }
            throw new Exception(string.Format("Unknown geometry type: {0}", (object)s));
        }