Contains a linear ring
Inheritance: geBoundaryIs
Ejemplo n.º 1
0
 public gePolygon(geOuterBoundaryIs outerBoundaryIs)
 {
     OuterBoundaryIs = outerBoundaryIs;
 }
Ejemplo n.º 2
0
        geGeometry DoPolygon(SqlGeography g)
        {
            List<geCoordinates> outcoor = new List<geCoordinates>();
            List<geCoordinates>[] innercoor = null;
            geInnerBoundaryIs[] inner = null;
            int points = 0;
            int rings = 0;

            while (points < g.RingN(1).STNumPoints().Value)
            {
                outcoor.Add(new geCoordinates(new geAngle90(g.STPointN(points + 1).Lat.Value), new geAngle180(g.STPointN(points + 1).Long.Value)));
                points++;
            }

            geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(outcoor));
            gePolygon poly = new gePolygon(outer);

            if (g.NumRings().Value > 1)
            {
                innercoor = new List<geCoordinates>[g.NumRings().Value - 1];
                inner = new geInnerBoundaryIs[g.NumRings().Value - 1];
                rings = 1;
                while (rings < g.NumRings().Value)
                {
                    innercoor[rings-1] = new List<geCoordinates>();
                    points = 0;
                    while (points < g.RingN(rings+1).STNumPoints().Value)
                    {
                        geCoordinates c = new geCoordinates(new geAngle90(g.RingN(rings+1).STPointN(points + 1).Lat.Value), new geAngle180(g.RingN(rings+1).STPointN(points + 1).Long.Value));
                        innercoor[rings-1].Add(c);
                        points++;
                    }
                    inner[rings-1] = new geInnerBoundaryIs(new geLinearRing(innercoor[rings-1]));
                    poly.InnerBoundaries.Add(inner[rings-1]);
                    rings++;
                }
            }

            return poly;
        }
Ejemplo n.º 3
0
 public gePolygon(geOuterBoundaryIs outerBoundaryIs)
 {
     OuterBoundaryIs = outerBoundaryIs;
 }
Ejemplo n.º 4
0
        public static geKML RunExample(string FileName)
        {
            // Use a Document as the root of the KML
            geDocument doc = new geDocument();
            doc.Name = "My Root Document";

            gePlacemark pm = new gePlacemark();

            //Always complete the boundary by adding an end point that matches your beginning point

            List<geCoordinates> outerCoords = new List<geCoordinates>();
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-108)));
            outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-114)));
            outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114)));

            List<geCoordinates> innerCoords1 = new List<geCoordinates>();
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-112)));
            innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-113)));
            innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113)));

            List<geCoordinates> innerCoords2 = new List<geCoordinates>();
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-112)));
            innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-113)));
            innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113)));

            geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(outerCoords));

            gePolygon poly = new gePolygon(outer);

            geInnerBoundaryIs inner1 = new geInnerBoundaryIs(new geLinearRing(innerCoords1));
            geInnerBoundaryIs inner2 = new geInnerBoundaryIs(new geLinearRing(innerCoords2));
            poly.InnerBoundaries.Add(inner1);
            poly.InnerBoundaries.Add(inner2);

            pm.Geometry = poly;

            doc.Features.Add(pm);

            //Lets add a Line somewhere too...
            geStyle myLineStyle = new geStyle("myLineStyle");
            myLineStyle.LineStyle = new geLineStyle();
            myLineStyle.LineStyle.Color.SysColor = Color.Yellow;
            myLineStyle.LineStyle.Width = 4;  //This may or may not work, depends on the end user's video card

            doc.StyleSelectors.Add(myLineStyle);

            gePlacemark pmLine = new gePlacemark();
            pmLine.StyleUrl = "#myLineStyle";
            pmLine.Name = "Example Line";
            pmLine.Description = "Some description";

            List<geCoordinates> lineCoords = new List<geCoordinates>();
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-117)));
            lineCoords.Add(new geCoordinates(new geAngle90(35),new geAngle180(-106)));

            geLineString line = new geLineString(lineCoords);

            pmLine.Geometry = line;

            doc.Features.Add(pmLine);

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

            return kml;
        }
Ejemplo n.º 5
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
            }
        }