简体   繁体   中英

C# - Array of Jagged Array

How to initialize and allocate array of jagged array? I am trying to create Geojson Polygon coordinates structure (with no holes) like the example geojson below using c# objects. My code able to generate the json which using jagged array and missing some bracket next to "coordinates": , but want that json like the example geojson, which can be possible using array of jagged array. Code example for array of jagged array would be appreciated.

My code generated

{ "type": "Polygon",
        "coordinates": 
          [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]

    }

Example Geojson Polygon

{ "type": "Polygon",
    "coordinates": [
      [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
      ]
}

Thanks.

Array of jagged arrays:

double[][][] coordinates = 
            {
                new double[][]
                    {
                        new double[] {1, 3, 5, 7, 9},
                        new double[] {0, 2, 4, 6},
                        new double[] {11, 22}
                    }
            };

But, in my opinion, your first code sample seems to do the job. Are you sure you need this?

Actually, why not an array of GeoPoint , where a GeoPoint holds two double s and is mapped to a json array when serialized?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM