Ejemplo n.º 1
0
        public string Write(Guid listGuid)
        {
            string     kml        = string.Empty;
            Serializer serializer = new Serializer();
            Kml        _kml       = new Kml();
            Folder     folder     = new Folder();

            UseWeb(spWeb =>
            {
                SPList list   = spWeb.Lists.GetList(listGuid, true);
                SPField field = list.GetGeoField();
                if (field != null)
                {
                    foreach (SPListItem item in list.Items)
                    {
                        string wkt = item[field.Id] as string;
                        SimpleWKTReader wktReader = new SimpleWKTReader();
                        var simpleGeometry        = wktReader.Parse(wkt);

                        if (simpleGeometry.GeometryType == GeometryTypes.Point)
                        {
                            var _point = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.Point)simpleGeometry;
                            SharpKml.Dom.Point point = new SharpKml.Dom.Point();
                            point.Coordinate         = new Vector(_point.Lat, _point.Lon);

                            Placemark placemark = CreatePlaceMark(item.Title, point);
                            folder.AddFeature(placemark);
                        }
                        else if (simpleGeometry.GeometryType == GeometryTypes.LineString)
                        {
                            var _lineString = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.LineString)simpleGeometry;
                            SharpKml.Dom.LineString line = new SharpKml.Dom.LineString();
                            line.Coordinates             = CreateCoordinateCollection(_lineString.Points);
                            Placemark placeMark          = CreatePlaceMark(item.Title, line);
                            folder.AddFeature(placeMark);
                        }
                        else if (simpleGeometry.GeometryType == GeometryTypes.Polygon)
                        {
                            var _polygon = (OpenSMIL.Server.SimpleFeature.GeomtryTypes.Polygon)simpleGeometry;
                            OuterBoundary outerBoundary          = new OuterBoundary();
                            outerBoundary.LinearRing             = new LinearRing();
                            outerBoundary.LinearRing.Coordinates = CreateCoordinateCollection(_polygon.Points);

                            SharpKml.Dom.Polygon polygon = new SharpKml.Dom.Polygon();
                            polygon.OuterBoundary        = outerBoundary;
                            polygon.Extrude = true;

                            Placemark placeMark = CreatePlaceMark(item.Title, polygon);
                            folder.AddFeature(placeMark);
                        }
                    }
                    _kml.Feature = folder;
                }
            });
            serializer.Serialize(_kml);
            return(serializer.Xml);
        }
Ejemplo n.º 2
0
        public string Write(Guid listGuid)
        {
            string csv = string.Empty;

            UseWeb(spWeb => {
                SPList list = spWeb.Lists.GetList(listGuid, true);

                SPView view = list.DefaultView;

                SPViewFieldCollection fields = view.ViewFields;


                SPField geomField = list.GetGeoField();

                //create header
                for (int i = 0; i < view.ViewFields.Count; i++)
                {
                    string field = view.ViewFields[i];
                    if (geomField.InternalName != field)
                    {
                        csv += view.ViewFields[i];
                    }
                    else
                    {
                        csv += "Longitude, Latitude";
                    }

                    if ((i + 1) < view.ViewFields.Count)
                    {
                        csv += ",";
                    }
                    else
                    {
                        csv += "\r\n";
                    }
                }

                //create CSV rows
                foreach (SPListItem listItem in list.Items)
                {
                    for (int i = 0; i < view.ViewFields.Count; i++)
                    {
                        string field = view.ViewFields[i];
                        if (geomField.InternalName != field)
                        {
                            csv += listItem[view.ViewFields[i]].ToString();
                        }
                        else
                        {
                            OpenSMIL.Server.SimpleFeature.GeomtryTypes.Point point = GetPoint(listItem[field] as string);
                            csv += point.Lon + ",";
                            csv += point.Lat;
                        }

                        if ((i + 1) < view.ViewFields.Count)
                        {
                            csv += ",";
                        }
                        else
                        {
                            csv += "\r\n";
                        }
                    }
                }
            });
            return(csv);
        }