Generating CZML from Natural Earth II SVG data

I am trying to find information about using tools (perhaps CZML-writer) to convert SVG data downloaded from the Natural Earth project into a format that Cesium can use to display. Several years ago in 2015, a similar question was asked, and the reply from @Mark_Erikson included a sample data set containing country lines. I really appreciate that data, and I’ve successfully integrated those czml files into my viewer. However, I don’t understand how the author of the file was able to create the files.

I have cloned the forked repo GitHub - markerikson/czml-writer: A library for writing CZML content for use with Cesium, but I cannot find any documentation for using it. I see that there is one application in the CesiumLanguageWriter solution, GenerateFromSchema. Whether or not this utility is the application to use or not, I have built it and and see that there are two possible ways of running it:

Usage:
        GenerateWritersFromSchema <schema> markdown <outputFile>
        GenerateWritersFromSchema <schema> csharp <outputDirectory> <configurationFileName>

My main goal is to create similar data sets to show rivers, roads, the contintental United States, and perhaps each state’s counties. I just need a little assistance getting started.

Oh my. I haven’t thought about that repo in many years :slight_smile:

Um… unfortunately, looking at the list of branches, I don’t see any commits from me. So, it’s possible I never got around to pushing up my customizations and that the repo doesn’t have anything useful. Sorry :frowning:

I left that company earlier this year, so I definitely don’t have access to whatever changes I might have made, either,

That’s ok. Bad timing, I guess… :slight_smile:

Do you have any suggestions as to how to go about generating the coordinates? The czml format used for the country border data is fairly straight-forward. However, the .shp files are binary, so they aren’t as easy to just look at. I’ve been programming for a few decades now and have the gray hairs to prove it. I’m no stranger to having to figure things out; it’s just helpful when I don’t have to. :wink:

Obviously, you must have used czml-writer in the process. This utility is woefully lacking in terms of documentation or how it is to be used. I know it’s been many years since you looked at it, but any pointers you might have would be most appreciated.

Thanks so much for replying!

[edit]
After looking at the czml-writer project, I discovered it wasn’t as difficult to use as I had feared. I made a quick and dirty console app passing a shape file from Natural Earth (ne_10m_admin_0_countries.shp, if interested) and was able to make an assumption that at least seems plausible.

I’m including my source code. Please excuse the terrible variable names… I’m more wanting to verify that I’m on the right track. I can clean it up later. As I explain below, I used Albania for my test, and the numbers in the shapefile are close to those reported in the czml file that you provided several years ago.

        static void Main(string[] args)
        {
            ShapefileReader sf = new ShapefileReader("c:/build/cesium/country_data/ne_10m_admin_0_countries.shp");

            if (sf == null)
            {
                System.Console.WriteLine("uh-oh");
                return;
            }

            foreach (Shape s in sf._shapes)
            {
                PolygonShape ps = s as PolygonShape;

                if (ps != null)
                {
                    string country = s.GetMetadataValue("brk_name");

                    // discovered that country names might have a long trail of
                    // \0 characters.  
                    int nullIndex = country.IndexOf("\0");

                    if (nullIndex >= 0)
                    {
                        country = country.Substring(0, nullIndex);
                    }

                    // I chose Albania at random.
                    // First few coordinates in czml file (see linked post) for Albania
                    // [ 0.3593676114556317, 0.7305146123647166, 0.0,
                    //   0.3571497806121453, 0.7245749925925384, 0.0,
                    //   0.35962826745960563, 0.7170899262362601, 0.0, ... ]

                    if (country == "Albania")
                    {
                        for (int i=0; i<ps.Count; i++)
                        {
                            ShapePart sp = ps[i];

                            if (sp != null)
                            {
                                for (int posIndex = 0; posIndex < sp.Count; posIndex++)
                                {
                                    Cartographic c = sp[posIndex];
                                    if (c != null)
                                    {
                                        // first 5 coordinates are:
                                        // 0.358964, 0.730825
                                        // 0.358521, 0.730622
                                        // 0.358504, 0.730331
                                        // 0.358499, 0.730236
                                        // 0.358638, 0.729795

                                        // These aren't exact matches to what was in the CZML file, but they seem close.

                                        Console.WriteLine($"{c.Longitude.ToString("0.000000")}, " +
                                            $"{c.Latitude.ToString("0.000000")}");
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return;
        }

Based on the previous code, I’ve constructed a CZML file and have somewhat positive results. However, some of the vectors are all over the place. In the image below, the gulf of Mexico is shown, and a clear outline can be seen showing the coastline between Texas and Florida. However, there’s a lot of extra noise in the data as well.

Any ideas?