public void TestFeatureCollectionSerialization() { var geometry = new Point(new GeoCoordinate(0, 1)); var feature1 = new Feature(geometry); var feature2 = new Feature(geometry, new SimpleGeometryAttributeCollection(new GeometryAttribute[] { new GeometryAttribute() { Key = "key1", Value = "value1" } })); var featureCollection = new FeatureCollection(new Feature[] { feature1, feature2 }); var serialized = featureCollection.ToGeoJson(); serialized = serialized.RemoveWhitespace(); Assert.AreEqual("{\"type\":\"FeatureCollection\",\"features\":[" + "{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.0,0.0]}}," + "{\"type\":\"Feature\",\"properties\":{\"key1\":\"value1\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.0,0.0]}}" + "]}", serialized); }
/// <summary> /// Converts a point into an oms object. /// </summary> /// <param name="point"></param> /// <returns></returns> private static Point ConvertPoint(OsmSharp.Xml.Kml.v2_1.PointType point) { // convert the coordiantes. IList<GeoCoordinate> coordinates = KmlGeoStreamSource.ConvertCoordinates(point.coordinates); // create the point. Point pointGeometry = new Point(coordinates[0]); pointGeometry.Attributes = new SimpleGeometryAttributeCollection(); if (point.targetId != null) { pointGeometry.Attributes.Add("targetId", point.targetId); } pointGeometry.Attributes.Add("altitude", point.altitudeMode); if (point.extrude) { pointGeometry.Attributes.Add("extrude", point.extrude); } if (point.id != null) { pointGeometry.Attributes.Add("id", point.id); } return pointGeometry; }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); SupportActionBar.DisplayOptions = (int)ActionBarDisplayOptions.ShowCustom; SupportActionBar.SetCustomView(Resource.Layout.ActionBar_Moses); _sos = SupportActionBar.CustomView.FindViewById <RelativeLayout>(Resource.Id.sos); _myLocation = SupportActionBar.CustomView.FindViewById <RelativeLayout>(Resource.Id.where_i); _layers = SupportActionBar.CustomView.FindViewById <RelativeLayout>(Resource.Id.layers); _sos.Click += delegate(object sender, EventArgs args) { Toast.MakeText(this, "Help me!!!!", ToastLength.Long).Show(); }; _layers.Click += delegate(object sender, EventArgs args) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(this); builderSingle.SetTitle("Type"); ArrayAdapterWithIcon arrayAdapter = new ArrayAdapterWithIcon( this, Android.Resource.Layout.select_dialog_singlechoice_material); arrayAdapter.Add(new ListItem() { ImageResourceId = Resource.Drawable.tse_tse }); arrayAdapter.Add(new ListItem() { ImageResourceId = Resource.Drawable.grass }); arrayAdapter.Add(new ListItem() { ImageResourceId = Resource.Drawable.water }); arrayAdapter.Add(new ListItem() { ImageResourceId = Resource.Drawable.fire }); builderSingle.SetNegativeButton("Cancel", NegativeHandler); builderSingle.SetAdapter(arrayAdapter, this); builderSingle.Show(); }; _myLocation.Click += delegate(object sender, EventArgs args) { _mapController.SetCenter(_centreOfMap); }; //StyleInterpreter interpreter = null; try { bool isTile = true; //List<OsmGeo> osm = null; if (isTile) { _mapView = FindViewById <MapView>(Resource.Id.mapview); _mapView.SetTileSource(TileSourceFactory.DefaultTileSource); _mapView.SetBuiltInZoomControls(true); //_mapView.SetUseDataConnection(false); _provider = new CustomLocationProvider(this); _provider.StartLocationProvider(new MyLocationNewOverlay(this, _mapView)); //List<OverlayItem> overlayItemArray = new List<OverlayItem>(); //OverlayItem olItem = new OverlayItem("Here", "SampleDescription", new GeoPoint(34.878039, -10.650)); //overlayItemArray.Add(olItem); //olItem.SetMarker(Resources.GetDrawable(Resource.Drawable.cloud)); //overlayItemArray.Add(new OverlayItem("Hi", "You're here", new GeoPoint(34.888039, -10.660))); DefaultResourceProxyImpl defaultResourceProxyImpl = new DefaultResourceProxyImpl(this); //ItemizedIconOverlay myItemizedIconOverlay = new ItemizedIconOverlay(overlayItemArray, null, defaultResourceProxyImpl); //_mapView.Overlays.Add(myItemizedIconOverlay); //PathOverlay myPath = new PathOverlay(Color.Red, this); //myPath.AddPoint(new GeoPoint(34.878039, -10.650)); //myPath.AddPoint(new GeoPoint(34.888039, -10.660)); //_mapView.Overlays.Add(myPath); _mapController = _mapView.Controller; _mapController.SetZoom(6); _mapController.SetCenter(_centreOfMap); _geoService = new CouchDbGeoObjectsService(); //var firstPoint = ((GeoJSON.Net.Geometry.Point) points.Features[0].Geometry); var firstPoint = new OsmSharp.Geo.Geometries.Point(new OsmSharp.Math.Geo.GeoCoordinate(33, -10)); //double x = ((GeographicPosition) firstPoint.Coordinates).Latitude; //double y = ((GeographicPosition)firstPoint.Coordinates).Longitude; //List<OverlayItem> overlayItemArray = new List<OverlayItem>(); //OverlayItem olItem = new OverlayItem("Here", "SampleDescription", new GeoPoint(x, y)); //overlayItemArray.Add(olItem); //olItem.SetMarker(Resources.GetDrawable(Resource.Drawable.cloud)); //ItemizedIconOverlay newPoints = new ItemizedIconOverlay(overlayItemArray, null, defaultResourceProxyImpl); //_mapView.Overlays.Add(newPoints); } else { /*List<OsmGeo> osm = await _service.DownloadArea(34.878039, -10.465, 36, -9.077); * if (osm != null) * { * Native.Initialize(); * * // initialize map. * var map = new Map(); * interpreter = new MapCSSInterpreter(css); * * IDataSourceReadOnly source = new MemoryDataSource(osm.ToArray()); * var layer = map.AddLayerOsm(source, interpreter); * * _mapView = new MapView(this, new MapViewSurface(this)); * _mapView.Map = map; * _mapView.MapMaxZoomLevel = 17; // limit min/max zoom because MBTiles sample only contains a small portion of a map. * _mapView.MapMinZoomLevel = 1; * _mapView.MapTilt = 0; * _mapView.MapCenter = new GeoCoordinate(-9.2, 36); * _mapView.MapZoom = 2; * _mapView.MapAllowTilt = false; * * //OsmSharp.Data.SQLite.SQLiteConnectionBase sqLiteConnection = new SQLiteConnection("osmMap"); * * frame.AddView(_mapView); * var textLabel = FindViewById<TextView>(Resource.Id.text_label); * textLabel.Text = "Изображение подгрузилось"; * Toast.MakeText(this, "Read success", ToastLength.Long).Show(); * } * else * { * Toast.MakeText(this, "OSM is null", ToastLength.Long).Show(); * }*/ } } catch (Exception exception) { Toast.MakeText(this, exception.Message, ToastLength.Long).Show(); SetContentView(Resource.Layout.Main); } }
public void TestPointSerialization() { var geometry = new Point(new GeoCoordinate(0, 1)); var serialized = geometry.ToGeoJson(); serialized = serialized.RemoveWhitespace(); Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[1.0,0.0]}", serialized); }
public void TestMultiPointSerialization() { var geometry1 = new Point(new GeoCoordinate(0, 1)); var geometry2 = new Point(new GeoCoordinate(1, 1)); var geometry3 = new Point(new GeoCoordinate(1, 0)); var geometryCollection = new MultiPoint(new Point[] { geometry1, geometry2, geometry3 }); var serialized = geometryCollection.ToGeoJson(); serialized = serialized.RemoveWhitespace(); Assert.AreEqual("{\"type\":\"MultiPoint\",\"coordinates\":[[1.0,0.0],[1.0,1.0],[0.0,1.0]]}", serialized); }
public void TestGeometryCollectionSerialization() { var geometry1 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0) }); var geometry2 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 2), new GeoCoordinate(2, 2), new GeoCoordinate(2, 0) }); var geometry3 = new LineString( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 3), new GeoCoordinate(3, 3), new GeoCoordinate(3, 0) }); var geometry4 = new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0), new GeoCoordinate(0, 0) }); var geometry5 = new Polygon(new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 1), new GeoCoordinate(1, 1), new GeoCoordinate(1, 0), new GeoCoordinate(0, 0) })); var geometry6 = new MultiPolygon(geometry5, new Polygon(new LineairRing( new GeoCoordinate[] { new GeoCoordinate(0, 0), new GeoCoordinate(0, 2), new GeoCoordinate(2, 2), new GeoCoordinate(2, 0), new GeoCoordinate(0, 0) }))); var geometry7 = new Point(new GeoCoordinate(0, 1)); var geometry8 = new MultiPoint(geometry7, new Point(new GeoCoordinate(0, 2))); var geometryCollection = new GeometryCollection( geometry1, geometry2, geometry3, geometry4, geometry5, geometry6, geometry7, geometry8); var serialized = geometryCollection.ToGeoJson(); serialized = serialized.RemoveWhitespace(); Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]]},{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0]]},{\"type\":\"LineString\",\"coordinates\":[[0.0,0.0],[3.0,0.0],[3.0,3.0],[0.0,3.0]]},{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},{\"type\":\"Polygon\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]]},{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]]],[[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0],[0.0,0.0]]]]},{\"type\":\"Point\",\"coordinates\":[1.0,0.0]},{\"type\":\"MultiPoint\",\"coordinates\":[[1.0,0.0],[2.0,0.0]]}]}", serialized); }
/// <summary> /// Reads a gpx v1.1 object into corresponding geometries. /// </summary> /// <param name="gpx"></param> private void ReadGpxv1_1(Xml.Gpx.v1_1.gpxType gpx) { this.GeometryCollection.Clear(); // do the waypoints. if (gpx.wpt != null) { // there are waypoints. foreach (var wpt in gpx.wpt) { Point point = new Point( new GeoCoordinate((double)wpt.lat, (double)wpt.lon)); point.Attributes = new SimpleGeometryAttributeCollection(); if (wpt.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", wpt.ageofdgpsdata); } if (wpt.eleSpecified) { point.Attributes.Add("ele", wpt.ele); } if (wpt.fixSpecified) { point.Attributes.Add("fix", wpt.fix); } if (wpt.geoidheightSpecified) { point.Attributes.Add("geoidheight", wpt.geoidheight); } if (wpt.hdopSpecified) { point.Attributes.Add("hdop", wpt.hdop); } if (wpt.magvarSpecified) { point.Attributes.Add("magvar", wpt.magvar); } if (wpt.pdopSpecified) { point.Attributes.Add("pdop", wpt.pdop); } if (wpt.timeSpecified) { point.Attributes.Add("time", wpt.time); } if (wpt.vdopSpecified) { point.Attributes.Add("vdop", wpt.vdop); } if (wpt.cmt != null) { point.Attributes.Add("cmt", wpt.cmt); } if (wpt.desc != null) { point.Attributes.Add("desc", wpt.desc); } if (wpt.dgpsid != null) { point.Attributes.Add("dgpsid", wpt.dgpsid); } if (wpt.name != null) { point.Attributes.Add("name", wpt.name); } if (wpt.sat != null) { point.Attributes.Add("sat", wpt.sat); } if (wpt.src != null) { point.Attributes.Add("src", wpt.src); } if (wpt.sym != null) { point.Attributes.Add("sym", wpt.sym); } if (wpt.type != null) { point.Attributes.Add("type", wpt.type); } this.GeometryCollection.Add(point); } } // do the routes. if (gpx.rte != null) { foreach (var rte in gpx.rte) { // convert to a line-string List<GeoCoordinate> coordinates = new List<GeoCoordinate>(); foreach (var rtept in rte.rtept) { GeoCoordinate coordinate = new GeoCoordinate((double)rtept.lat, (double)rtept.lon); coordinates.Add(coordinate); if (_createTrackPoints) { Point point = new Point(coordinate); point.Attributes = new SimpleGeometryAttributeCollection(); if (rtept.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", rtept.ageofdgpsdata); } if (rtept.eleSpecified) { point.Attributes.Add("ele", rtept.ele); } if (rtept.fixSpecified) { point.Attributes.Add("fix", rtept.fix); } if (rtept.geoidheightSpecified) { point.Attributes.Add("geoidheight", rtept.geoidheight); } if (rtept.hdopSpecified) { point.Attributes.Add("hdop", rtept.hdop); } if (rtept.magvarSpecified) { point.Attributes.Add("magvar", rtept.magvar); } if (rtept.pdopSpecified) { point.Attributes.Add("pdop", rtept.pdop); } if (rtept.timeSpecified) { point.Attributes.Add("time", rtept.time); } if (rtept.vdopSpecified) { point.Attributes.Add("vdop", rtept.vdop); } if (rtept.cmt != null) { point.Attributes.Add("cmt", rtept.cmt); } if (rtept.desc != null) { point.Attributes.Add("desc", rtept.desc); } if (rtept.dgpsid != null) { point.Attributes.Add("dgpsid", rtept.dgpsid); } if (rtept.name != null) { point.Attributes.Add("name", rtept.name); } if (rtept.sat != null) { point.Attributes.Add("sat", rtept.sat); } if (rtept.src != null) { point.Attributes.Add("src", rtept.src); } if (rtept.sym != null) { point.Attributes.Add("sym", rtept.sym); } if (rtept.type != null) { point.Attributes.Add("type", rtept.type); } this.GeometryCollection.Add(point); } } // creates a new linestring. LineString lineString = new LineString(coordinates); lineString.Attributes = new SimpleGeometryAttributeCollection(); if (rte.cmt != null) { lineString.Attributes.Add("cmt", rte.cmt); } if (rte.desc != null) { lineString.Attributes.Add("desc", rte.desc); } if (rte.name != null) { lineString.Attributes.Add("name", rte.name); } if (rte.number != null) { lineString.Attributes.Add("number", rte.number); } if (rte.src != null) { lineString.Attributes.Add("src", rte.src); } this.GeometryCollection.Add(lineString); } } // do the tracks. foreach (var trk in gpx.trk) { // convert to a line-string List<GeoCoordinate> coordinates = new List<GeoCoordinate>(); foreach (var trkseg in trk.trkseg) { foreach (var wpt in trkseg.trkpt) { GeoCoordinate coordinate = new GeoCoordinate((double)wpt.lat, (double)wpt.lon); // only add new coordinates. if (coordinates.Count == 0 || coordinates[coordinates.Count - 1] != coordinate) { coordinates.Add(coordinate); } if (_createTrackPoints) { Point point = new Point(coordinate); point.Attributes = new SimpleGeometryAttributeCollection(); if (wpt.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", wpt.ageofdgpsdata); } if (wpt.eleSpecified) { point.Attributes.Add("ele", wpt.ele); } if (wpt.fixSpecified) { point.Attributes.Add("fix", wpt.fix); } if (wpt.geoidheightSpecified) { point.Attributes.Add("geoidheight", wpt.geoidheight); } if (wpt.hdopSpecified) { point.Attributes.Add("hdop", wpt.hdop); } if (wpt.magvarSpecified) { point.Attributes.Add("magvar", wpt.magvar); } if (wpt.pdopSpecified) { point.Attributes.Add("pdop", wpt.pdop); } if (wpt.timeSpecified) { point.Attributes.Add("time", wpt.time); } if (wpt.vdopSpecified) { point.Attributes.Add("vdop", wpt.vdop); } if (wpt.cmt != null) { point.Attributes.Add("cmt", wpt.cmt); } if (wpt.desc != null) { point.Attributes.Add("desc", wpt.desc); } if (wpt.dgpsid != null) { point.Attributes.Add("dgpsid", wpt.dgpsid); } if (wpt.name != null) { point.Attributes.Add("name", wpt.name); } if (wpt.sat != null) { point.Attributes.Add("sat", wpt.sat); } if (wpt.src != null) { point.Attributes.Add("src", wpt.src); } if (wpt.sym != null) { point.Attributes.Add("sym", wpt.sym); } if (wpt.type != null) { point.Attributes.Add("type", wpt.type); } this.GeometryCollection.Add(point); } } } // creates a new linestring. LineString lineString = new LineString(coordinates); lineString.Attributes = new SimpleGeometryAttributeCollection(); if (trk.cmt != null) { lineString.Attributes.Add("cmt", trk.cmt); } if (trk.desc != null) { lineString.Attributes.Add("desc", trk.desc); } if (trk.name != null) { lineString.Attributes.Add("name", trk.name); } if (trk.number != null) { lineString.Attributes.Add("number", trk.number); } if (trk.src != null) { lineString.Attributes.Add("src", trk.src); } this.GeometryCollection.Add(lineString); } }