[fdo-users] SDF2 to SDF3

Tom Fukushima tom.fukushima at autodesk.com
Mon Jan 18 12:29:22 EST 2010


Here is a C# program using the Studio API that I hacked together a few years ago to convert from SDF2 to 3. To compile, you will need references to the following assemblies: Autodesk.Gis.CoordinateSystems, Autodesk.MapGuide.Studio.FdoLoader, and SDFConverter.  You can find these assemblies in your Studio directory; after compiling you will probably need to run the executable from your Studio directory so that all the proper dependencies can be found.

Cheers
Tom


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Autodesk.Gis.CoordinateSystems;

namespace SdfConv
{
    class Program
    {
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(Resource1.ResourceManager.GetString("Usage")); // NOXLATE
                return 0;
            }

            string cscode = "LL84"; // NOXLATE

            bool useKey = false;
            bool mergeDuplicates = false;

            int i = 0;
            for ( ; i < args.Length; i++)
            {
                //check for --generate-ids option
                if (args[i].ToLower().Equals("--generate-ids")) //NOXLATE
                {
                    useKey = false;
                    continue;
                }

                //check for --use-key option
                else if (args[i].ToLower().Equals("--use-key")) //NOXLATE
                {
                    useKey = true;
                    continue;
                }

                else if (args[i].ToLower().Equals("--merge-duplicates")) // NOXLATE
                {
                    mergeDuplicates = true;
                    continue;
                }

                // check for --mentor-code
                else if (args[i].ToLower().Equals("--mentor-code")) // NOXLATE
                {
                    i++;
                    cscode = args[i];
                    continue;
                }

                else if (args[i].StartsWith("--")) // NOXLATE
                {
                    Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("UnknownOption"), args[i]));
                    return -20;
                }

                else
                    break;

            }

            string inFile = null;
            string outFile = null;

            if (i < args.Length)
                inFile = args[i];
            else
            {
                Console.WriteLine(Resource1.ResourceManager.GetString("noInputFile")); // NOXLATE
                return -10;
            }

            i++;
            if (i < args.Length)
                outFile = args[i];
            else
            {
                Console.WriteLine(Resource1.ResourceManager.GetString("noOutputFile")); // NOXLATE
                return -11;
            }

#if DEBUG
            File.Delete(outFile);
#endif
            if (File.Exists(outFile))
            {
                Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("OutputFileExists"), outFile)); // NOXLATE
                return -1;
            }

            if (!File.Exists(inFile))
            {
                Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("InputFileNotFound"), inFile)); // NOXLATE
            }

            string wkt = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; // NOXLATE
            if (cscode != null && cscode.Length != 0)
            {
                try
                {
                    wkt = MapCoordinateSystem.ConvertCoordinateSystemCodeToWkt(cscode);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("InvalidCSCode"), cscode, ex.ToString())); //NOXLATE
                    return -2;
                }
            }

            try
            {
                Autodesk.MapGuide.Studio.FdoLoader.FdoLoader.Initialize();
                if (SdfConverter.GetSdfFileVersion(inFile) >= 3)
                {
                    Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("AlreadySDF3"), inFile)); // NOXLATE
                    return -4;
                }

                Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("ConversionSummary"), //NOXLATE
                    new object[] { inFile, outFile, cscode, wkt, useKey ? "use key" : "generate ids", mergeDuplicates.ToString() })); // NOXLATE
                Console.WriteLine(Resource1.ResourceManager.GetString("Start")); // NOXLATE
                SdfConverter.Convert(inFile,
                    outFile,
                    wkt,
                    useKey,
                    mergeDuplicates
                );
                Console.WriteLine(Resource1.ResourceManager.GetString("Done")); // NOXLATE
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format(Resource1.ResourceManager.GetString("UnknownException"), ex.ToString())); // NOXLATE
                return -3;
            }
            return 0;
        }
    }
}

-----Original Message-----
From: fdo-users-bounces at lists.osgeo.org [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Jackie Ng
Sent: January-18-10 5:25 AM
To: fdo-users at lists.osgeo.org
Subject: Re: [fdo-users] SDF2 to SDF3


I haven't actually used the Studio API, but I do know it has the classes that
do what you want to do. You're best to look at the MG Studio API
documentation. 

- Jackie


Davidow wrote:
> 
> Hi Jackie,
> 
> Can you give me some start information to convert SDF 2 to SDF 3 with
> MapGuide Studio API in Visual Studio C#.
> 
> Which dll’s i need for this?
> 
> Dennis
> 
> 
> 
> Jackie Ng wrote:
>> 
>> The only known way to convert from SDF 2 to SDF 3 is to use the MapGuide
>> Studio API which has this functionality.
>> 
>> Another (completely) unproven/untested way would be to read from your
>> SDF2 file using the SDF component toolkit, convert the SDF2 geometry to
>> FGF (that's the tricky part), and write the converted features to your
>> SDF3 file.
>> 
>> - Jackie
>> 
>> 
>> Davidow wrote:
>>> 
>>> Hello to all
>>> 
>>> I would like to convert SDF data
>>> 
>>> SDF version 2 to SDF version 3
>>> 
>>> You know what some ways to implement this in. NET environment ?
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/SDF2-to-SDF3-tp4290710p4413356.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
fdo-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users


More information about the fdo-users mailing list