예제 #1
0
        public static geKML RunExample(string FileName)
        {
            Utilities util = new Utilities();

            // Point

            geFolder fld = util.SqlGeogCommandToKmlFolder(
                "server=.;database=geonames;integrated security=sspi",
                "select top(10) geog, name from geonames",
                "Sample Folder");

            //Now that we have our document, lets create our KML
            geKML kml = new geKML(fld);

            return(kml);
        }
예제 #2
0
        public geFolder SqlGeogCommandToKmlFolder(string connstr, string cmdstr, string fldname)
        {
            geFolder fld = new geFolder();

            fld.Name = fldname;

            using (SqlConnection conn = new SqlConnection(connstr))
                using (SqlCommand cmd = new SqlCommand(cmdstr, conn))
                {
                    try
                    {
                        conn.Open();
                        SqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            SqlGeography geog = (SqlGeography)rdr.GetValue(0);
                            if (!IsNullOrEmpty(geog))
                            {
                                gePlacemark pm = new gePlacemark();

                                if (rdr.FieldCount == 3)
                                {
                                    pm = SqlGeogToKmlPlacemark(geog,
                                                               rdr.GetString(1),
                                                               rdr.GetString(2));
                                }
                                else
                                {
                                    pm = SqlGeogToKmlPlacemark(geog,
                                                               rdr.GetString(1),
                                                               rdr.GetString(1));
                                }
                                fld.Features.Add(pm);
                            }
                        }
                    }
                    catch
                    {
                        return(null);
                    }
                }

            return(fld);
        }
예제 #3
0
 private void processLayerProperties(LayerProperties lp, geFolder folder)
 {
     if (lp.Layeru is IFeatureLayer)
     {
         if ((lp.Layeru as IFeatureLayer).FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
         {
             processPolyLineLayer(lp, folder);
         }
         if ((lp.Layeru as IFeatureLayer).FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
         {
             processPointLayer(lp, folder);
         }
         if ((lp.Layeru as IFeatureLayer).FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
         {
             processPolygonLayer(lp, folder);
         }
     }
     if (lp.Layeru is IRasterLayer)
     {
         processRasterLayer(lp, folder);
     }
 }
예제 #4
0
        public void Generate(string path, ProgressBar pBar)
        {
            //generates document at path. shows progress using progressbar pBar

            this.Path        = path;
            kmlDocument.Name = System.IO.Path.GetFileName(path);;
            kmlDocument.StyleSelectors.Add(defaultStyle);

            //create a step in the progressbar for each layer
            int nrLayers = kmlLayers.Count;

            pBar.Minimum = 0;
            pBar.Maximum = nrLayers + 1;
            pBar.Step    = 1;
            //should generate a kml document at path...
            //first, iterate layers. Each layer makes a folder
            foreach (LayerProperties lp in kmlLayers)
            {
                //create a folder for the layer
                geFolder folder = new geFolder();
                folder.Name        = lp.name;
                folder.Open        = true;
                folder.Description = lp.Layeru.Name;

                processLayerProperties(lp, folder);

                kmlDocument.Features.Add(folder);
                pBar.PerformStep();
            }

            //no more layers, get document :)
            geKML kml = new geKML(kmlDocument);

            File.WriteAllBytes(path, kml.ToKML());
            pBar.PerformStep();
            //ProcessStartInfo psInfNotepad = new ProcessStartInfo("notepad.exe", path);
            //Process.Start(psInfNotepad);
        }
예제 #5
0
        private void processRasterLayer(LayerProperties layerProps, geFolder folder)
        {
            IRasterLayer currentLayer = layerProps.Layeru as IRasterLayer;

            //get coordinates for image :D
            geAngle90  north;
            geAngle90  south;
            geAngle180 east;
            geAngle180 west;
            Double     coordlat, coordlong;
            IPoint     refPoint;

            refPoint = currentLayer.AreaOfInterest.LowerLeft;

            //coordinate system.
            IGeographicCoordinateSystem gcs;
            SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();

            //create coordinate system for WGS 84 (Google earth)
            gcs = sre.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            //spatial reference
            ISpatialReference pointToSpatialReference;

            pointToSpatialReference = gcs;

            //project point to google earth projection
            refPoint.Project(pointToSpatialReference);

            //and get coordinates
            refPoint.QueryCoords(out coordlong, out coordlat);
            //left = west point and lower = south
            west  = new geAngle180(coordlong);
            south = new geAngle90(coordlat);

            //and upper right
            refPoint = currentLayer.AreaOfInterest.UpperRight;

            //project point to google earth projection
            refPoint.Project(pointToSpatialReference);
            //x.ToString("{0:0.00}");

            //and get coordinates
            refPoint.QueryCoords(out coordlong, out coordlat);

            //north and east
            north = new geAngle90(coordlat);
            east  = new geAngle180(coordlong);

            //so I have all coordinates, now I create the overlay.
            geGroundOverlay.geLatLonBox latlonbox = new geGroundOverlay.geLatLonBox(north, south, east, west);
            geGroundOverlay             overlay   = new geGroundOverlay(latlonbox);

            //copy image to current folder...
            string name = System.IO.Path.GetDirectoryName(Path);

            name = System.IO.Path.Combine(name, currentLayer.Name);
            File.Copy(currentLayer.FilePath, name, true);

            // overlay.Icon.Href = currentLayer.FilePath;
            overlay.Icon        = new geIcon(System.IO.Path.GetFileName(name));
            overlay.Name        = currentLayer.Name;
            overlay.Description = currentLayer.FilePath;
            overlay.StyleUrl    = "#Shape2KMLGeneratedStyle";

            switch (layerProps.AltitudeMode)
            {
            case AltitudeMode.absolute:
                overlay.AltitudeMode = geAltitudeModeEnum.absolute;
                overlay.Altitude     = layerProps.Altitude;
                //use altitude from field , do that later...
                break;

            case AltitudeMode.clampToGround:
                overlay.AltitudeMode = geAltitudeModeEnum.clampToGround;
                break;

            case AltitudeMode.relativeToGround:
                overlay.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                overlay.Altitude     = layerProps.Altitude;
                //use altitude from field , do that later...
                break;

            default:
                break;
            }



            //and add overlay to folder. THAT "simple"
            folder.Features.Add(overlay);
        }
예제 #6
0
        private void processPolygonLayer(LayerProperties layerProps, geFolder folder)
        {
            //I have a polygon layer, and a kml folder :)
            IFeatureClass clasa = (layerProps.Layeru as IFeatureLayer).FeatureClass;
            //get acces to features
            IFeatureCursor featurele = clasa.Search(null, true);
            int            nrFeature = clasa.FeatureCount(null);

            //if I have any features
            Polygon  poligon;
            IFeature currentFeature;

            while ((currentFeature = featurele.NextFeature()) != null)
            {
                poligon = currentFeature.Shape as Polygon;
                //coordinates and vertices
                double      coordLat;
                double      coordLong;
                IEnumVertex colection = poligon.EnumVertices;
                IPoint      polyVertex;

                //create coord system WGS 84 (Google earth)
                IGeographicCoordinateSystem gcs;
                SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
                gcs = sre.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                //create spatial reference
                ISpatialReference pointToSpatialReference;
                pointToSpatialReference = gcs;

                #region add points to polygon
                //create a placemark for the line
                gePlacemark pmPolygon = new gePlacemark();
                pmPolygon.StyleUrl = "#Shape2KMLGeneratedStyle";

                List <geCoordinates> polyCoords = new List <geCoordinates>();
                int index1, index2;
                //iterate points...



                while (!colection.IsLastInPart())
                {
                    //create polygon from vertices
                    colection.Next(out polyVertex, out index1, out index2);
                    //project point and get coordinates
                    polyVertex.Project(pointToSpatialReference);
                    polyVertex.QueryCoords(out coordLong, out coordLat);
                    //add point to line

                    try
                    {
                        //create points for polygon based on altitude mode.
                        switch (layerProps.AltitudeMode)
                        {
                        case AltitudeMode.absolute:
                            if (layerProps.Field == "")
                            {
                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                            }
                            else
                            {
                                int altitude;
                                //if altitude is integer, this should work
                                altitude = (int)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));
                            }
                            break;

                        case AltitudeMode.clampToGround:
                            //add point to line
                            polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong)));
                            break;

                        case AltitudeMode.relativeToGround:
                            if (layerProps.Field == "")
                            {
                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude));
                            }
                            else
                            {
                                float altitude;
                                //if altitude is integer, this should work
                                altitude = (float)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                                //add point to line
                                polyCoords.Add(new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude));
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Altitude field is not a number value");
                        break;
                    }
                }

                //create line from list of coords
                geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(polyCoords));
                gePolygon         poly  = new gePolygon(outer);
                //and add it to document

                switch (layerProps.AltitudeMode)
                {
                //set altitude mode...
                case AltitudeMode.absolute:
                    poly.AltitudeMode = geAltitudeModeEnum.absolute;
                    break;

                case AltitudeMode.clampToGround:
                    poly.AltitudeMode = geAltitudeModeEnum.clampToGround;
                    break;

                case AltitudeMode.relativeToGround:
                    poly.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                    break;

                default:
                    break;
                }

                if (layerProps.DescField != "")
                {
                    pmPolygon.Description = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.DescField)).ToString();
                }

                if (layerProps.NameField != "")
                {
                    pmPolygon.Name = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.NameField)).ToString();
                }

                pmPolygon.Geometry = poly;
                folder.Features.Add(pmPolygon);

                #endregion
            }
        }
예제 #7
0
        private void processPointLayer(LayerProperties layerProps, geFolder folder)
        {
            //I have a point layer, and a kml folder :)
            IFeatureClass clasa = (layerProps.Layeru as IFeatureLayer).FeatureClass;
            //get acces to features
            IFeatureCursor featurele = clasa.Search(null, true);

            //if I have any features
            Point    punct;
            IFeature currentFeature;

            //create coord system WGS 84 (Google earth)
            IGeographicCoordinateSystem gcs;
            SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();

            gcs = sre.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            //create spatial reference
            ISpatialReference pointToSpatialReference;

            pointToSpatialReference = gcs;

            #region add points
            while ((currentFeature = featurele.NextFeature()) != null)
            {
                punct = currentFeature.Shape as Point;
                //coordinates and vertices
                double coordLat;
                double coordLong;


                //create a placemark for the point
                gePlacemark pmPoint = new gePlacemark();
                pmPoint.StyleUrl = "#Shape2KMLGeneratedStyle";

                //project point and get coordinates
                punct.Project(pointToSpatialReference);
                punct.QueryCoords(out coordLong, out coordLat);
                //add point

                geCoordinates coords;
                gePoint       point;

                switch (layerProps.AltitudeMode)
                {
                case AltitudeMode.absolute:

                    if (layerProps.Field == "")
                    {
                        //add point
                        coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude);
                    }
                    else
                    {
                        int altitude;
                        //if altitude is integer, this should work
                        altitude = (int)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                        //add point
                        coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude);
                    }
                    point = new gePoint(coords);
                    point.AltitudeMode = geAltitudeModeEnum.absolute;
                    break;

                case AltitudeMode.clampToGround:
                    coords             = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong));
                    point              = new gePoint(coords);
                    point.AltitudeMode = geAltitudeModeEnum.clampToGround;
                    break;

                case AltitudeMode.relativeToGround:
                    if (layerProps.Field == "")
                    {
                        //add point
                        coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Altitude);
                    }
                    else
                    {
                        int altitude;
                        //if altitude is integer, this should work
                        altitude = (int)currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.Field));

                        //add point
                        coords = new geCoordinates(new geAngle90(coordLat), new geAngle180(coordLong), layerProps.Multiplier * altitude);
                    }
                    point = new gePoint(coords);
                    point.AltitudeMode = geAltitudeModeEnum.relativeToGround;
                    break;

                default:
                    point = null;
                    break;
                }

                if (layerProps.DescField != "")
                {
                    pmPoint.Description = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.DescField)).ToString();
                }

                if (layerProps.NameField != "")
                {
                    pmPoint.Name = currentFeature.get_Value(currentFeature.Fields.FindField(layerProps.NameField)).ToString();
                }

                pmPoint.Geometry = point;
                folder.Features.Add(pmPoint);
                #endregion
            }
        }