Example #1
0
            public override void ParseJson(DbGeographyGeoJsonConverter converter, Newtonsoft.Json.Linq.JArray array)
            {
                var targetCoordinateSystem = (converter as EpsgDbGeometryConverter).CoordinateSystem;

                //Cant convert if source dont have any coordinate system.
                if (!CoordinateSystem.HasValue || CoordinateSystem == targetCoordinateSystem)
                {
                    base.ParseJson(converter, array);
                    return;
                }



                Rings = new List <List <Position> >();
                var rings = array.ToObject <double[][][]>();

                var ringSizes        = rings.Select(r => r.Length).ToArray();
                var coordinateLength = rings.First().GroupBy(c => c.Length).Single().Key;

                foreach (var ring in rings)
                {
                    var flat = ring.SelectMany(s => s).ToArray();

                    Reproject.ReprojectPoints(flat, null,
                                              ProjectionInfo.FromEpsgCode(CoordinateSystem.Value), ProjectionInfo.FromEpsgCode(targetCoordinateSystem.Value), 0, ringSizes[0]);

                    var ringList = new List <Position>();
                    for (int i = 0; i < flat.Length; i += coordinateLength)
                    {
                        ringList.Add(new Position(flat.Skip(i).Take(coordinateLength).ToArray()));
                    }
                    Rings.Add(ringList);
                }
                CoordinateSystem = targetCoordinateSystem;
            }
 /// <inheritdoc/>
 public override void ParseJson(JsonReader reader)
 {
     this.Entries = new List <GeoBase>();
     reader.Read();
     if (reader.TokenType != JsonToken.StartArray)
     {
         throw new ArgumentException(
                   string.Format("Expected the start of a geometries array, got {0}", reader.TokenType));
     }
     this.Entries = new List <GeoBase>();
     for (;;)
     {
         reader.Read();
         if (reader.TokenType != JsonToken.StartObject)
         {
             if (reader.TokenType != JsonToken.EndArray)
             {
                 throw new ArgumentException(
                           string.Format("Expected StartObject or EndArray JSON token, got {0}", reader.TokenType),
                           "reader");
             }
             break;
         }
         this.Entries.Add(DbGeographyGeoJsonConverter.ReadType(reader)(reader));
         reader.Read();
         if (reader.TokenType != JsonToken.EndObject)
         {
             throw new ArgumentException(
                       string.Format("Expected EndObject JSON token, got {0}", reader.TokenType),
                       "reader");
         }
     }
 }
            public override void ParseJson(DbGeographyGeoJsonConverter converter, Newtonsoft.Json.Linq.JArray array)
            {
                var targetCoordinateSystem = (converter as EpsgDbGeometryConverter).CoordinateSystem;
                //Cant convert if source dont have any coordinate system.
                if (!CoordinateSystem.HasValue ||  CoordinateSystem == targetCoordinateSystem)
                {
                    base.ParseJson(converter, array);
                    return;
                }

                Rings = new List<List<Position>>();
                var rings = array.ToObject<double[][][]>();

                var ringSizes = rings.Select(r => r.Length).ToArray();
                var coordinateLength = rings.First().GroupBy(c => c.Length).Single().Key;
                foreach (var ring in rings)
                {
                    var flat = ring.SelectMany(s => s).ToArray();

                    Reproject.ReprojectPoints(flat, null,
                     ProjectionInfo.FromEpsgCode(CoordinateSystem.Value), ProjectionInfo.FromEpsgCode(targetCoordinateSystem.Value), 0, ringSizes[0]);

                    var ringList = new List<Position>();
                    for (int i = 0; i < flat.Length; i += coordinateLength)
                        ringList.Add(new Position(flat.Skip(i).Take(coordinateLength).ToArray()));
                    Rings.Add(ringList);
                }
                CoordinateSystem = targetCoordinateSystem;
            }
 /// <inheritdoc/>
 public override void ParseJson(JArray array)
 {
     this.Entries = new List <GeoBase>();
     foreach (var elem in array)
     {
         if (elem.Type != JTokenType.Object)
         {
             throw new ArgumentException(
                       string.Format("Expected object elements of the collection array, got {0}", elem.Type),
                       "array");
         }
         int?dummyCoordinateSystem;
         this.Entries.Add(DbGeographyGeoJsonConverter.ParseJsonObjectToGeoBase((JObject)elem, out dummyCoordinateSystem));
     }
 }