Click here to Skip to main content
15,886,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm hoping you can help me. I have the a fairly complex object that represents geoJson data. The class was generated by placing some of the geojson into the converter found here.

The code that is generated works fine when I'm de-serialising for conversion and storing into a database, however when I come to retrieve the data and re-serialise it I am getting some very strange behaviour.

Here is a brief snippet of my json:

C#
{"type":"FeatureCollection",
 "crs": {"type":"name",
         "properties":{ "name":"urn:ogc:def:crs:OGC:1.3:CRS84"}},
 "features":[
   {"type":"Feature",
    "properties":{"name":"AB","color":"#0E0299"},
    "geometry":{"type":"MultiPolygon",
                "coordinates":[[[[56.8860559718878,-2.21295884939764],
                                 [-2.22418043724705,56.8874548172591],
                                 [56.8873756021234,-2.22608015201419],
                                 [-2.24113736145235,56.8942204769533],
                                 [56.8953863168858,-2.24940218298088],
                                 [-2.25140561654796,56.8950015957031],
                                 [56.8950244655219,-2.25393237467251],
                                 [-2.26499735012973,56.8885090148966],
                                 [56.8827985864266,-2.28369393347917]]]]}}]}

Rather than putting this in twice I will explain what is wrong. Every other entry in the coordinates list is reversed. So the second pair of values is back to front.

However when I look at the data in the original class before serialisation they are in the correct order (i.e. 56.8874... comes first then, -2.2241....)

If you put that json into the class generator I linked it basically creates the classes I'm using.

It is the following property that is resulting in the issues:

C#
public List<List<List<List<double>>>> coordinates { get; set; }

Firstly, I think it is hideous, but that aside it makes it hard to see what exactly is going on.

My question is:

How can I maintain the order of my coordinates within my list as these coordinates represent steps along a path. By reversing every other coordinate when I plot them on my world map it jumps between two sides of the world, which is completely wrong.

If you need more information or my question isn't clear please let me know.
Posted
Comments
BillWoodruff 28-Jan-15 1:48am    
This is the type of problem I think it might be very difficult to analyze without all the code. You might try using Mehdi Gholam's JSON tools here on CodeProject (I'm assuming you are using the Newton tools that .NET provides) and see if you get the same ordering:

http://www.codeproject.com/Articles/159450/fastJSON

http://www.codeproject.com/Articles/345070/fastBinaryJSON
Pheonyx 28-Jan-15 9:40am    
Hi @BillWoodruff, thank's for your response. I found the issue this morning and it wasn't the serialisation at all. It was actually the linq that was populating my object. I thought I had checked that it was all working correctly however when my foreach loops were getting migrated to LINQ something was going haywire and resulting in very strange behaviour. Having reverted back to the foreach loops it appears to be working without an issue now. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900