Пример #1
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ��Mapguide���ص�����ת��ΪKML
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public String CreateWheatonMuni()
    {
        StringBuilder outString = new StringBuilder(1024000);
        outString.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        outString.Append("<kml xmlns=\"http://earth.google.com/kml/2.0\">");
        outString.Append("<Document>");
        outString.Append("<Style id=\"muniStyle\">");
        outString.Append("<PolyStyle>");
        outString.Append("<outline>1</outline>");
        outString.Append("<fill>0</fill>");
        outString.Append("<color>ff00ff00</color>");
        outString.Append("</PolyStyle>");
        outString.Append("<geomColor>ff00ff00</geomColor>");
        outString.Append("<geomScale>2</geomScale>");
        outString.Append("</Style>");

        outString.Append("<Folder>");
        outString.Append("<description>Tux - Wheaton Municipal Districts</description>");
        outString.Append("<name>Wheaton Municipal Districts</name>");
        outString.Append("<visibility>0</visibility>");
        outString.Append("<open>0</open>");

        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgResourceIdentifier resId = new MgResourceIdentifier("Library://MgTutorial/Data/WheatonMunicipalities.FeatureSource");
        MgFeatureReader featureReader = featureService.SelectFeatures(resId, "WheatonMunicipalities", null);
        MgAgfReaderWriter geoReader = new MgAgfReaderWriter();
        while (featureReader.ReadNext())
        {
            String muniName = featureReader.GetString("MUNINAME");
            MgByteReader byteReader = featureReader.GetGeometry("Geometry");
            MgGeometry geo = geoReader.Read(byteReader);

            outString.Append("<Placemark>");
            outString.Append("<name>" + muniName + "</name>");
            outString.Append("<description>" + muniName + "</description>");
            outString.Append("<styleUrl>#muniStyle</styleUrl>");

            PolygonWriter polygonWriter = new PolygonWriter();
            polygonWriter.EmitGeometry(geo, 0, 0);

            outString.Append(polygonWriter.getOutputString());
            outString.Append("</Placemark>");
        }
        featureReader.Close();

        outString.Append("</Folder>");
        outString.Append("</Document>");
        outString.Append("</kml>");

        return outString.ToString();
    }
Пример #2
0
    //----------------------------------------------------------------------------------------
    // �� �ܣ� ��Mapguide���ص�����ת��ΪKML
    //
    // �� �ߣ�
    //
    //
    // �� �ڣ�2007.05.#
    //
    //-----------------------------------------------------------------------------------------
    public String createSheboygon3D()
    {
        StringBuilder outString = new StringBuilder();

        outString.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        outString.Append("<kml xmlns=\"http://earth.google.com/kml/2.0\">");
        outString.Append("<Document>");
        outString.Append("<Style id=\"muniStyle\">");
        outString.Append("<PolyStyle>");
        outString.Append("<outline>1</outline>");
        outString.Append("<fill>1</fill>");
        outString.Append("<color>70000000</color>");
        outString.Append("</PolyStyle>");
        outString.Append("<LineStyle>");
        outString.Append("<color>ff0000ff</color>");
        outString.Append("</LineStyle>");
        outString.Append("</Style>");
        outString.Append("<Folder>");
        outString.Append("<description>Sheboygan Building Footprints 3D</description>");
        outString.Append("<name>Sheboygan Bulding Model</name>");
        outString.Append("<visibility>0</visibility>");
        outString.Append("<open>0</open>");

        MgGeometryFactory geoFactory = new MgGeometryFactory();
        MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgResourceIdentifier resId = new MgResourceIdentifier("Library://MgTutorial/Data/Sheboygan3D.FeatureSource");
        MgFeatureReader featureReader = featureService.SelectFeatures(resId, "Sheboygan3D", null);
        MgAgfReaderWriter geoReader = new MgAgfReaderWriter();

        outString.Append("<Placemark>");
        outString.Append("<name>3D Model</name>");
        outString.Append("<description>Sheboygan Building Model Area</description>");
        outString.Append("<styleUrl>#muniStyle</styleUrl>");

        PolygonWriter polygonWriter = new PolygonWriter();

        polygonWriter.StartEmitConsolidatedGeometry();

        while (featureReader.ReadNext())
        {
            MgByteReader byteReader = featureReader.GetGeometry("Geometry");
            double ht = featureReader.GetDouble("HEIGHT");
            MgGeometry geo = geoReader.Read(byteReader);
            polygonWriter.WriteConsolidatedGeometryRing(geo, 1, ht * 0.1);

        }

        featureReader.Close();
        polygonWriter.EndEmitConsolidatedGeometry();

        outString.Append(polygonWriter.getOutputString());
        outString.Append("</Placemark>");
        outString.Append("</Folder>");
        outString.Append("</Document>");
        outString.Append("</kml>");

        return outString.ToString();
    }