Пример #1
0
        public static FeatureCollection GetFeatures(string key, string searchTerm)
        {
            var results = Result.GetResults(key, searchTerm);
            List <BAMCIS.GeoJSON.Feature> featureList = new List <BAMCIS.GeoJSON.Feature>();

            foreach (Result result in results)
            {
                Dictionary <string, dynamic> properties = new Dictionary <string, dynamic>();
                foreach (var prop in result.GetType().GetProperties())
                {
                    if (prop.Name != "Lat" && prop.Name != "Lng")
                    {
                        var propValue = prop.GetValue(result, null).ToString();
                        if (propValue.Contains("'"))
                        {
                            propValue = propValue.Replace("'", "");
                        }
                        properties.Add(prop.Name, propValue);
                    }
                }

                BAMCIS.GeoJSON.Feature feature = new BAMCIS.GeoJSON.Feature(new Point(new Position(result.Lng, result.Lat)), properties);
                featureList.Add(feature);
            }

            FeatureCollection list = new FeatureCollection(featureList);

            // JObject jsonResponse = JsonConvert.DeserializeObject<JObject>(result);
            //FeatureCollection list = FeatureCollection.FromJson(result);
            return(list);
        }
Пример #2
0
        public List <List <double[]> > getHoles(BAMCIS.GeoJSON.Feature feature)
        {
            List <List <double[]> > holes = new List <List <double[]> >();

            if (feature.Geometry.Type == GeoJsonType.Polygon)
            {
                Polygon polygon = feature.Geometry as Polygon;
                IEnumerable <LinearRing> innerRings = polygon.Coordinates.Skip(1);
                holes = innerRings.Select(r => r.Coordinates.Select(c => new double[] {
                    c.Longitude,
                    c.Latitude
                }).ToList()).ToList();
            }
            return(holes);
        }
Пример #3
0
        private List <double[]> getCoordinates(BAMCIS.GeoJSON.Feature feature)
        {
            List <double[]> coordinates = new List <double[]>();

            switch (feature.Geometry.Type)
            {
            case GeoJsonType.Point:
                Point p = feature.Geometry as Point;
                coordinates.Add(new double[]
                {
                    p.Coordinates.Longitude,
                    p.Coordinates.Latitude,
                });
                return(coordinates);

            case GeoJsonType.LineString:
                LineString lineString = feature.Geometry as LineString;
                coordinates = lineString.Coordinates.Select(coord => new double[] {
                    coord.Longitude,
                    coord.Latitude
                }).ToList();
                return(coordinates);

            case GeoJsonType.Polygon:
                Polygon    polygon = feature.Geometry as Polygon;
                LinearRing outline = polygon.Coordinates.FirstOrDefault();
                coordinates = outline.Coordinates.Select(coord => new double[] {
                    coord.Longitude,
                    coord.Latitude
                }).ToList();
                return(coordinates);

            default:
                return(coordinates);
            }
        }